From 15a1d9c74ed75945cb6cd38eb8acd144a56f674e Mon Sep 17 00:00:00 2001 From: Esophose Date: Fri, 5 Oct 2018 21:01:28 -0600 Subject: [PATCH] /pp add | /pp help finished and working --- .../command/AddCommandModule.java | 60 +++++++++++++++++-- .../command/CommandModule.java | 25 +++++++- .../command/DefaultCommandModule.java | 12 +++- .../command/HelpCommandModule.java | 5 +- .../command/ParticleCommandHandler.java | 29 ++++++++- .../gui/PlayerParticlesGui.java | 12 ++-- .../playerparticles/manager/DataManager.java | 22 +++++-- .../playerparticles/manager/LangManager.java | 34 ++++++----- .../manager/ParticleManager.java | 10 ++-- .../playerparticles/particles/PPlayer.java | 2 +- .../particles/ParticleGroup.java | 4 +- .../styles/ParticleStyleBlockBreak.java | 4 +- .../styles/ParticleStyleBlockEdit.java | 2 +- .../styles/ParticleStyleBlockPlace.java | 4 +- .../styles/ParticleStyleCube.java | 4 +- .../styles/ParticleStyleMove.java | 2 +- .../playerparticles/util/ParticleUtils.java | 27 +++++---- src/config.yml | 4 +- src/lang/{en_US.lang => default.lang} | 27 +++++---- 19 files changed, 210 insertions(+), 79 deletions(-) rename src/lang/{en_US.lang => default.lang} (84%) diff --git a/src/com/esophose/playerparticles/command/AddCommandModule.java b/src/com/esophose/playerparticles/command/AddCommandModule.java index 82a7b04..a884742 100644 --- a/src/com/esophose/playerparticles/command/AddCommandModule.java +++ b/src/com/esophose/playerparticles/command/AddCommandModule.java @@ -1,14 +1,18 @@ package com.esophose.playerparticles.command; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; import com.esophose.playerparticles.manager.DataManager; import com.esophose.playerparticles.manager.LangManager; +import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.PermissionManager; -import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.particles.PPlayer; import com.esophose.playerparticles.particles.ParticleEffect; import com.esophose.playerparticles.particles.ParticleEffect.NoteColor; @@ -116,15 +120,59 @@ public class AddCommandModule implements CommandModule { } } } - - ParticleGroup group = pplayer.getActiveParticleGroup(); - group.getParticles().add(new ParticlePair(pplayer.getUniqueId(), pplayer.getNextActiveParticleId(), effect, style, blockData, blockData, colorData, noteColorData)); - DataManager.saveParticleGroup(pplayer.getUniqueId(), group); } + + ParticleGroup group = pplayer.getActiveParticleGroup(); + ParticlePair newParticle = new ParticlePair(pplayer.getUniqueId(), pplayer.getNextActiveParticleId(), effect, style, blockData, blockData, colorData, noteColorData); + group.getParticles().add(newParticle); + DataManager.saveParticleGroup(pplayer.getUniqueId(), group); + + LangManager.sendMessage(pplayer, Lang.COMMAND_ADD_PARTICLE_APPLIED, newParticle.getEffect().getName(), newParticle.getStyle().getName(), newParticle.getDataString()); } public List onTabComplete(PPlayer pplayer, String[] args) { - return null; + Player p = pplayer.getPlayer(); + List matches = new ArrayList(); + System.out.println("Args in AddCommandModule: " + Arrays.toString(args) + " " + args.length); + if (args.length <= 1) { // Effect name + if (args.length == 0) matches = PermissionManager.getEffectsUserHasPermissionFor(p); + else StringUtil.copyPartialMatches(args[0], PermissionManager.getEffectsUserHasPermissionFor(p), matches); + } else if (args.length == 2) { // Style name + StringUtil.copyPartialMatches(args[1], PermissionManager.getStylesUserHasPermissionFor(p), matches); + } else if (args.length >= 3) { // Data + ParticleEffect effect = ParticleEffect.fromName(args[0]); + if (effect != null) { + if (effect.hasProperty(ParticleProperty.COLORABLE)) { + List possibleValues = new ArrayList(); + if (effect == ParticleEffect.NOTE) { // Note data + if (args.length == 3) { + possibleValues.add("<0-23>"); + possibleValues.add("rainbow"); + } + } else { // Color data + if (args.length <= 5 && !args[2].equalsIgnoreCase("rainbow")) { + possibleValues.add("<0-255>"); + } + if (args.length <= 4 && !args[2].equalsIgnoreCase("rainbow")) { + possibleValues.add("<0-255> <0-255>"); + } + if (args.length <= 3) { + possibleValues.add("<0-255> <0-255> <0-255>"); + possibleValues.add("rainbow"); + } + } + StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches); + } else if (args.length == 3 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { + if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material + matches = StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllBlockMaterials(), matches); + } else if (effect == ParticleEffect.ITEM) { // Item material + matches = StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllItemMaterials(), matches); + } + } + } + } + + return matches; } public String getName() { diff --git a/src/com/esophose/playerparticles/command/CommandModule.java b/src/com/esophose/playerparticles/command/CommandModule.java index bafcf87..5f45ca1 100644 --- a/src/com/esophose/playerparticles/command/CommandModule.java +++ b/src/com/esophose/playerparticles/command/CommandModule.java @@ -1,11 +1,14 @@ package com.esophose.playerparticles.command; +import java.text.MessageFormat; import java.util.List; import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.particles.PPlayer; +import net.md_5.bungee.api.ChatColor; + public interface CommandModule { /** @@ -59,7 +62,24 @@ public interface CommandModule { * @param command The command to display usage for */ public static void printUsage(PPlayer pplayer, CommandModule command) { - LangManager.sendCustomMessage(pplayer, String.format("/{0} {1}", command.getName(), command.getArguments())); + Object[] args = new Object[] { command.getName(), command.getArguments() }; + LangManager.sendCustomMessage(pplayer, new MessageFormat(ChatColor.YELLOW + "/pp {0} {1}").format(args)); + } + + /** + * Displays a command's usage (with its description) to the player + * + * @param pplayer The PPlayer to display the command usage to + * @param command The command to display usage for + */ + public static void printUsageWithDescription(PPlayer pplayer, CommandModule command) { + if (command.getArguments().length() == 0) { + Object[] args = new Object[] { command.getName(), LangManager.getText(command.getDescription()) }; + LangManager.sendCustomMessage(pplayer, new MessageFormat(ChatColor.YELLOW + "/pp {0} - {1}").format(args)); + } else { + Object[] args = new Object[] { command.getName(), command.getArguments(), LangManager.getText(command.getDescription()) }; + LangManager.sendCustomMessage(pplayer, new MessageFormat(ChatColor.YELLOW + "/pp {0} {1} - {2}").format(args)); + } } /** @@ -71,7 +91,8 @@ public interface CommandModule { * @param subCommandArgs The sub-command's arguments */ public static void printSubcommandUsage(PPlayer pplayer, CommandModule command, String subCommandName, String subCommandArgs) { - LangManager.sendCustomMessage(pplayer, String.format("/{0} {1} {2}", command.getName(), subCommandName, subCommandArgs)); + Object[] args = new Object[] { command.getName(), subCommandName, subCommandArgs }; + LangManager.sendCustomMessage(pplayer, new MessageFormat(ChatColor.YELLOW + "/pp {0} {1} {2}").format(args)); } } diff --git a/src/com/esophose/playerparticles/command/DefaultCommandModule.java b/src/com/esophose/playerparticles/command/DefaultCommandModule.java index e9fac80..f2e04f4 100644 --- a/src/com/esophose/playerparticles/command/DefaultCommandModule.java +++ b/src/com/esophose/playerparticles/command/DefaultCommandModule.java @@ -1,7 +1,10 @@ package com.esophose.playerparticles.command; +import java.util.ArrayList; import java.util.List; +import org.bukkit.util.StringUtil; + import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.particles.PPlayer; @@ -13,7 +16,14 @@ public class DefaultCommandModule implements CommandModule { } public List onTabComplete(PPlayer pplayer, String[] args) { - return null; + List matches = new ArrayList(); + List commandNames = ParticleCommandHandler.getCommandNames(); + + if (args.length == 0) return commandNames; + + StringUtil.copyPartialMatches(args[0], commandNames, matches); + + return matches; } public String getName() { diff --git a/src/com/esophose/playerparticles/command/HelpCommandModule.java b/src/com/esophose/playerparticles/command/HelpCommandModule.java index e575552..fb85a9c 100644 --- a/src/com/esophose/playerparticles/command/HelpCommandModule.java +++ b/src/com/esophose/playerparticles/command/HelpCommandModule.java @@ -8,7 +8,10 @@ import com.esophose.playerparticles.particles.PPlayer; public class HelpCommandModule implements CommandModule { public void onCommandExecute(PPlayer pplayer, String[] args) { - // TODO: Rewrite to be dynamically generated from the ParticleCommandHandler's registered CommandModules + List cmds = ParticleCommandHandler.getCommands(); + for (CommandModule cmd : cmds) { + CommandModule.printUsageWithDescription(pplayer, cmd); + } } public List onTabComplete(PPlayer pplayer, String[] args) { diff --git a/src/com/esophose/playerparticles/command/ParticleCommandHandler.java b/src/com/esophose/playerparticles/command/ParticleCommandHandler.java index 784ad60..2384b53 100644 --- a/src/com/esophose/playerparticles/command/ParticleCommandHandler.java +++ b/src/com/esophose/playerparticles/command/ParticleCommandHandler.java @@ -57,6 +57,27 @@ public class ParticleCommandHandler implements CommandExecutor, TabCompleter { return commandModule; return null; } + + /** + * Get a list of all available commands + * + * @return A List of all CommandModules registered + */ + public static List getCommands() { + return commands; + } + + /** + * Get all available command names + * + * @return All available command names + */ + public static List getCommandNames() { + List commandNames = new ArrayList(); + for (CommandModule cmd : commands) + commandNames.add(cmd.getName()); + return commandNames; + } /** * Called when a player executes a /pp command @@ -110,10 +131,14 @@ public class ParticleCommandHandler implements CommandExecutor, TabCompleter { if (!(sender instanceof Player)) return new ArrayList(); if (cmd.getName().equalsIgnoreCase("pp")) { - if (args.length > 1) { + System.out.println("Args in onTabComplete: " + Arrays.toString(args) + " " + args.length); + if (args.length <= 1) { + CommandModule commandModule = findMatchingCommand(""); // Get the default command module + return commandModule.onTabComplete(DataManager.getPPlayer(((Player) sender).getUniqueId()), args); + } else if (args.length >= 2) { CommandModule commandModule = findMatchingCommand(args[0]); + String[] cmdArgs = Arrays.copyOfRange(args, 1, args.length); if (commandModule != null) { - String[] cmdArgs = Arrays.copyOfRange(args, 1, args.length); return commandModule.onTabComplete(DataManager.getPPlayer(((Player) sender).getUniqueId()), cmdArgs); } diff --git a/src/com/esophose/playerparticles/gui/PlayerParticlesGui.java b/src/com/esophose/playerparticles/gui/PlayerParticlesGui.java index 18c7a57..6ade10c 100644 --- a/src/com/esophose/playerparticles/gui/PlayerParticlesGui.java +++ b/src/com/esophose/playerparticles/gui/PlayerParticlesGui.java @@ -250,7 +250,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener { particles.clear(); particles.add(particle); - ParticleGroup group = new ParticleGroup(null, particles); + ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles); DataManager.saveParticleGroup(pplayer.getUniqueId(), group); } @@ -264,7 +264,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener { particles.clear(); particles.add(particle); - ParticleGroup group = new ParticleGroup(null, particles); + ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles); DataManager.saveParticleGroup(pplayer.getUniqueId(), group); } @@ -278,7 +278,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener { particles.clear(); particles.add(particle); - ParticleGroup group = new ParticleGroup(null, particles); + ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles); DataManager.saveParticleGroup(pplayer.getUniqueId(), group); } @@ -292,7 +292,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener { particles.clear(); particles.add(particle); - ParticleGroup group = new ParticleGroup(null, particles); + ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles); DataManager.saveParticleGroup(pplayer.getUniqueId(), group); } @@ -306,7 +306,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener { particles.clear(); particles.add(particle); - ParticleGroup group = new ParticleGroup(null, particles); + ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles); DataManager.saveParticleGroup(pplayer.getUniqueId(), group); } @@ -320,7 +320,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener { particles.clear(); particles.add(particle); - ParticleGroup group = new ParticleGroup(null, particles); + ParticleGroup group = new ParticleGroup(ParticleGroup.DEFAULT_NAME, particles); DataManager.saveParticleGroup(pplayer.getUniqueId(), group); } diff --git a/src/com/esophose/playerparticles/manager/DataManager.java b/src/com/esophose/playerparticles/manager/DataManager.java index f653b68..5ee0c83 100644 --- a/src/com/esophose/playerparticles/manager/DataManager.java +++ b/src/com/esophose/playerparticles/manager/DataManager.java @@ -88,9 +88,10 @@ public class DataManager { "WHERE g.owner_uuid = ?"; // @formatter:on try (PreparedStatement statement = connection.prepareStatement(groupQuery)) { statement.setString(1, playerUUID.toString()); - + System.out.println("Executing particle query"); ResultSet result = statement.executeQuery(); while (result.next()) { + System.out.println("Particle result found"); // Group properties String groupName = result.getString("name"); @@ -103,6 +104,15 @@ public class DataManager { NoteColor noteColor = new NoteColor(result.getInt("note")); OrdinaryColor color = new OrdinaryColor(result.getInt("r"), result.getInt("g"), result.getInt("b")); ParticlePair particle = new ParticlePair(playerUUID, id, effect, style, itemMaterial, blockMaterial, color, noteColor); + + System.out.println("=============================="); + System.out.println(result.getInt("id")); + System.out.println(result.getString("effect")); + System.out.println(result.getString("style")); + System.out.println(result.getString("item_material")); + System.out.println(result.getString("block_material")); + System.out.println(result.getInt("note")); + System.out.println(result.getInt("r") + " " + result.getInt("g") + " " + result.getInt("b")); // Try to add particle to an existing group boolean groupAlreadyExists = false; @@ -155,7 +165,7 @@ public class DataManager { } if (groups.size() == 0) { // If there aren't any groups then this is a brand new PPlayer and we need to save a new active group for them - ParticleGroup activeGroup = new ParticleGroup(null, new ArrayList()); + ParticleGroup activeGroup = new ParticleGroup(ParticleGroup.DEFAULT_NAME, new ArrayList()); saveParticleGroup(playerUUID, activeGroup); groups.add(activeGroup); } @@ -222,15 +232,15 @@ public class DataManager { particlesStatement.setInt(11, particle.getColor().getBlue()); particlesStatement.addBatch(); } + + particlesStatement.executeBatch(); } }); }); getPPlayer(playerUUID, (pplayer) -> { - String groupName = group.getName() == null ? "" : group.getName(); for (ParticleGroup existing : pplayer.getParticles()) { - String existingName = existing.getName() == null ? "" : existing.getName(); - if (groupName.equalsIgnoreCase(existingName)) { + if (group.getName().equalsIgnoreCase(existing.getName())) { pplayer.getParticles().remove(existing); break; } @@ -298,7 +308,7 @@ public class DataManager { try (PreparedStatement statement = connection.prepareStatement(particleQuery)) { ParticlePair particle = fixedEffect.getParticlePair(); statement.setString(1, particleUUID); - statement.setString(2, null); + statement.setNull(2, java.sql.Types.VARCHAR); statement.setInt(3, fixedEffect.getId()); statement.setString(4, particle.getEffect().getName()); statement.setString(5, particle.getStyle().getName()); diff --git a/src/com/esophose/playerparticles/manager/LangManager.java b/src/com/esophose/playerparticles/manager/LangManager.java index 7ca75d7..4b95762 100644 --- a/src/com/esophose/playerparticles/manager/LangManager.java +++ b/src/com/esophose/playerparticles/manager/LangManager.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.MessageFormat; import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; @@ -55,6 +56,9 @@ public class LangManager { COMMAND_DESCRIPTION_GROUP_LOAD, COMMAND_DESCRIPTION_GROUP_REMOVE, + // Add Command + COMMAND_ADD_PARTICLE_APPLIED, + // Effects EFFECT_NO_PERMISSION, EFFECT_INVALID, @@ -158,8 +162,8 @@ public class LangManager { * * @return The message */ - private String get(String... replacements) { - return String.format(this.message, (Object[]) replacements); + private String get(Object... replacements) { + return new MessageFormat(this.message).format(replacements); } } @@ -198,8 +202,8 @@ public class LangManager { /** * Loads the target .lang file as defined in the config and grabs its YamlConfiguration - * If it doesn't exist, default to en_US.lang - * If en_US.lang doesn't exist, copy the file from this .jar to the target directory + * If it doesn't exist, default to default.lang + * If default.lang doesn't exist, copy the file from this .jar to the target directory * * @param config The plugin's configuration file * @return The YamlConfiguration of the target .lang file @@ -209,21 +213,21 @@ public class LangManager { langFileName = config.getString("lang-file"); File targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName); - if (!targetLangFile.exists()) { // Target .lang file didn't exist, default to en_US.lang - if (!langFileName.equals("en_US.lang")) { - PlayerParticles.getPlugin().getLogger().warning("Couldn't find lang file '" + langFileName + "', defaulting to en_US.lang"); + if (!targetLangFile.exists()) { // Target .lang file didn't exist, default to default.lang + if (!langFileName.equals("default.lang")) { + PlayerParticles.getPlugin().getLogger().warning("Couldn't find lang file '" + langFileName + "', defaulting to default.lang"); } - langFileName = "en_US.lang"; + langFileName = "default.lang"; targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName); - if (!targetLangFile.exists()) { // en_US.lang didn't exist, create it - try (InputStream stream = PlayerParticles.getPlugin().getResource("lang/en_US.lang")) { + if (!targetLangFile.exists()) { // default.lang didn't exist, create it + try (InputStream stream = PlayerParticles.getPlugin().getResource("lang/default.lang")) { targetLangFile.getParentFile().mkdir(); // Make sure the directory always exists Files.copy(stream, Paths.get(targetLangFile.getAbsolutePath())); return YamlConfiguration.loadConfiguration(targetLangFile); } catch (IOException ex) { ex.printStackTrace(); - PlayerParticles.getPlugin().getLogger().severe("Unable to write en_US.lang to disk! All messages for the plugin have been disabled until this is fixed!"); + PlayerParticles.getPlugin().getLogger().severe("Unable to write default.lang to disk! All messages for the plugin have been disabled until this is fixed!"); return null; } } @@ -238,7 +242,7 @@ public class LangManager { * @param messageType The message type to get * @param replacements The replacements fot the message */ - public static String getText(Lang messageType, String... replacements) { + public static String getText(Lang messageType, Object... replacements) { return messageType.get(replacements); } @@ -248,7 +252,7 @@ public class LangManager { * @param player The player to send the message to * @param messageType The message to send to the player */ - public static void sendMessage(Player player, Lang messageType, String... replacements) { + public static void sendMessage(Player player, Lang messageType, Object... replacements) { if (!messagesEnabled) return; String message = messageType.get(replacements); @@ -270,8 +274,8 @@ public class LangManager { * @param pplayer The player to send the message to * @param messageType The message to send to the player */ - public static void sendMessage(PPlayer pplayer, Lang messageType, String... replacements) { - sendMessage(pplayer, messageType, replacements); + public static void sendMessage(PPlayer pplayer, Lang messageType, Object... replacements) { + sendMessage(pplayer.getPlayer(), messageType, replacements); } /** diff --git a/src/com/esophose/playerparticles/manager/ParticleManager.java b/src/com/esophose/playerparticles/manager/ParticleManager.java index 453f87e..b12ada0 100644 --- a/src/com/esophose/playerparticles/manager/ParticleManager.java +++ b/src/com/esophose/playerparticles/manager/ParticleManager.java @@ -131,13 +131,11 @@ public class ParticleManager extends BukkitRunnable implements Listener { // Don't show their particles if they are in spectator mode // Don't spawn particles if the world doesn't allow it if (player != null && player.getGameMode() != GameMode.SPECTATOR && !DataManager.isWorldDisabled(player.getWorld().getName())) { - Location loc = player.getLocation(); - loc.setY(loc.getY() + 1); - - for (ParticlePair particles : pplayer.getActiveParticles()) - displayParticles(particles, loc); + for (ParticlePair particles : pplayer.getActiveParticles()) { + displayParticles(particles, player.getLocation().clone().add(0, 1, 0)); + } } - + // Loop for FixedParticleEffects // Don't spawn particles if the world doesn't allow it for (FixedParticleEffect effect : pplayer.getFixedParticles()) diff --git a/src/com/esophose/playerparticles/particles/PPlayer.java b/src/com/esophose/playerparticles/particles/PPlayer.java index a79bbb0..3800dc5 100644 --- a/src/com/esophose/playerparticles/particles/PPlayer.java +++ b/src/com/esophose/playerparticles/particles/PPlayer.java @@ -96,7 +96,7 @@ public class PPlayer { */ public ParticleGroup getActiveParticleGroup() { for (ParticleGroup group : this.particleGroups) - if (group.getName() == null) + if (group.getName().equals(ParticleGroup.DEFAULT_NAME)) return group; return null; // This should never return null, there will always be at least one ParticleGroup } diff --git a/src/com/esophose/playerparticles/particles/ParticleGroup.java b/src/com/esophose/playerparticles/particles/ParticleGroup.java index 3126e43..a348d35 100644 --- a/src/com/esophose/playerparticles/particles/ParticleGroup.java +++ b/src/com/esophose/playerparticles/particles/ParticleGroup.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.List; public class ParticleGroup { + + public static final String DEFAULT_NAME = "active"; private String name; private List particles; @@ -38,7 +40,7 @@ public class ParticleGroup { * @return The default empty active ParticleGroup */ public static ParticleGroup getDefaultGroup() { - return new ParticleGroup(null, new ArrayList()); + return new ParticleGroup(DEFAULT_NAME, new ArrayList()); } } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleBlockBreak.java b/src/com/esophose/playerparticles/styles/ParticleStyleBlockBreak.java index 0811d49..d931465 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleBlockBreak.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleBlockBreak.java @@ -23,7 +23,7 @@ public class ParticleStyleBlockBreak implements ParticleStyle, Listener { List particles = new ArrayList(); for (int i = 0; i < 15; i++) - particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.05F)); + particles.add(new PParticle(location.add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.05F)); return particles; } @@ -46,7 +46,7 @@ public class ParticleStyleBlockBreak implements ParticleStyle, Listener { PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); if (pplayer != null) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) { - Location loc = event.getBlock().getLocation(); + Location loc = event.getBlock().getLocation().clone(); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc)); } } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleBlockEdit.java b/src/com/esophose/playerparticles/styles/ParticleStyleBlockEdit.java index a74956c..f320a3f 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleBlockEdit.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleBlockEdit.java @@ -54,7 +54,7 @@ public class ParticleStyleBlockEdit implements ParticleStyle, Listener { PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); if (pplayer != null) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) { - Location loc = event.getBlock().getLocation(); + Location loc = event.getBlock().getLocation().clone(); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc)); } } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleBlockPlace.java b/src/com/esophose/playerparticles/styles/ParticleStyleBlockPlace.java index 83a8153..8911c4f 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleBlockPlace.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleBlockPlace.java @@ -23,7 +23,7 @@ public class ParticleStyleBlockPlace implements ParticleStyle, Listener { List particles = new ArrayList(); for (int i = 0; i < 15; i++) - particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.75F, 0.75F, 0.75F, 0.05F)); + particles.add(new PParticle(location.add(0.5, 0.5, 0.5), 0.75F, 0.75F, 0.75F, 0.05F)); return particles; } @@ -46,7 +46,7 @@ public class ParticleStyleBlockPlace implements ParticleStyle, Listener { PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); if (pplayer != null) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKPLACE)) { - Location loc = event.getBlock().getLocation(); + Location loc = event.getBlock().getLocation().clone(); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc)); } } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleCube.java b/src/com/esophose/playerparticles/styles/ParticleStyleCube.java index 27fda78..c0e91c7 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleCube.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleCube.java @@ -70,7 +70,7 @@ public class ParticleStyleCube implements ParticleStyle { VectorUtils.rotateAroundAxisX(v, angleX); VectorUtils.rotateAroundAxisY(v, angleY); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - pparticles.add(new PParticle(location.clone().add(v))); + pparticles.add(new PParticle(location.add(v))); } } for (int p = 0; p <= particles; p++) { @@ -78,7 +78,7 @@ public class ParticleStyleCube implements ParticleStyle { v.setY(edgeLength * p / particles - a); VectorUtils.rotateAroundAxisY(v, angleY); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - pparticles.add(new PParticle(location.clone().add(v))); + pparticles.add(new PParticle(location.add(v))); } } } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleMove.java b/src/com/esophose/playerparticles/styles/ParticleStyleMove.java index ce097cf..8eff6a5 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleMove.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleMove.java @@ -38,7 +38,7 @@ public class ParticleStyleMove implements ParticleStyle, Listener { PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId()); if (pplayer != null) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.MOVE)) { - Location loc = e.getPlayer().getLocation(); + Location loc = e.getPlayer().getLocation().clone(); loc.setY(loc.getY() + 0.05); ParticleManager.displayParticles(particle, DefaultStyles.MOVE.getParticles(particle, loc)); } diff --git a/src/com/esophose/playerparticles/util/ParticleUtils.java b/src/com/esophose/playerparticles/util/ParticleUtils.java index b2c6d29..260bd45 100644 --- a/src/com/esophose/playerparticles/util/ParticleUtils.java +++ b/src/com/esophose/playerparticles/util/ParticleUtils.java @@ -6,6 +6,21 @@ import java.util.List; import org.bukkit.Material; public class ParticleUtils { + + private static List blockMaterials, itemMaterials; + + static { + blockMaterials = new ArrayList(); + itemMaterials = new ArrayList(); + + for (Material mat : Material.values()) { + if (mat.isBlock()) { + blockMaterials.add(mat.name().toLowerCase()); + } else { + itemMaterials.add(mat.name().toLowerCase()); + } + } + } /** * Finds a block/item as a material from a string @@ -45,19 +60,11 @@ public class ParticleUtils { } public static List getAllBlockMaterials() { - List materials = new ArrayList(); - for (Material mat : Material.values()) - if (mat.isBlock()) - materials.add(mat.name().toLowerCase()); - return materials; + return blockMaterials; } public static List getAllItemMaterials() { - List materials = new ArrayList(); - for (Material mat : Material.values()) - if (!mat.isBlock()) - materials.add(mat.name().toLowerCase()); - return materials; + return itemMaterials; } /** diff --git a/src/config.yml b/src/config.yml index 85df2c4..e19daa7 100644 --- a/src/config.yml +++ b/src/config.yml @@ -20,8 +20,8 @@ version: 5.3 check-updates: true # The .lang file to use in the ./lang/ folder -# Default: 'en_US.lang' -lang-file: 'en_US.lang' +# Default: 'default.lang' +lang-file: 'default.lang' # If you're using other plugins to execute commands you may wish to turn off messages # Default: true diff --git a/src/lang/en_US.lang b/src/lang/default.lang similarity index 84% rename from src/lang/en_US.lang rename to src/lang/default.lang index b67ed7d..d950581 100644 --- a/src/lang/en_US.lang +++ b/src/lang/default.lang @@ -1,5 +1,5 @@ # ================================================================ # -# en_US.lang MESSAGE CONFIGURATION # +# default.lang (English) MESSAGE CONFIGURATION # # Important Notes: # # * You can use the & symbol to color the messages # # * {#} Will be replaced with whatever that message requires # @@ -17,7 +17,7 @@ command-description-add: 'Add a particle to your active particles' command-description-data: 'Check what type of data an effect uses' command-description-default: 'The main command. By default, opens the GUI.' command-description-edit: 'Edit the effect, style, or data of an active particle' -command-description-effect: 'This command has been removed, use /pp help to find new commands' +command-description-effect: '&cThis command has been removed, use &b/pp help &cto find new commands' command-description-effects: 'Display a list of effects you can use' command-description-fixed: 'Create, edit, and remove fixed particle effects' command-description-group: 'Save, load, and remove your particle groups' @@ -27,20 +27,23 @@ command-description-info: 'Gets the description of one of your active particles' command-description-list: 'Lists the ids of your active particles' command-description-remove: 'Removes one of your active particles' command-description-reset: 'Removes all your active particles' -command-description-style: 'This command has been removed, use /pp help to find new commands' +command-description-style: '&cThis command has been removed, use &b/pp help &cto find new commands' command-description-styles: 'Display a list of styles you can use' command-description-version: 'Display the current version of the plugin and the author' -command-description-worlds: 'Find out what worlds PlayerParticles is disabled in' +command-description-worlds: 'Find out what worlds particles is disabled in' # Sub-Command Usage -command-description-fixed-create: '/pp fixed create