Compare commits
3 Commits
1caef4bb83
...
c163885345
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c163885345 | ||
|
|
95bb1e90fe | ||
|
|
a3b4922b70 |
|
|
@ -36,6 +36,18 @@ tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT")
|
// Cosmos
|
||||||
|
compileOnly("com.alttd.cosmos:cosmos-api:1.21.6-R0.1-SNAPSHOT") {
|
||||||
|
isChanging = true
|
||||||
|
}
|
||||||
|
// Lombok
|
||||||
|
compileOnly("org.projectlombok:lombok:1.18.32")
|
||||||
|
annotationProcessor("org.projectlombok:lombok:1.18.32")
|
||||||
|
// Premium vanish
|
||||||
compileOnly("com.github.LeonMangler:PremiumVanishAPI:2.9.0-4")
|
compileOnly("com.github.LeonMangler:PremiumVanishAPI:2.9.0-4")
|
||||||
|
// Jackson/Dynamic Beans Integration
|
||||||
|
implementation("com.fasterxml.jackson.module:jackson-module-parameter-names:2.15.2")
|
||||||
|
// Jackson for JSON Parsing
|
||||||
|
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
|
||||||
|
implementation("com.fasterxml.jackson.core:jackson-annotations:2.15.2")
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import com.alttd.commands.subcommands.CommandHelp;
|
||||||
import com.alttd.commands.subcommands.CommandReload;
|
import com.alttd.commands.subcommands.CommandReload;
|
||||||
import com.alttd.config.Config;
|
import com.alttd.config.Config;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
import lombok.Getter;
|
||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
@ -15,6 +16,7 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class CommandManager implements CommandExecutor, TabExecutor {
|
public class CommandManager implements CommandExecutor, TabExecutor {
|
||||||
private final List<SubCommand> subCommands;
|
private final List<SubCommand> subCommands;
|
||||||
|
|
||||||
|
|
@ -45,7 +47,7 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
||||||
subCommand = getSubCommand(args[0]);
|
subCommand = getSubCommand(args[0]);
|
||||||
|
|
||||||
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
||||||
commandSender.sendMiniMessage(Config.NO_PERMISSION, null);
|
commandSender.sendRichMessage(Config.NO_PERMISSION);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,7 +63,7 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
||||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||||
.map(SubCommand::getName)
|
.map(SubCommand::getName)
|
||||||
.filter(name -> args.length == 0 || name.startsWith(args[0]))
|
.filter(name -> args.length == 0 || name.startsWith(args[0]))
|
||||||
.collect(Collectors.toList())
|
.toList()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
SubCommand subCommand = getSubCommand(args[0]);
|
SubCommand subCommand = getSubCommand(args[0]);
|
||||||
|
|
@ -71,10 +73,6 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SubCommand> getSubCommands() {
|
|
||||||
return subCommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SubCommand getSubCommand(String cmdName) {
|
private SubCommand getSubCommand(String cmdName) {
|
||||||
return subCommands.stream()
|
return subCommands.stream()
|
||||||
.filter(subCommand -> subCommand.getName().equals(cmdName))
|
.filter(subCommand -> subCommand.getName().equals(cmdName))
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class CommandGUI extends SubCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
if (!(commandSender instanceof Player player)) {
|
if (!(commandSender instanceof Player player)) {
|
||||||
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
|
commandSender.sendRichMessage(Config.NO_CONSOLE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
new OpenParticleGUI(player).open(player);
|
new OpenParticleGUI(player).open(player);
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@ public class CommandHelp extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", commandManager
|
commandSender.sendRichMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", commandManager
|
||||||
.getSubCommands().stream()
|
.getSubCommands().stream()
|
||||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||||
.map(SubCommand::getHelpMessage)
|
.map(SubCommand::getHelpMessage)
|
||||||
.collect(Collectors.joining("\n"))), null);
|
.collect(Collectors.joining("\n"))));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ public class CommandReload extends SubCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
AltitudeParticles.getInstance().reload();
|
AltitudeParticles.getInstance().reload();
|
||||||
commandSender.sendMiniMessage("<green>Reloaded AltitudeParticles config.</green>", null);
|
commandSender.sendRichMessage("<green>Reloaded AltitudeParticles config.</green>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,33 @@
|
||||||
package com.alttd.config;
|
package com.alttd.config;
|
||||||
|
|
||||||
|
import com.alttd.models.ParticleData;
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.models.ParticleInfo;
|
||||||
import com.alttd.objects.AParticle;
|
import com.alttd.objects.AParticle;
|
||||||
import com.alttd.objects.Frame;
|
import com.alttd.objects.Frame;
|
||||||
import com.alttd.objects.ParticleSet;
|
import com.alttd.objects.ParticleSet;
|
||||||
import com.alttd.storage.ParticleStorage;
|
import com.alttd.storage.ParticleStorage;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import com.destroystokyo.paper.ParticleBuilder;
|
import com.destroystokyo.paper.ParticleBuilder;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HexFormat;
|
import java.util.HexFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ParticleConfig {
|
public class ParticleConfig {
|
||||||
|
|
||||||
private static final File particlesDir = new File(File.separator + "mnt" + File.separator + "configs"
|
private static final File particlesDir = new File(File.separator + "mnt" + File.separator + "configs"
|
||||||
+ File.separator + "AltitudeParticles" + File.separator + "particles");
|
+ File.separator + "AltitudeParticles" + File.separator + "particles");
|
||||||
private static ParticleConfig instance = null;
|
private static ParticleConfig instance = null;
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
private static ParticleConfig getInstance() {
|
private static ParticleConfig getInstance() {
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
|
|
@ -60,34 +57,31 @@ public class ParticleConfig {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParticleSet loadParticle(JSONObject jsonObject) throws Exception {
|
/**
|
||||||
String particleName = (String) jsonObject.get("particle_name");
|
* Converts a ParticleData object to a ParticleSet
|
||||||
String displayName = (String) jsonObject.get("display_name");
|
* @param particleData The ParticleData object to convert
|
||||||
APartType aPartType = APartType.valueOf((String) jsonObject.get("particle_type"));
|
* @return A ParticleSet created from the ParticleData
|
||||||
String lore = (String) jsonObject.get("lore");
|
*/
|
||||||
ItemStack displayItem = new ItemStack(Material.valueOf((String) jsonObject.get("display_item")));
|
public ParticleSet convertToParticleSet(ParticleData particleData) {
|
||||||
String permission = (String) jsonObject.get("permission");
|
|
||||||
String packagePermission = (String) jsonObject.get("package_permission");
|
|
||||||
int frameDelay = (int) (long) jsonObject.get("frame_delay");
|
|
||||||
int repeat = (int) (long) jsonObject.get("repeat");
|
|
||||||
int repeatDelay = (int) (long) jsonObject.get("repeat_delay");
|
|
||||||
double randomOffset = (double) jsonObject.get("random_offset");
|
|
||||||
boolean stationary = (boolean) jsonObject.get("stationary");
|
|
||||||
JSONObject frames = (JSONObject) jsonObject.get("frames");
|
|
||||||
List<Frame> loadedFrames = new ArrayList<>();
|
List<Frame> loadedFrames = new ArrayList<>();
|
||||||
for (Object key : frames.keySet()) {
|
double randomOffset = particleData.getRandomOffset();
|
||||||
Object o = frames.get(key);
|
|
||||||
List<AParticle> aParticleList = new ArrayList<>();
|
// Process each frame
|
||||||
for (Object o1 : ((JSONArray) o)) {
|
for (Map.Entry<String, List<ParticleInfo>> entry : particleData.getFrames().entrySet()) {
|
||||||
JSONObject pData = (JSONObject) o1;
|
List<AParticle> aParticleList = new ArrayList<>();
|
||||||
Particle particleType = Particle.valueOf((String) pData.get("particle_type"));
|
|
||||||
|
// Process each particle in the frame
|
||||||
|
for (ParticleInfo particleInfo : entry.getValue()) {
|
||||||
|
Particle particleType = Particle.valueOf(particleInfo.getParticleType());
|
||||||
|
double x = particleInfo.getX();
|
||||||
|
double y = particleInfo.getY();
|
||||||
|
double z = particleInfo.getZ();
|
||||||
|
|
||||||
double x = (double) pData.get("x");
|
|
||||||
double y = (double) pData.get("y");
|
|
||||||
double z = (double) pData.get("z");
|
|
||||||
ParticleBuilder particleBuilder = new ParticleBuilder(particleType);
|
ParticleBuilder particleBuilder = new ParticleBuilder(particleType);
|
||||||
if (particleType.getDataType().equals(Particle.DustOptions.class)) {
|
|
||||||
int rgb = HexFormat.fromHexDigits((String) pData.get("color"));
|
// Handle different particle data types
|
||||||
|
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));
|
particleBuilder.data(new Particle.DustOptions(Color.fromRGB(rgb), 1));
|
||||||
}
|
}
|
||||||
// else if (particleType.getDataType().equals(MaterialData.class)) {
|
// else if (particleType.getDataType().equals(MaterialData.class)) {
|
||||||
|
|
@ -103,38 +97,50 @@ public class ParticleConfig {
|
||||||
//TODO implement
|
//TODO implement
|
||||||
} else if (particleType.getDataType().equals(ItemStack.class)) {
|
} else if (particleType.getDataType().equals(ItemStack.class)) {
|
||||||
//TODO implement
|
//TODO implement
|
||||||
} else {
|
} else if (particleInfo.getExtra() != null) {
|
||||||
double data = (double) pData.get("extra");
|
particleBuilder.extra(particleInfo.getExtra());
|
||||||
particleBuilder.extra(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aParticleList.add(new AParticle(x, y, z, randomOffset, particleBuilder));
|
aParticleList.add(new AParticle(x, y, z, randomOffset, particleBuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedFrames.add(new Frame(aParticleList));
|
loadedFrames.add(new Frame(aParticleList));
|
||||||
}
|
}
|
||||||
return new ParticleSet(loadedFrames, displayName, List.of(lore.split("\n")), frameDelay, repeat, repeatDelay, stationary, aPartType, particleName, permission, packagePermission, displayItem);
|
|
||||||
|
// Create and return the ParticleSet
|
||||||
|
ItemStack displayItem = new ItemStack(Material.valueOf(particleData.getDisplayItem()));
|
||||||
|
return new ParticleSet(
|
||||||
|
loadedFrames,
|
||||||
|
particleData.getDisplayName(),
|
||||||
|
List.of(particleData.getLore().split("\n")),
|
||||||
|
particleData.getFrameDelay(),
|
||||||
|
particleData.getRepeat(),
|
||||||
|
particleData.getRepeatDelay(),
|
||||||
|
particleData.isStationary(),
|
||||||
|
particleData.getAPartType(),
|
||||||
|
particleData.getParticleName(),
|
||||||
|
particleData.getPermission(),
|
||||||
|
particleData.getPackagePermission(),
|
||||||
|
displayItem
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
ParticleStorage.clear();
|
ParticleStorage.clear();
|
||||||
ParticleConfig instance = getInstance();
|
ParticleConfig instance = getInstance();
|
||||||
|
|
||||||
for (File file : instance.getJsonFiles()) {
|
for (File file : instance.getJsonFiles()) {
|
||||||
JSONParser parser = new JSONParser();
|
|
||||||
try {
|
try {
|
||||||
Object obj = parser.parse(new FileReader(file));
|
ParticleData particleData = objectMapper.readValue(file, ParticleData.class);
|
||||||
ParticleSet particleSet = instance.loadParticle((JSONObject) obj);
|
|
||||||
|
ParticleSet particleSet = instance.convertToParticleSet(particleData);
|
||||||
|
|
||||||
ParticleStorage.addParticleSet(particleSet.getAPartType(), particleSet);
|
ParticleStorage.addParticleSet(particleSet.getAPartType(), particleSet);
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
Logger.error("Error reading particle file " + file.getName(), e);
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
exception.printStackTrace();
|
Logger.error("Error processing particle file " + file.getName(), exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO implement
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,12 @@
|
||||||
package com.alttd.listeners;
|
package com.alttd.listeners;
|
||||||
|
|
||||||
import com.alttd.AltitudeParticles;
|
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.objects.ParticleSet;
|
|
||||||
import com.alttd.storage.PlayerSettings;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BlockBreakListener implements Listener {
|
public class BlockBreakListener implements Listener {
|
||||||
|
|
||||||
|
|
@ -27,21 +20,7 @@ public class BlockBreakListener implements Listener {
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
new BukkitRunnable() {
|
SpawnParticleUtil.spawnAsyncParticles(particlesToActivate, event.getPlayer(), () ->
|
||||||
@Override
|
event.getBlock().getLocation());
|
||||||
public void run() {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(uuid);
|
|
||||||
if (!playerSettings.hasActiveParticles())
|
|
||||||
return;
|
|
||||||
particlesToActivate.forEach(aPartType -> {
|
|
||||||
ParticleSet particleSet = playerSettings.getParticles(aPartType);
|
|
||||||
if (particleSet == null)
|
|
||||||
return;
|
|
||||||
particleSet.run(event.getBlock().getLocation(), player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(AltitudeParticles.getInstance());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,12 @@
|
||||||
package com.alttd.listeners;
|
package com.alttd.listeners;
|
||||||
|
|
||||||
import com.alttd.AltitudeParticles;
|
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.objects.ParticleSet;
|
|
||||||
import com.alttd.storage.PlayerSettings;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BlockPlaceListener implements Listener {
|
public class BlockPlaceListener implements Listener {
|
||||||
|
|
||||||
|
|
@ -27,21 +20,7 @@ public class BlockPlaceListener implements Listener {
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
new BukkitRunnable() {
|
SpawnParticleUtil.spawnAsyncParticles(particlesToActivate, event.getPlayer(), () ->
|
||||||
@Override
|
event.getBlock().getLocation());
|
||||||
public void run() {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(uuid);
|
|
||||||
if (!playerSettings.hasActiveParticles())
|
|
||||||
return;
|
|
||||||
particlesToActivate.forEach(aPartType -> {
|
|
||||||
ParticleSet particleSet = playerSettings.getParticles(aPartType);
|
|
||||||
if (particleSet == null)
|
|
||||||
return;
|
|
||||||
particleSet.run(event.getBlock().getLocation(), player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(AltitudeParticles.getInstance());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,13 @@
|
||||||
package com.alttd.listeners;
|
package com.alttd.listeners;
|
||||||
|
|
||||||
import com.alttd.AltitudeParticles;
|
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.objects.ParticleSet;
|
|
||||||
import com.alttd.storage.PlayerSettings;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class DeathListener implements Listener {
|
public class DeathListener implements Listener {
|
||||||
|
|
||||||
|
|
@ -26,21 +21,7 @@ public class DeathListener implements Listener {
|
||||||
public void onDeath(PlayerDeathEvent event) {
|
public void onDeath(PlayerDeathEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
new BukkitRunnable() {
|
Player player = event.getPlayer();
|
||||||
@Override
|
SpawnParticleUtil.spawnAsyncParticles(particlesToActivate, player, player::getLocation);
|
||||||
public void run() {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(uuid);
|
|
||||||
if (!playerSettings.hasActiveParticles())
|
|
||||||
return;
|
|
||||||
particlesToActivate.forEach(aPartType -> {
|
|
||||||
ParticleSet particleSet = playerSettings.getParticles(aPartType);
|
|
||||||
if (particleSet == null)
|
|
||||||
return;
|
|
||||||
particleSet.run(player.getLocation(), player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(AltitudeParticles.getInstance());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,13 @@
|
||||||
package com.alttd.listeners;
|
package com.alttd.listeners;
|
||||||
|
|
||||||
import com.alttd.AltitudeParticles;
|
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.objects.ParticleSet;
|
|
||||||
import com.alttd.storage.PlayerSettings;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class KillListener implements Listener {
|
public class KillListener implements Listener {
|
||||||
private final List<APartType> particlesToActivate;
|
private final List<APartType> particlesToActivate;
|
||||||
|
|
@ -29,20 +23,6 @@ public class KillListener implements Listener {
|
||||||
Player player = event.getEntity().getKiller();
|
Player player = event.getEntity().getKiller();
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
new BukkitRunnable() {
|
SpawnParticleUtil.spawnAsyncParticles(particlesToActivate, player, () -> event.getEntity().getLocation());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(uuid);
|
|
||||||
if (!playerSettings.hasActiveParticles())
|
|
||||||
return;
|
|
||||||
particlesToActivate.forEach(aPartType -> {
|
|
||||||
ParticleSet particleSet = playerSettings.getParticles(aPartType);
|
|
||||||
if (particleSet == null)
|
|
||||||
return;
|
|
||||||
particleSet.run(event.getEntity().getLocation(), player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(AltitudeParticles.getInstance());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
public class PlayerQuitListener implements Listener {
|
public class PlayerQuitListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
public void onPlayerLeave(PlayerQuitEvent event) { //TODO particles when a player leaves
|
||||||
PlayerSettings.removePlayer(event.getPlayer().getUniqueId());
|
PlayerSettings.removePlayer(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
package com.alttd.listeners;
|
package com.alttd.listeners;
|
||||||
|
|
||||||
import com.alttd.AltitudeParticles;
|
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.objects.ParticleSet;
|
|
||||||
import com.alttd.storage.PlayerSettings;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -14,10 +11,8 @@ import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class RightClickListener implements Listener {
|
public class RightClickListener implements Listener {
|
||||||
|
|
||||||
|
|
@ -38,22 +33,7 @@ public class RightClickListener implements Listener {
|
||||||
Block clickedBlock = event.getClickedBlock();
|
Block clickedBlock = event.getClickedBlock();
|
||||||
if (clickedBlock == null)
|
if (clickedBlock == null)
|
||||||
return;
|
return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
new BukkitRunnable() {
|
SpawnParticleUtil.spawnAsyncParticles(particlesToActivate, player, player::getLocation);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(uuid);
|
|
||||||
if (!playerSettings.hasActiveParticles())
|
|
||||||
return;
|
|
||||||
particlesToActivate.forEach(aPartType -> {
|
|
||||||
ParticleSet particleSet = playerSettings.getParticles(aPartType);
|
|
||||||
if (particleSet == null)
|
|
||||||
return;
|
|
||||||
particleSet.run(player.getLocation(), player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(AltitudeParticles.getInstance());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
src/main/java/com/alttd/listeners/SpawnParticleUtil.java
Normal file
43
src/main/java/com/alttd/listeners/SpawnParticleUtil.java
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.alttd.listeners;
|
||||||
|
|
||||||
|
import com.alttd.AltitudeParticles;
|
||||||
|
import com.alttd.objects.APartType;
|
||||||
|
import com.alttd.objects.ParticleSet;
|
||||||
|
import com.alttd.storage.PlayerSettings;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class SpawnParticleUtil {
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface LocationConsumer {
|
||||||
|
Location getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void spawnAsyncParticles(List<APartType> particlesToActivate, Player player, LocationConsumer locationConsumer) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
spawn(particlesToActivate, player, locationConsumer);
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(AltitudeParticles.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void spawn(List<APartType> particlesToActivate, Player player, LocationConsumer locationConsumer) {
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
PlayerSettings playerSettings = PlayerSettings.getPlayer(uuid);
|
||||||
|
if (!playerSettings.hasActiveParticles())
|
||||||
|
return;
|
||||||
|
particlesToActivate.forEach(aPartType -> {
|
||||||
|
ParticleSet particleSet = playerSettings.getParticles(aPartType);
|
||||||
|
if (particleSet == null)
|
||||||
|
return;
|
||||||
|
particleSet.run(locationConsumer.getLocation(), player);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,19 +1,12 @@
|
||||||
package com.alttd.listeners;
|
package com.alttd.listeners;
|
||||||
|
|
||||||
import com.alttd.AltitudeParticles;
|
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.objects.ParticleSet;
|
|
||||||
import com.alttd.storage.PlayerSettings;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class TeleportArriveListener implements Listener {
|
public class TeleportArriveListener implements Listener {
|
||||||
private final List<APartType> particlesToActivate;
|
private final List<APartType> particlesToActivate;
|
||||||
|
|
@ -26,22 +19,7 @@ public class TeleportArriveListener implements Listener {
|
||||||
public void onTeleportArrive(PlayerTeleportEvent event) {
|
public void onTeleportArrive(PlayerTeleportEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
new BukkitRunnable() {
|
SpawnParticleUtil.spawnAsyncParticles(particlesToActivate, event.getPlayer(), event::getTo);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(uuid);
|
|
||||||
if (!playerSettings.hasActiveParticles())
|
|
||||||
return;
|
|
||||||
particlesToActivate.forEach(aPartType -> {
|
|
||||||
ParticleSet particleSet = playerSettings.getParticles(aPartType);
|
|
||||||
if (particleSet == null)
|
|
||||||
return;
|
|
||||||
particleSet.run(event.getTo(), player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(AltitudeParticles.getInstance());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
77
src/main/java/com/alttd/models/ParticleData.java
Normal file
77
src/main/java/com/alttd/models/ParticleData.java
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.alttd.models;
|
||||||
|
|
||||||
|
import com.alttd.objects.APartType;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the configuration data for a particle effect, including its name, type, display properties,
|
||||||
|
* animations, and permissions. This class is primarily used for managing particle data in the context
|
||||||
|
* of custom particle effects and animations.
|
||||||
|
* <p>
|
||||||
|
* Fields:
|
||||||
|
* - particleName: The unique name of the particle effect, used internally.
|
||||||
|
* - displayName: The name displayed to the user.
|
||||||
|
* - particleType: The type of the particle effect, which corresponds to an {@link APartType}.
|
||||||
|
* - lore: Additional descriptive text associated with the particle effect.
|
||||||
|
* - displayItem: An item representation for display purposes in order to visually represent the effect.
|
||||||
|
* - permission: The permission string required for accessing the particle effect.
|
||||||
|
* - packagePermission: A specific permission string linked to a grouped set of effects.
|
||||||
|
* - frameDelay: The delay between animation frames, in milliseconds.
|
||||||
|
* - repeat: The number of times the particle animation should repeat.
|
||||||
|
* - repeatDelay: The delay between repeat executions, in milliseconds.
|
||||||
|
* - randomOffset: A random position offset applied to the particle effect for variances.
|
||||||
|
* - stationary: Determines if the particle effect remains static or follows movement.
|
||||||
|
* - frames: A map defining animation frames for the particle effect. The key is an identifier, and the
|
||||||
|
* value is a list of {@link ParticleInfo} objects representing the frame's particle configuration.
|
||||||
|
* <p>
|
||||||
|
* Methods:
|
||||||
|
* - getAPartType(): Converts the particleType string field into an equivalent {@link APartType} enum value.
|
||||||
|
* This allows for accessing predefined properties of the particle type.
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class ParticleData {
|
||||||
|
@JsonProperty("particle_name")
|
||||||
|
private String particleName;
|
||||||
|
|
||||||
|
@JsonProperty("display_name")
|
||||||
|
private String displayName;
|
||||||
|
|
||||||
|
@JsonProperty("particle_type")
|
||||||
|
private String particleType;
|
||||||
|
|
||||||
|
private String lore;
|
||||||
|
|
||||||
|
@JsonProperty("display_item")
|
||||||
|
private String displayItem;
|
||||||
|
|
||||||
|
private String permission;
|
||||||
|
|
||||||
|
@JsonProperty("package_permission")
|
||||||
|
private String packagePermission;
|
||||||
|
|
||||||
|
@JsonProperty("frame_delay")
|
||||||
|
private int frameDelay;
|
||||||
|
|
||||||
|
private int repeat;
|
||||||
|
|
||||||
|
@JsonProperty("repeat_delay")
|
||||||
|
private int repeatDelay;
|
||||||
|
|
||||||
|
@JsonProperty("random_offset")
|
||||||
|
private double randomOffset;
|
||||||
|
|
||||||
|
private boolean stationary;
|
||||||
|
|
||||||
|
private Map<String, List<ParticleInfo>> frames;
|
||||||
|
|
||||||
|
public APartType getAPartType() {
|
||||||
|
return APartType.valueOf(particleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
src/main/java/com/alttd/models/ParticleInfo.java
Normal file
39
src/main/java/com/alttd/models/ParticleInfo.java
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.alttd.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents information about a particle, including its type, position, and additional properties.
|
||||||
|
* This class is used to describe the details of individual particles, including support for
|
||||||
|
* particle-specific attributes such as color and extra data.
|
||||||
|
* <p>
|
||||||
|
* Fields:
|
||||||
|
* - particleType: The type of the particle, as defined by its name or identifier.
|
||||||
|
* - x, y, z: Coordinates representing the position of the particle in the 3D space.
|
||||||
|
* - color: A string representing the color of the particle, used primarily for "DustOptions".
|
||||||
|
* - extra: An additional property used for some specific particle types, allowing for further customization.
|
||||||
|
* <p>
|
||||||
|
* The class is annotated for JSON serialization and deserialization using the Jackson library,
|
||||||
|
* ensuring smooth integration with JSON-based configurations.
|
||||||
|
* <p>
|
||||||
|
* This object is used in the context of particle data configurations and animations.
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class ParticleInfo {
|
||||||
|
@JsonProperty("particle_type")
|
||||||
|
private String particleType;
|
||||||
|
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
private double z;
|
||||||
|
|
||||||
|
// For DustOptions
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
// For other particle types
|
||||||
|
private Double extra;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.util;
|
||||||
|
|
||||||
import com.alttd.AltitudeParticles;
|
import com.alttd.AltitudeParticles;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Logger {
|
public class Logger {
|
||||||
|
|
||||||
static private final java.util.logging.Logger logger;
|
static private final java.util.logging.Logger logger;
|
||||||
|
|
@ -33,4 +35,8 @@ public class Logger {
|
||||||
}
|
}
|
||||||
logger.severe(severe);
|
logger.severe(severe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void error(String error, Throwable throwable) {
|
||||||
|
logger.log(Level.SEVERE, error, throwable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user