Compare commits
No commits in common. "master" and "particle_storage_rework" have entirely different histories.
master
...
particle_s
20
Jenkinsfile
vendored
20
Jenkinsfile
vendored
|
|
@ -1,20 +0,0 @@
|
|||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Gradle') {
|
||||
steps {
|
||||
sh 'bash gradlew shadowJar'
|
||||
}
|
||||
}
|
||||
stage('Archive') {
|
||||
steps {
|
||||
archiveArtifacts artifacts: 'build/libs/', followSymlinks: false
|
||||
}
|
||||
}
|
||||
stage('discord') {
|
||||
steps {
|
||||
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,23 +7,16 @@ import com.alttd.config.ParticleConfig;
|
|||
import com.alttd.database.Database;
|
||||
import com.alttd.listeners.*;
|
||||
import com.alttd.objects.APartType;
|
||||
import com.alttd.storage.AutoReload;
|
||||
import com.alttd.util.Logger;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class AltitudeParticles extends JavaPlugin {
|
||||
|
||||
@Getter
|
||||
public static AltitudeParticles instance;
|
||||
|
||||
private static AutoReload autoReload = null;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
|
|
@ -53,30 +46,9 @@ public class AltitudeParticles extends JavaPlugin {
|
|||
}
|
||||
|
||||
public void reload() {
|
||||
Logger.info("Reloading AltitudeParticles...");
|
||||
Config.reload();
|
||||
DatabaseConfig.reload();
|
||||
ParticleConfig.reload();
|
||||
startAutoReload();
|
||||
}
|
||||
|
||||
private static void startAutoReload() {
|
||||
Path path = Path.of(Config.AUTO_RELOAD_PATH);
|
||||
File file = path.toFile();
|
||||
if (file.exists() && file.isDirectory()) {
|
||||
try {
|
||||
if (autoReload != null) {
|
||||
autoReload.stop();
|
||||
}
|
||||
autoReload = new AutoReload(path);
|
||||
autoReload.startWatching();
|
||||
} catch (IOException e) {
|
||||
Logger.severe("Failed to start AutoReload at path %", Config.AUTO_RELOAD_PATH);
|
||||
Logger.error("Failed to start AutoReload", e);
|
||||
}
|
||||
} else {
|
||||
Logger.severe("Failed to start AutoReload at path %", Config.AUTO_RELOAD_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,9 +98,4 @@ public final class Config extends AbstractConfig {
|
|||
CLICK_BLOCK_COOL_DOWN = config.getInt("cool_down.click-block", CLICK_BLOCK_COOL_DOWN);
|
||||
TELEPORT_ARRIVE_COOL_DOWN = config.getInt("cool_down.teleport-arrive", TELEPORT_ARRIVE_COOL_DOWN);
|
||||
}
|
||||
|
||||
public static String AUTO_RELOAD_PATH = "/mnt/configs/AltitudeParticles/particles";
|
||||
private static void loadAutoReload() {
|
||||
AUTO_RELOAD_PATH = config.getString("auto-reload.path", AUTO_RELOAD_PATH);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,32 +8,26 @@ import com.alttd.objects.ParticleSet;
|
|||
import com.alttd.storage.ParticleStorage;
|
||||
import com.alttd.util.Logger;
|
||||
import com.destroystokyo.paper.ParticleBuilder;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HexFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ParticleConfig {
|
||||
|
||||
private static final int MAX_DEPTH = 1;
|
||||
private static final File particlesDir = new File(File.separator + "mnt" + File.separator + "configs"
|
||||
+ File.separator + "AltitudeParticles" + File.separator + "particles");
|
||||
private static ParticleConfig instance = null;
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
static {
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
|
||||
}
|
||||
|
||||
private static ParticleConfig getInstance() {
|
||||
if (instance == null)
|
||||
|
|
@ -43,92 +37,28 @@ public class ParticleConfig {
|
|||
|
||||
/**
|
||||
* Finds all files in particles directory that are valid .json files
|
||||
* Only searches one level deep into subdirectories
|
||||
*
|
||||
* @return all files found
|
||||
*/
|
||||
private List<File> getJsonFiles() {
|
||||
List<File> files = new ArrayList<>();
|
||||
|
||||
// Ensure particles directory exists
|
||||
if (!ensureParticlesDirectoryExists()) {
|
||||
return files;
|
||||
}
|
||||
|
||||
try {
|
||||
Files.walkFileTree(particlesDir.toPath(), getJsonFileVistor(files));
|
||||
} catch (IOException e) {
|
||||
Logger.warning("Error while traversing directory: " + e.getMessage());
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
private FileVisitor<? super @NotNull Path> getJsonFileVistor(List<File> files) {
|
||||
return new SimpleFileVisitor<>() {
|
||||
private int depth = 0;
|
||||
|
||||
@Override
|
||||
public @NotNull FileVisitResult preVisitDirectory(@NotNull Path dir, @NotNull BasicFileAttributes attrs) {
|
||||
if (depth > ParticleConfig.MAX_DEPTH) {
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
}
|
||||
depth++;
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs) {
|
||||
File physicalFile = file.toFile();
|
||||
if (isValidJsonFile(physicalFile)) {
|
||||
files.add(physicalFile);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FileVisitResult postVisitDirectory(@NotNull Path dir, IOException exc) {
|
||||
depth--;
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the particles directory exists and is a directory
|
||||
*
|
||||
* @return true if directory exists or was created successfully, false otherwise
|
||||
*/
|
||||
private boolean ensureParticlesDirectoryExists() {
|
||||
if (!particlesDir.exists()) {
|
||||
if (!particlesDir.mkdirs()) {
|
||||
if (!particlesDir.mkdir())
|
||||
Logger.warning("Unable to create particles directory");
|
||||
return false;
|
||||
return files;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!particlesDir.isDirectory()) {
|
||||
Logger.warning("Particles path exists but is not a directory: " + particlesDir.getAbsolutePath());
|
||||
return false;
|
||||
Logger.warning("Particles directory doesn't exist (it's a file??)");
|
||||
return files;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file is a valid JSON file
|
||||
*
|
||||
* @param file the file to check
|
||||
* @return true if the file is a valid JSON file
|
||||
*/
|
||||
private boolean isValidJsonFile(File file) {
|
||||
return file.isFile() && file.canRead() && file.getName().endsWith(".json");
|
||||
File[] validFiles = particlesDir.listFiles(file -> file.isFile() && file.canRead() && file.getName().endsWith(".json"));
|
||||
if (validFiles == null)
|
||||
return files;
|
||||
files.addAll(List.of(validFiles));
|
||||
return files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a ParticleData object to a ParticleSet
|
||||
*
|
||||
* @param particleData The ParticleData object to convert
|
||||
* @return A ParticleSet created from the ParticleData
|
||||
*/
|
||||
|
|
@ -148,41 +78,30 @@ public class ParticleConfig {
|
|||
double z = particleInfo.getZ();
|
||||
|
||||
ParticleBuilder particleBuilder = new ParticleBuilder(particleType);
|
||||
Class<?> dataType = particleType.getDataType();
|
||||
|
||||
// Handle different particle data types
|
||||
if (dataType.equals(Particle.DustOptions.class)) {
|
||||
if (particleInfo.getColor() != null) {
|
||||
particleBuilder.color(getColor(particleInfo.getColor()),
|
||||
particleInfo.getSize());
|
||||
if (particleType.getDataType().equals(Particle.DustOptions.class) && particleInfo.getColor() != null) {
|
||||
int rgb = HexFormat.fromHexDigits(particleInfo.getColor());
|
||||
particleBuilder.data(new Particle.DustOptions(Color.fromRGB(rgb), 1));
|
||||
}
|
||||
} else if (dataType.equals(Particle.DustTransition.class)) {
|
||||
if (particleInfo.getColorGradientEnd() != null) {
|
||||
particleBuilder.colorTransition(getColor(particleInfo.getColor()),
|
||||
getColor(particleInfo.getColorGradientEnd()),
|
||||
particleInfo.getSize());
|
||||
}
|
||||
}
|
||||
else if (dataType.equals(Color.class)) {
|
||||
particleBuilder.color(getColor(particleInfo.getColor()));
|
||||
} else if (dataType.equals(BlockData.class)) {
|
||||
particleBuilder.data(Material.STONE.createBlockData());
|
||||
// else if (particleType.getDataType().equals(MaterialData.class)) {
|
||||
// //TODO implement
|
||||
// }
|
||||
else if (particleType.getDataType().equals(BlockData.class)) {
|
||||
//TODO implement
|
||||
} else if (dataType.equals(Integer.class)) {
|
||||
particleBuilder.data(1);
|
||||
} else if (particleType.getDataType().equals(Integer.class)) {
|
||||
//TODO implement
|
||||
} else if (dataType.equals(Float.class)) {
|
||||
particleBuilder.data(1f);
|
||||
} else if (particleType.getDataType().equals(Float.class)) {
|
||||
//TODO implement
|
||||
} else if (dataType.equals(ItemStack.class)) {
|
||||
particleBuilder.data(new ItemStack(Material.STONE));
|
||||
} else if (particleType.getDataType().equals(Particle.DustTransition.class)) {
|
||||
//TODO implement
|
||||
} else if (particleType.getDataType().equals(ItemStack.class)) {
|
||||
//TODO implement
|
||||
} else if (particleInfo.getExtra() != null) {
|
||||
particleBuilder.extra(particleInfo.getExtra());
|
||||
}
|
||||
|
||||
//Add 0.2 to adjust for the player model being 1.6 blocks high
|
||||
aParticleList.add(new AParticle(x, y + 0.2, z, randomOffset, particleBuilder));
|
||||
aParticleList.add(new AParticle(x, y, z, randomOffset, particleBuilder));
|
||||
}
|
||||
|
||||
loadedFrames.add(new Frame(aParticleList));
|
||||
|
|
@ -206,26 +125,11 @@ public class ParticleConfig {
|
|||
);
|
||||
}
|
||||
|
||||
private Color getColor(String hexColor) {
|
||||
int color = HexFormat.fromHexDigits(hexColor);
|
||||
if (hexColor.length() == 6) {
|
||||
return Color.fromARGB(color);
|
||||
} else {
|
||||
return Color.fromRGB(color);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
ParticleStorage.clear();
|
||||
instance = getInstance();
|
||||
ParticleConfig instance = getInstance();
|
||||
|
||||
for (File file : instance.getJsonFiles()) {
|
||||
loadParticleFromFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadParticleFromFile(File file) {
|
||||
instance = getInstance();
|
||||
try {
|
||||
ParticleData particleData = objectMapper.readValue(file, ParticleData.class);
|
||||
|
||||
|
|
@ -239,3 +143,4 @@ public class ParticleConfig {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.frame_spawners;
|
||||
package com.alttd.frameSpawners;
|
||||
|
||||
import com.alttd.AltitudeParticles;
|
||||
import com.alttd.config.Config;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.frame_spawners;
|
||||
package com.alttd.frameSpawners;
|
||||
|
||||
import com.alttd.AltitudeParticles;
|
||||
import com.alttd.config.Config;
|
||||
|
|
@ -36,14 +36,6 @@ import java.util.List;
|
|||
@Setter
|
||||
@Getter
|
||||
public class ParticleData {
|
||||
// TODO add optional property for a list of users that can use the particle
|
||||
// If that list is present the particle should be loaded as a dev particle
|
||||
// Dev particles should disable all others while in use and all be grouped together
|
||||
// (since the dev should know what each particle is and does)
|
||||
// Seeing dev particles should require a permission
|
||||
@JsonProperty("user_list")
|
||||
private List<String> userList;
|
||||
|
||||
@JsonProperty("particle_name")
|
||||
private String particleName;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,12 +32,6 @@ public class ParticleInfo {
|
|||
|
||||
// For DustOptions
|
||||
private String color;
|
||||
@JsonProperty("color_gradient_end")
|
||||
private String colorGradientEnd;
|
||||
// For DustOptions
|
||||
|
||||
@JsonProperty(value = "size", defaultValue = "1")
|
||||
private int size;
|
||||
|
||||
// For other particle types
|
||||
private Double extra;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package com.alttd.objects;
|
|||
|
||||
import com.alttd.AltitudeParticles;
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.frame_spawners.FrameSpawnerLocation;
|
||||
import com.alttd.frame_spawners.FrameSpawnerPlayer;
|
||||
import com.alttd.frameSpawners.FrameSpawnerLocation;
|
||||
import com.alttd.frameSpawners.FrameSpawnerPlayer;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import com.alttd.util.Logger;
|
||||
import de.myzelyam.api.vanish.VanishAPI;
|
||||
|
|
|
|||
|
|
@ -1,171 +0,0 @@
|
|||
package com.alttd.storage;
|
||||
|
||||
import com.alttd.config.ParticleConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class AutoReload {
|
||||
private final WatchService watchService;
|
||||
private final Map<WatchKey, Path> keys;
|
||||
private final Path rootDirectory;
|
||||
private volatile boolean running = true;
|
||||
|
||||
public AutoReload(Path directory) throws IOException {
|
||||
this.watchService = FileSystems.getDefault().newWatchService();
|
||||
this.keys = new HashMap<>();
|
||||
this.rootDirectory = directory;
|
||||
register(directory);
|
||||
registerAll(directory);
|
||||
}
|
||||
|
||||
private void registerAll(Path start) throws IOException {
|
||||
Files.walkFileTree(start, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult preVisitDirectory(@NotNull Path path, @NotNull BasicFileAttributes attrs) throws IOException {
|
||||
if (path.toFile().isDirectory()) {
|
||||
register(path);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void register(@NotNull Path dir) throws IOException {
|
||||
WatchKey key = dir.register(watchService,
|
||||
StandardWatchEventKinds.ENTRY_CREATE,
|
||||
StandardWatchEventKinds.ENTRY_DELETE,
|
||||
StandardWatchEventKinds.ENTRY_MODIFY);
|
||||
keys.put(key, dir);
|
||||
}
|
||||
|
||||
public void startWatching() {
|
||||
log.info("Starting watch thread.");
|
||||
Thread watchThread = new Thread(() -> {
|
||||
log.info("Watch thread started.");
|
||||
while (running) {
|
||||
log.info("Watch thread loop start");
|
||||
WatchKey key;
|
||||
try {
|
||||
key = watchService.take();
|
||||
log.info("Watch thread loop key {}", key.toString());
|
||||
} catch (InterruptedException e) {
|
||||
log.error("Interrupted while waiting for key", e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!running) {
|
||||
log.info("Exiting watch thread.");
|
||||
return;
|
||||
}
|
||||
|
||||
Path dir = keys.get(key);
|
||||
if (dir == null) {
|
||||
log.warn("Detected unknown key: {}. Ignoring.", key.toString());
|
||||
continue;
|
||||
}
|
||||
|
||||
detectChanges(key, dir);
|
||||
|
||||
if (!key.reset()) {
|
||||
keys.remove(key);
|
||||
if (keys.isEmpty()) {
|
||||
log.info("No longer watching any directories. Exiting.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
watchThread.start();
|
||||
}
|
||||
|
||||
private void detectChanges(@NotNull WatchKey key, Path dir) {
|
||||
for (WatchEvent<?> event : key.pollEvents()) {
|
||||
WatchEvent.Kind<?> kind = event.kind();
|
||||
|
||||
if (kind == StandardWatchEventKinds.OVERFLOW) {
|
||||
log.warn("Detected overflow event. Ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
Path child = resolveEventPath(event, dir);
|
||||
boolean isDirectory = Files.isDirectory(child);
|
||||
|
||||
if (shouldIgnoreDirectoryEvent(isDirectory, dir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kind == StandardWatchEventKinds.ENTRY_CREATE && isDirectory) {
|
||||
handleNewDirectoryCreation(child);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isDirectory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
handleFileEvent(kind, child);
|
||||
}
|
||||
}
|
||||
|
||||
private @NotNull Path resolveEventPath(@NotNull WatchEvent<?> event, Path dir) {
|
||||
Object context = event.context();
|
||||
if (!(context instanceof Path path)) {
|
||||
throw new IllegalArgumentException("Expected event context to be a Path, but got: " + context);
|
||||
}
|
||||
|
||||
return dir.resolve(path);
|
||||
}
|
||||
|
||||
|
||||
private boolean shouldIgnoreDirectoryEvent(boolean isDirectory, Path dir) {
|
||||
if (isDirectory && !dir.equals(rootDirectory)) {
|
||||
log.warn("Detected directory {} outside of root directory. Ignoring.", dir);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleNewDirectoryCreation(Path child) {
|
||||
try {
|
||||
log.info("Registering new directory: {}", child);
|
||||
registerAll(child);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to register directory: {}", child);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFileEvent(WatchEvent.Kind<?> kind, Path child) {
|
||||
if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
|
||||
log.debug("Detected file modification: {}", child);
|
||||
reloadFile(child);
|
||||
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
|
||||
log.debug("Detected file deletion: {}", child);
|
||||
handleFileDeletion();
|
||||
} else if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
|
||||
log.debug("Detected file creation: {}", child);
|
||||
reloadFile(child);
|
||||
} else {
|
||||
log.warn("Unknown event kind: {}", kind);
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadFile(Path child) {
|
||||
ParticleConfig.loadParticleFromFile(child.toFile());
|
||||
}
|
||||
|
||||
private void handleFileDeletion() {
|
||||
log.info("Detected file deletion. Reloading all particles.");
|
||||
ParticleConfig.reload();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,26 +2,18 @@ package com.alttd.storage;
|
|||
|
||||
import com.alttd.objects.APartType;
|
||||
import com.alttd.objects.ParticleSet;
|
||||
import com.alttd.util.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ParticleStorage {
|
||||
private static final HashMap<APartType, List<ParticleSet>> particles = new HashMap<>();
|
||||
|
||||
public static void addParticleSet(APartType aPartType, ParticleSet particleSet) {
|
||||
List<ParticleSet> particleSets = particles.getOrDefault(aPartType, new ArrayList<>());
|
||||
Optional<ParticleSet> existingParticleSet = particleSets.stream()
|
||||
.filter(p -> p.getParticleId().equalsIgnoreCase(particleSet.getParticleId()))
|
||||
.findAny();
|
||||
if (existingParticleSet.isPresent()) {
|
||||
Logger.warning("Overwriting particle set %", particleSet.getParticleId());
|
||||
particleSets.remove(existingParticleSet.get());
|
||||
if (particleSets.contains(particleSet))
|
||||
return;
|
||||
}
|
||||
particleSets.add(particleSet);
|
||||
particles.put(aPartType, particleSets);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user