diff --git a/src/com/esophose/playerparticles/PPlayer.java b/src/com/esophose/playerparticles/PPlayer.java index 80d55b1..184a22d 100644 --- a/src/com/esophose/playerparticles/PPlayer.java +++ b/src/com/esophose/playerparticles/PPlayer.java @@ -1,3 +1,11 @@ +/** + * Copyright Esophose 2016 + * While using any of the code provided by this plugin + * you must not claim it as your own. This plugin may + * be modified and installed on a server, but may not + * be distributed to any person by any means. + */ + package com.esophose.playerparticles; import java.util.UUID; @@ -17,16 +25,36 @@ import com.esophose.playerparticles.styles.api.ParticleStyle; public class PPlayer { + /** + * The UUID of the player + */ private final UUID playerUUID; + /** + * The effect and style the player is using + */ private ParticleEffect particleEffect; private ParticleStyle particleStyle; + /** + * All data used to display custom particles + */ private ItemData particleItemData; private BlockData particleBlockData; private OrdinaryColor particleColorData; private NoteColor particleNoteColorData; + /** + * Constructs a new PPlayer + * + * @param uuid The player UUID + * @param effect The player's effect + * @param style The player's style + * @param itemData The player's item data + * @param blockData The player's block data + * @param colorData The player's color data + * @param noteColorData The player's note color data + */ public PPlayer(UUID uuid, ParticleEffect effect, ParticleStyle style, ItemData itemData, BlockData blockData, OrdinaryColor colorData, NoteColor noteColorData) { this.playerUUID = uuid; this.particleEffect = effect; @@ -37,58 +65,128 @@ public class PPlayer { this.particleNoteColorData = noteColorData; } + /** + * Gets the player's UUID + * + * @return The player's UUID + */ public UUID getUniqueId() { return this.playerUUID; } + /** + * Gets the player's particle effect + * + * @return The player's particle effect + */ public ParticleEffect getParticleEffect() { return this.particleEffect; } + /** + * Gets the player's particle style + * + * @return The player's particle style + */ public ParticleStyle getParticleStyle() { return this.particleStyle; } + /** + * Gets the player's item data + * + * @return The player's item data + */ public ItemData getItemData() { return this.particleItemData; } + /** + * Gets the player's block data + * + * @return The player's block data + */ public BlockData getBlockData() { return this.particleBlockData; } + /** + * Gets the player's color data + * + * @return The player's color data + */ public OrdinaryColor getColorData() { return this.particleColorData; } + /** + * Gets the player's note color data + * + * @return The player's note color data + */ public NoteColor getNoteColorData() { return this.particleNoteColorData; } + /** + * Sets the player's particle effect + * + * @param effect The player's new particle effect + */ public void setParticleEffect(ParticleEffect effect) { this.particleEffect = effect; } + /** + * Sets the player's particle style + * + * @param effect The player's new particle style + */ public void setParticleStyle(ParticleStyle style) { this.particleStyle = style; } + /** + * Sets the player's item data + * + * @param effect The player's new item data + */ public void setItemData(ItemData itemData) { this.particleItemData = itemData; } + /** + * Sets the player's block data + * + * @param effect The player's new block data + */ public void setBlockData(BlockData blockData) { this.particleBlockData = blockData; } + /** + * Sets the player's color data + * + * @param effect The player's new color data + */ public void setColorData(OrdinaryColor colorData) { this.particleColorData = colorData; } + /** + * Sets the player's note color data + * + * @param effect The player's new note color data + */ public void setNoteColorData(NoteColor noteColorData) { this.particleNoteColorData = noteColorData; } + /** + * Gets the data the current particle effect will spawn with + * + * @return The ParticleData the current particle effect requires + */ public ParticleData getParticleSpawnData() { if (particleEffect.hasProperty(ParticleProperty.REQUIRES_DATA)) { if (particleEffect == ParticleEffect.BLOCK_CRACK || particleEffect == ParticleEffect.BLOCK_DUST || particleEffect == ParticleEffect.FALLING_DUST) { @@ -100,6 +198,11 @@ public class PPlayer { return null; } + /** + * Gets the color the current particle effect will spawn with + * + * @return Gets the ParticleColor the current particle effect will spawn with + */ public ParticleColor getParticleSpawnColor() { if (particleEffect.hasProperty(ParticleProperty.COLORABLE)) { if (particleEffect == ParticleEffect.NOTE) { @@ -109,6 +212,13 @@ public class PPlayer { return null; } + /** + * Gets a default PPlayer + * Used for when a new PPlayer is being created + * + * @param playerUUID The player's UUID + * @return A default PPlayer + */ public static PPlayer getNewPPlayer(UUID playerUUID) { ParticleEffect particleEffect = ParticleEffect.NONE; ParticleStyle particleStyle = DefaultStyles.NONE; diff --git a/src/com/esophose/playerparticles/ParticleCommandExecutor.java b/src/com/esophose/playerparticles/ParticleCommandExecutor.java index 7ee99b5..bc204fb 100644 --- a/src/com/esophose/playerparticles/ParticleCommandExecutor.java +++ b/src/com/esophose/playerparticles/ParticleCommandExecutor.java @@ -1,3 +1,11 @@ +/** + * Copyright Esophose 2016 + * While using any of the code provided by this plugin + * you must not claim it as your own. This plugin may + * be modified and installed on a server, but may not + * be distributed to any person by any means. + */ + package com.esophose.playerparticles; import org.bukkit.ChatColor; @@ -15,6 +23,7 @@ import com.esophose.playerparticles.library.ParticleEffect.OrdinaryColor; import com.esophose.playerparticles.library.ParticleEffect.ParticleProperty; import com.esophose.playerparticles.manager.ConfigManager; import com.esophose.playerparticles.manager.MessageManager; +import com.esophose.playerparticles.manager.MessageManager.MessageType; import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.styles.DefaultStyles; import com.esophose.playerparticles.styles.api.ParticleStyle; @@ -37,7 +46,7 @@ public class ParticleCommandExecutor implements CommandExecutor { Player p = (Player) sender; if (args.length == 0) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-arguments", null) + ChatColor.GREEN + " /pp help", ChatColor.RED); + MessageManager.sendMessage(p, MessageType.INVALID_ARGUMENTS); return true; } else { switch (args[0].toLowerCase()) { @@ -69,7 +78,7 @@ public class ParticleCommandExecutor implements CommandExecutor { onReset(p, args); break; default: - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-arguments", null) + ChatColor.GREEN + " /pp help", ChatColor.RED); + MessageManager.sendMessage(p, MessageType.INVALID_ARGUMENTS); } return true; } @@ -82,9 +91,8 @@ public class ParticleCommandExecutor implements CommandExecutor { * @param args The arguments for the command */ private void onHelp(Player p, String[] args) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-available-commands", null), ChatColor.GREEN); - MessageManager.getInstance().sendMessage(p, "effect, effects, style, styles, data, reset, worlds, version, help", ChatColor.AQUA); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp ", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.AVAILABLE_COMMANDS); + MessageManager.sendMessage(p, MessageType.COMMAND_USAGE); } /** @@ -94,20 +102,18 @@ public class ParticleCommandExecutor implements CommandExecutor { * @param args The arguments for the command */ private void onWorlds(Player p, String[] args) { - String worlds = ""; - if (ConfigManager.getInstance().getDisabledWorlds() == null) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-disabled-worlds-none", null), ChatColor.GREEN); + if (ConfigManager.getInstance().getDisabledWorlds() == null || ConfigManager.getInstance().getDisabledWorlds().isEmpty()) { + MessageManager.sendMessage(p, MessageType.DISABLED_WORLDS_NONE); + return; } + + String worlds = ""; for (String s : ConfigManager.getInstance().getDisabledWorlds()) { worlds += s + ", "; } if (worlds.length() > 2) worlds = worlds.substring(0, worlds.length() - 2); - if (worlds.equals("")) { - worlds = MessageManager.getMessageFromConfig("message-disabled-worlds-none", null); - } else { - worlds = MessageManager.getMessageFromConfig("message-disabled-worlds", null) + " " + ChatColor.AQUA + worlds; - } - MessageManager.getInstance().sendMessage(p, worlds, ChatColor.GREEN); + + MessageManager.sendCustomMessage(p, MessageType.DISABLED_WORLDS.getMessage() + " " + worlds); } /** @@ -117,8 +123,8 @@ public class ParticleCommandExecutor implements CommandExecutor { * @param args The arguments for the command */ private void onVersion(Player p, String[] args) { - MessageManager.getInstance().sendMessage(p, "Running PlayerParticles v" + PlayerParticles.getPlugin().getDescription().getVersion(), ChatColor.GOLD); - MessageManager.getInstance().sendMessage(p, "Plugin created by: Esophose", ChatColor.GOLD); + MessageManager.sendCustomMessage(p, ChatColor.GOLD + "Running PlayerParticles v" + PlayerParticles.getPlugin().getDescription().getVersion()); + MessageManager.sendCustomMessage(p, ChatColor.GOLD + "Plugin created by: Esophose"); } /** @@ -132,22 +138,22 @@ public class ParticleCommandExecutor implements CommandExecutor { if ((!effect.hasProperty(ParticleProperty.REQUIRES_DATA) && !effect.hasProperty(ParticleProperty.COLORABLE)) || args.length == 1) { if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect == ParticleEffect.NOTE) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-note-data-usage", null), ChatColor.YELLOW); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-23>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_USAGE, "note"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.NOTE_DATA_USAGE.getMessage()); } else { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-color-data-usage", null), ChatColor.YELLOW); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-255> <0-255> <0-255>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_USAGE, "color"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.COLOR_DATA_USAGE.getMessage()); } } else if (effect.hasProperty(ParticleProperty.REQUIRES_DATA)) { if (effect == ParticleEffect.ITEM_CRACK) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-usage", null), ChatColor.YELLOW); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_USAGE, "item"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.ITEM_DATA_USAGE.getMessage()); } else { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-usage", null), ChatColor.YELLOW); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_USAGE, "block"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.BLOCK_DATA_USAGE.getMessage()); } } else { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-data-usage", null), ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.NO_DATA_USAGE); } return; } @@ -158,22 +164,22 @@ public class ParticleCommandExecutor implements CommandExecutor { try { note = Integer.parseInt(args[1]); } catch (Exception e) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-note-data-invalid-arguments", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-23>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "note"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.NOTE_DATA_USAGE.getMessage()); return; } if (note < 0 || note > 23) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-note-data-invalid-arguments", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-23>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "note"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.NOTE_DATA_USAGE.getMessage()); return; } ConfigManager.getInstance().savePPlayer(p.getUniqueId(), new NoteColor(note)); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-note-data-applied", null), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "note"); } else { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-note-data-invalid-arguments", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-23>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "note"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.NOTE_DATA_USAGE.getMessage()); } } else { if (args.length >= 4) { @@ -186,22 +192,22 @@ public class ParticleCommandExecutor implements CommandExecutor { g = Integer.parseInt(args[2]); b = Integer.parseInt(args[3]); } catch (Exception e) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-color-data-invalid-arguments", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-255> <0-255> <0-255>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "color"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.COLOR_DATA_USAGE.getMessage()); return; } if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-color-data-invalid-arguments", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-255> <0-255> <0-255>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "color"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.COLOR_DATA_USAGE.getMessage()); return; } ConfigManager.getInstance().savePPlayer(p.getUniqueId(), new OrdinaryColor(r, g, b)); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-color-data-applied", null), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "color"); } else { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-color-data-invalid-arguments", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-255> <0-255> <0-255>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "color"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.COLOR_DATA_USAGE.getMessage()); } } } else if (effect.hasProperty(ParticleProperty.REQUIRES_DATA)) { @@ -214,33 +220,33 @@ public class ParticleCommandExecutor implements CommandExecutor { if (material == null) material = Material.matchMaterial(args[1]); if (material == null) throw new Exception(); } catch (Exception e) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-unknown", args[1]), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_MATERIAL_UNKNOWN, "item"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.ITEM_DATA_USAGE.getMessage()); return; } try { data = Integer.parseInt(args[2]); } catch (Exception e) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-usage", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "item"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.ITEM_DATA_USAGE.getMessage()); return; } if (material.isBlock()) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-mismatch", material.name()), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_MATERIAL_MISMATCH, "item"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.ITEM_DATA_USAGE.getMessage()); return; } if (data < 0 || data > 15) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-invalid-arguments", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "item"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.ITEM_DATA_USAGE.getMessage()); return; } ConfigManager.getInstance().savePPlayer(p.getUniqueId(), new ItemData(material, (byte) data)); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-item-data-applied", null), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "item"); } else { Material material = null; int data = -1; @@ -250,33 +256,33 @@ public class ParticleCommandExecutor implements CommandExecutor { if (material == null) material = Material.matchMaterial(args[1]); if (material == null) throw new Exception(); } catch (Exception e) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-unknown", args[1]), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_MATERIAL_UNKNOWN, "block"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.BLOCK_DATA_USAGE.getMessage()); return; } try { data = Integer.parseInt(args[2]); } catch (Exception e) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-usage", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "block"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.BLOCK_DATA_USAGE.getMessage()); return; } if (!material.isBlock()) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-mismatch", material.name()), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_MATERIAL_MISMATCH, "block"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.BLOCK_DATA_USAGE.getMessage()); return; } if (data < 0 || data > 15) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-invalid-arguments", null), ChatColor.RED); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp data <0-15>", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "block"); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.BLOCK_DATA_USAGE.getMessage()); return; } ConfigManager.getInstance().savePPlayer(p.getUniqueId(), new BlockData(material, (byte) data)); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-block-data-applied", null), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "block"); } } } @@ -289,7 +295,7 @@ public class ParticleCommandExecutor implements CommandExecutor { */ private void onReset(Player p, String[] args) { ConfigManager.getInstance().resetPPlayer(p.getUniqueId()); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-reset", null), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.RESET); } /** @@ -300,25 +306,25 @@ public class ParticleCommandExecutor implements CommandExecutor { */ private void onEffect(Player p, String[] args) { if (args.length == 1) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-type", null) + ChatColor.GREEN + " /pp effects | /pp effect ", ChatColor.RED); + MessageManager.sendMessage(p, MessageType.INVALID_TYPE); return; } String argument = args[1].replace("_", ""); if (ParticleCreator.particleFromString(argument) != null) { ParticleEffect effect = ParticleCreator.particleFromString(argument); if (!PermissionManager.hasEffectPermission(p, effect)) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-permission", ChatColor.AQUA + effect.getName().toLowerCase() + ChatColor.RED), ChatColor.RED); + MessageManager.sendMessage(p, MessageType.NO_PERMISSION, effect.getName().toLowerCase()); return; } ConfigManager.getInstance().savePPlayer(p.getUniqueId(), effect); if (effect != ParticleEffect.NONE) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-now-using", ChatColor.AQUA + effect.getName().toLowerCase() + ChatColor.GREEN), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.NOW_USING, effect.getName().toLowerCase()); } else { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-cleared-particles", null), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.CLEARED_PARTICLES); } return; } - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-type", null) + ChatColor.GREEN + " /pp effects", ChatColor.RED); + MessageManager.sendMessage(p, MessageType.INVALID_TYPE); } /** @@ -328,20 +334,22 @@ public class ParticleCommandExecutor implements CommandExecutor { * @param args The arguments for the command */ private void onEffects(Player p, String[] args) { - String toSend = MessageManager.getMessageFromConfig("message-use", null) + " "; + String toSend = MessageType.USE.getMessage() + " "; for (ParticleEffect effect : ParticleEffect.getSupportedEffects()) { if (PermissionManager.hasEffectPermission(p, effect)) { toSend += effect.getName().toLowerCase().replace("_", "") + ", "; continue; } } - if (toSend.equals(MessageManager.getMessageFromConfig("message-use", null) + " ")) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-particles", null), ChatColor.RED); + if (toSend.endsWith(", ")) { + toSend = toSend.substring(0, toSend.length() - 2); + } + if (toSend.equals(MessageType.USE.getMessage() + " " + ParticleEffect.NONE.getName())) { + MessageManager.sendMessage(p, MessageType.NO_PARTICLES); return; } - toSend = toSend + "clear"; - MessageManager.getInstance().sendMessage(p, toSend, ChatColor.GREEN); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp effect ", ChatColor.YELLOW); + MessageManager.sendCustomMessage(p, toSend); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.PARTICLE_USAGE.getMessage()); } /** @@ -352,25 +360,25 @@ public class ParticleCommandExecutor implements CommandExecutor { */ private void onStyle(Player p, String[] args) { if (args.length == 1) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp style ", ChatColor.YELLOW); + MessageManager.sendMessage(p, MessageType.INVALID_TYPE_STYLE); return; } String argument = args[1].replace("_", ""); if (ParticleStyleManager.styleFromString(argument) != null) { ParticleStyle style = ParticleStyleManager.styleFromString(argument); if (!PermissionManager.hasStylePermission(p, style)) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-permission-style", ChatColor.AQUA + style.getName().toLowerCase() + ChatColor.RED), ChatColor.RED); + MessageManager.sendMessage(p, MessageType.NO_PERMISSION_STYLE, style.getName().toLowerCase()); return; } ConfigManager.getInstance().savePPlayer(p.getUniqueId(), style); if (style != DefaultStyles.NONE) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-now-using-style", ChatColor.AQUA + style.getName().toLowerCase() + ChatColor.GREEN), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.NOW_USING_STYLE, style.getName().toLowerCase()); } else { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-cleared-style", null), ChatColor.GREEN); + MessageManager.sendMessage(p, MessageType.CLEARED_STYLE); } return; } - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-invalid-type-style", null) + ChatColor.GREEN + " /pp styles", ChatColor.RED); + MessageManager.sendMessage(p, MessageType.INVALID_TYPE_STYLE); } /** @@ -380,7 +388,7 @@ public class ParticleCommandExecutor implements CommandExecutor { * @param args The arguments for the command */ private void onStyles(Player p, String[] args) { - String toSend = MessageManager.getMessageFromConfig("message-use-style", null) + " "; + String toSend = MessageType.USE.getMessage() + " "; for (ParticleStyle style : ParticleStyleManager.getStyles()) { if (PermissionManager.hasStylePermission(p, style)) { toSend += style.getName().toLowerCase(); @@ -390,12 +398,12 @@ public class ParticleCommandExecutor implements CommandExecutor { if (toSend.endsWith(", ")) { toSend = toSend.substring(0, toSend.length() - 2); } - if (toSend.equals(MessageManager.getMessageFromConfig("message-use-style", null) + " " + DefaultStyles.NONE.getName().toLowerCase())) { - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-no-styles", null), ChatColor.RED); + if (toSend.equals(MessageType.USE.getMessage() + " " + DefaultStyles.NONE.getName().toLowerCase())) { + MessageManager.sendMessage(p, MessageType.NO_STYLES); return; } - MessageManager.getInstance().sendMessage(p, toSend, ChatColor.GREEN); - MessageManager.getInstance().sendMessage(p, MessageManager.getMessageFromConfig("message-usage", null) + ChatColor.AQUA + " /pp style ", ChatColor.YELLOW); + MessageManager.sendCustomMessage(p, toSend); + MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.STYLE_USAGE.getMessage()); } } diff --git a/src/com/esophose/playerparticles/ParticleCreator.java b/src/com/esophose/playerparticles/ParticleCreator.java index 8b1ac98..9219aca 100644 --- a/src/com/esophose/playerparticles/ParticleCreator.java +++ b/src/com/esophose/playerparticles/ParticleCreator.java @@ -11,6 +11,7 @@ package com.esophose.playerparticles; import java.util.ArrayList; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -63,7 +64,7 @@ public class ParticleCreator extends BukkitRunnable implements Listener { ConfigManager.getInstance().getPPlayer(player.getUniqueId()); } } - + public static void updateIfContains(PPlayer pplayer) { for (PPlayer pp : particlePlayers) { if (pp.getUniqueId() == pplayer.getUniqueId()) { @@ -89,15 +90,14 @@ public class ParticleCreator extends BukkitRunnable implements Listener { /** * The main loop to display all the particles - * Updates all the timing variables - * Refreshes the database connection if it is enabled and it has been 30 seconds since last refresh - * Displays the particles for all players on the server + * Does not display particles if the world is disabled or if the player is in spectator mode */ public void run() { ParticleStyleManager.updateTimers(); for (Player player : Bukkit.getOnlinePlayers()) { if (ConfigManager.getInstance().isWorldDisabled(player.getWorld().getName())) continue; + if (player.getGameMode() == GameMode.SPECTATOR) continue; PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId()); if (PermissionManager.hasEffectPermission(player, pplayer.getParticleEffect())) { Location loc = player.getLocation(); diff --git a/src/com/esophose/playerparticles/ParticlesUtil.java b/src/com/esophose/playerparticles/ParticlesUtil.java index d36dcc5..391a357 100644 --- a/src/com/esophose/playerparticles/ParticlesUtil.java +++ b/src/com/esophose/playerparticles/ParticlesUtil.java @@ -1,3 +1,11 @@ +/** + * Copyright Esophose 2016 + * While using any of the code provided by this plugin + * you must not claim it as your own. This plugin may + * be modified and installed on a server, but may not + * be distributed to any person by any means. + */ + package com.esophose.playerparticles; import java.util.ArrayList; @@ -6,7 +14,13 @@ import org.bukkit.Material; public class ParticlesUtil { - // TODO: Find a more reliable way of doing this that works better + /** + * Finds a block/item as a material from a string + * There must be some better way to do this that reliably gets the correct material + * + * @param input The material name as a string + * @return The material from the string + */ @SuppressWarnings("deprecation") public static Material closestMatch(String input) { ArrayList matchList = new ArrayList(); diff --git a/src/com/esophose/playerparticles/PlayerParticles.java b/src/com/esophose/playerparticles/PlayerParticles.java index 9ab86b0..a5297b3 100644 --- a/src/com/esophose/playerparticles/PlayerParticles.java +++ b/src/com/esophose/playerparticles/PlayerParticles.java @@ -7,6 +7,8 @@ * * TODO: Make sure copyright notice is on all files * TODO: Make sure all the comments are properly formatted still + * TODO: Add option to config to show particles in spectator mode or not - Disabled by default + * TODO: Add message configuration for data usage */ package com.esophose.playerparticles; @@ -20,6 +22,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import com.esophose.playerparticles.library.MySQL; +import com.esophose.playerparticles.manager.MessageManager; import com.esophose.playerparticles.styles.DefaultStyles; import com.esophose.playerparticles.updater.PluginUpdateListener; import com.esophose.playerparticles.updater.Updater; @@ -55,6 +58,7 @@ public class PlayerParticles extends JavaPlugin { */ public void onEnable() { DefaultStyles.registerStyles(); + MessageManager.setup(); saveDefaultConfig(); getCommand("pp").setTabCompleter(new ParticleCommandCompleter()); getCommand("pp").setExecutor(new ParticleCommandExecutor()); diff --git a/src/com/esophose/playerparticles/library/Database.java b/src/com/esophose/playerparticles/library/Database.java index a11281a..93190f9 100644 --- a/src/com/esophose/playerparticles/library/Database.java +++ b/src/com/esophose/playerparticles/library/Database.java @@ -116,11 +116,9 @@ public abstract class Database { String[] queries = query.split(";"); for (String q : queries) { statement.addBatch(q); - System.out.println("Running query: " + q); } results = statement.executeBatch(); } else { - System.out.println("Running query: " + query); results = new int[] { statement.executeUpdate(query) }; } diff --git a/src/com/esophose/playerparticles/library/ParticleEffect.java b/src/com/esophose/playerparticles/library/ParticleEffect.java index 54c5cf8..655666d 100644 --- a/src/com/esophose/playerparticles/library/ParticleEffect.java +++ b/src/com/esophose/playerparticles/library/ParticleEffect.java @@ -47,14 +47,10 @@ import com.esophose.playerparticles.library.ReflectionUtils.PackageType; /** * Modified a couple things for the plugin -<<<<<<< HEAD + * * Updated to 1.10 * * @author (of changes) Esophose -======= - * - * @author Esophose ->>>>>>> refs/remotes/origin/master */ public enum ParticleEffect { @@ -106,7 +102,9 @@ public enum ParticleEffect { END_ROD("endrod", 43, 9), DAMAGE_INDICATOR("damageindicator", 44, 9), SWEEP_ATTACK("sweepattack", 45, 9), - FALLING_DUST("fallingdust", 46, 10, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA); + FALLING_DUST("fallingdust", 46, 10, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA), + TOTEM("totem", 47, 11, ParticleProperty.DIRECTIONAL), + SPIT("spit", 48, 11, ParticleProperty.DIRECTIONAL); private static final Map NAME_MAP = new HashMap(); private static final Map ID_MAP = new HashMap(); diff --git a/src/com/esophose/playerparticles/library/VectorUtils.java b/src/com/esophose/playerparticles/library/VectorUtils.java new file mode 100644 index 0000000..38d153a --- /dev/null +++ b/src/com/esophose/playerparticles/library/VectorUtils.java @@ -0,0 +1,157 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2014 Slikey + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.esophose.playerparticles.library; + +import org.bukkit.Location; +import org.bukkit.util.Vector; + +public final class VectorUtils { + + /** + * Not instantiable + */ + private VectorUtils() { } + + /** + * Rotates a vector around the X axis at an angle + * + * @param v Starting vector + * @param angle How much to rotate + * @return The starting vector rotated + */ + public static final Vector rotateAroundAxisX(Vector v, double angle) { + double y, z, cos, sin; + cos = Math.cos(angle); + sin = Math.sin(angle); + y = v.getY() * cos - v.getZ() * sin; + z = v.getY() * sin + v.getZ() * cos; + return v.setY(y).setZ(z); + } + + /** + * Rotates a vector around the Y axis at an angle + * + * @param v Starting vector + * @param angle How much to rotate + * @return The starting vector rotated + */ + public static final Vector rotateAroundAxisY(Vector v, double angle) { + double x, z, cos, sin; + cos = Math.cos(angle); + sin = Math.sin(angle); + x = v.getX() * cos + v.getZ() * sin; + z = v.getX() * -sin + v.getZ() * cos; + return v.setX(x).setZ(z); + } + + /** + * Rotates a vector around the Z axis at an angle + * + * @param v Starting vector + * @param angle How much to rotate + * @return The starting vector rotated + */ + public static final Vector rotateAroundAxisZ(Vector v, double angle) { + double x, y, cos, sin; + cos = Math.cos(angle); + sin = Math.sin(angle); + x = v.getX() * cos - v.getY() * sin; + y = v.getX() * sin + v.getY() * cos; + return v.setX(x).setY(y); + } + + /** + * Rotates a vector around the X, Y, and Z axes + * + * @param v The starting vector + * @param angleX The change angle on X + * @param angleY The change angle on Y + * @param angleZ The change angle on Z + * @return The starting vector rotated + */ + public static final Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) { + rotateAroundAxisX(v, angleX); + rotateAroundAxisY(v, angleY); + rotateAroundAxisZ(v, angleZ); + return v; + } + + /** + * Rotate a vector about a location using that location's direction + * + * @param v The starting vector + * @param location The location to rotate around + * @return The starting vector rotated + */ + public static final Vector rotateVector(Vector v, Location location) { + return rotateVector(v, location.getYaw(), location.getPitch()); + } + + /** + * This handles non-unit vectors, with yaw and pitch instead of X,Y,Z angles. + * + * Thanks to SexyToad! + * + * @param v The starting vector + * @param yawDegrees The yaw offset in degrees + * @param pitchDegrees The pitch offset in degrees + * @return The starting vector rotated + */ + public static final Vector rotateVector(Vector v, float yawDegrees, float pitchDegrees) { + double yaw = Math.toRadians(-1 * (yawDegrees + 90)); + double pitch = Math.toRadians(-pitchDegrees); + + double cosYaw = Math.cos(yaw); + double cosPitch = Math.cos(pitch); + double sinYaw = Math.sin(yaw); + double sinPitch = Math.sin(pitch); + + double initialX, initialY, initialZ; + double x, y, z; + + // Z_Axis rotation (Pitch) + initialX = v.getX(); + initialY = v.getY(); + x = initialX * cosPitch - initialY * sinPitch; + y = initialX * sinPitch + initialY * cosPitch; + + // Y_Axis rotation (Yaw) + initialZ = v.getZ(); + initialX = x; + z = initialZ * cosYaw - initialX * sinYaw; + x = initialZ * sinYaw + initialX * cosYaw; + + return new Vector(x, y, z); + } + + /** + * Gets the angle toward the X axis + * + * @param vector + * @return + */ + public static final double angleToXAxis(Vector vector) { + return Math.atan2(vector.getX(), vector.getY()); + } +} diff --git a/src/com/esophose/playerparticles/manager/ConfigManager.java b/src/com/esophose/playerparticles/manager/ConfigManager.java index b2ba3f1..a7a3e34 100644 --- a/src/com/esophose/playerparticles/manager/ConfigManager.java +++ b/src/com/esophose/playerparticles/manager/ConfigManager.java @@ -12,7 +12,7 @@ import java.io.File; import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; +import java.util.List; import java.util.UUID; import org.bukkit.Color; @@ -399,10 +399,9 @@ public class ConfigManager { * * @return All world names that are disabled */ - @SuppressWarnings("unchecked") - public ArrayList getDisabledWorlds() { + public List getDisabledWorlds() { if (PlayerParticles.getPlugin().getConfig().get("disabled-worlds") != null) { - return ((ArrayList) PlayerParticles.getPlugin().getConfig().get("disabled-worlds")); + return PlayerParticles.getPlugin().getConfig().getStringList("disabled-worlds"); } else return null; } diff --git a/src/com/esophose/playerparticles/manager/MessageManager.java b/src/com/esophose/playerparticles/manager/MessageManager.java index 3fbb36f..cb49ae4 100644 --- a/src/com/esophose/playerparticles/manager/MessageManager.java +++ b/src/com/esophose/playerparticles/manager/MessageManager.java @@ -9,6 +9,7 @@ package com.esophose.playerparticles.manager; import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import com.esophose.playerparticles.PlayerParticles; @@ -16,80 +17,148 @@ import com.esophose.playerparticles.PlayerParticles; public class MessageManager { /** - * The instance of the MessageManager, we only need one of these + * Contains the location in the config of every chat message */ - private static MessageManager instance = new MessageManager(); + public static enum MessageType { + + // Particles + NO_PERMISSION("message-no-permission"), + NO_PARTICLES("message-no-particles"), + NOW_USING("message-now-using"), + CLEARED_PARTICLES("message-cleared-particles"), + INVALID_TYPE("message-invalid-type"), + PARTICLE_USAGE("message-particle-usage"), + + // Styles + NO_PERMISSION_STYLE("message-no-permission-style"), + NO_STYLES("message-no-styles"), + NOW_USING_STYLE("message-now-using-style"), + CLEARED_STYLE("message-cleared-style"), + USE_STYLE("message-use-style"), + INVALID_TYPE_STYLE("message-invalid-type-style"), + STYLE_USAGE("message-style-usage"), + + // Data + DATA_USAGE("message-data-usage"), + NO_DATA_USAGE("message-no-data-usage"), + DATA_APPLIED("message-data-applied"), + DATA_INVALID_ARGUMENTS("message-data-invalid-arguments"), + DATA_MATERIAL_UNKNOWN("message-data-material-unknown"), + DATA_MATERIAL_MISMATCH("message-data-material-mismatch"), + NOTE_DATA_USAGE("message-note-data-usage"), + COLOR_DATA_USAGE("message-color-data-usage"), + ITEM_DATA_USAGE("message-item-data-usage"), + BLOCK_DATA_USAGE("message-block-data-usage"), + + // Prefixes + USE("message-use"), + USAGE("message-usage"), + RESET("message-reset"), + + // Other + INVALID_ARGUMENTS("message-invalid-arguments"), + AVAILABLE_COMMANDS("message-available-commands"), + DISABLED_WORLDS_NONE("message-disabled-worlds-none"), + DISABLED_WORLDS("message-disabled-worlds"), + COMMAND_USAGE("message-command-usage"); + + public String configLocation; + + MessageType(String configLocation) { + this.configLocation = configLocation; + } + + /** + * Gets the message with the given config path + * + * @return The message from the config + */ + public String getMessage() { + return ChatColor.translateAlternateColorCodes('&', config.getString(this.configLocation)); + } + } + /** - * Values contained in the config used for custom messages + * Stores the main config for quick access */ - private boolean messagesEnabled, prefixEnabled; + private static FileConfiguration config; + /** + * Stores if messages and their prefixes should be displayed + */ + private static boolean messagesEnabled, prefixEnabled; /** * The prefix to place before all sent messages contained in the config */ - private String messagePrefix; + private static String messagePrefix; /** - * Sets up all the above variables with values from the plugin config + * Used to set up the MessageManager + * This should only get called once by the PlayerParticles class, however + * calling it multiple times wont affect anything negatively */ - private MessageManager() { - this.messagesEnabled = PlayerParticles.getPlugin().getConfig().getBoolean("messages-enabled"); - this.prefixEnabled = PlayerParticles.getPlugin().getConfig().getBoolean("use-message-prefix"); - this.messagePrefix = PlayerParticles.getPlugin().getConfig().getString("message-prefix"); - this.messagePrefix = ChatColor.translateAlternateColorCodes('&', this.messagePrefix); + public static void setup() { + config = PlayerParticles.getPlugin().getConfig(); + messagesEnabled = config.getBoolean("messages-enabled"); + prefixEnabled = config.getBoolean("use-message-prefix"); + messagePrefix = parseColors(config.getString("message-prefix")); } /** - * Gets the instance of the MessageManager + * Sends a message to the given player * - * @return The instance of the MessageManager + * @param player The player to send the message to + * @param messageType The message to send to the player */ - public static MessageManager getInstance() { - return instance; + public static void sendMessage(Player player, MessageType messageType) { + if (!messagesEnabled) return; + + String message = messageType.getMessage(); + if (prefixEnabled) { + message = messagePrefix + " " + message; + } + player.sendMessage(message); } - + /** - * Sends a message to a player + * Sends a message to the given player and allows for replacing {TYPE} + * @param player The player to send the message to + * @param messageType The message to send to the player + * @param typeReplacement What {TYPE} should be replaced with + */ + public static void sendMessage(Player player, MessageType messageType, String typeReplacement) { + if (!messagesEnabled) return; + + String message = messageType.getMessage().replaceAll("\\{TYPE\\}", typeReplacement); + if (prefixEnabled) { + message = messagePrefix + " " + message; + } + player.sendMessage(message); + } + + /** + * Sends a custom message + * Used in cases of string building * * @param player The player to send the message to * @param message The message to send to the player - * @param color The chat color to put before the message */ - public void sendMessage(Player player, String message, ChatColor color) { - if (!this.messagesEnabled) return; - if (this.prefixEnabled) { - message = this.messagePrefix + color + " " + message; - } else { - message = color + message; + public static void sendCustomMessage(Player player, String message) { + if (!messagesEnabled) return; + + if (prefixEnabled) { + message = messagePrefix + " " + message; } player.sendMessage(message); } /** - * Sends a player a message without any custom coloring - * This will become the default in v4.1 + * Translates all & symbols into the Minecraft chat color symbol * - * @param player The player to send the message to - * @param message The message to send to the player + * @param message The input + * @return The output, parsed */ - public void sendMessage(Player player, String message) { - if (!this.messagesEnabled) return; - if (this.prefixEnabled) { - message = this.messagePrefix + message; - } - player.sendMessage(message); - } - - /** - * Gets a message from the config with the formatting specified - * - * @param target The string to find in the config - * @param replacement The replacement for {TYPE}, can be null - * @return The message requested with the applied formatting - */ - public static String getMessageFromConfig(String target, String replacement) { - String message = ChatColor.translateAlternateColorCodes('&', PlayerParticles.getPlugin().getConfig().getString(target)); - if (replacement != null) message = message.replaceAll("\\{TYPE\\}", replacement); - return message; + public static String parseColors(String message) { + return ChatColor.translateAlternateColorCodes('&', message); } } diff --git a/src/com/esophose/playerparticles/manager/PermissionManager.java b/src/com/esophose/playerparticles/manager/PermissionManager.java index dc3030e..49d87da 100644 --- a/src/com/esophose/playerparticles/manager/PermissionManager.java +++ b/src/com/esophose/playerparticles/manager/PermissionManager.java @@ -22,6 +22,7 @@ public class PermissionManager { /** * Checks if a player has permission to use an effect + * Always returns true for 'none' * * @param player The player to check the permission for * @param effect The effect to check diff --git a/src/com/esophose/playerparticles/styles/DefaultStyles.java b/src/com/esophose/playerparticles/styles/DefaultStyles.java index 28212bc..04b5aa9 100644 --- a/src/com/esophose/playerparticles/styles/DefaultStyles.java +++ b/src/com/esophose/playerparticles/styles/DefaultStyles.java @@ -9,6 +9,9 @@ import com.esophose.playerparticles.styles.api.ParticleStyleManager; public class DefaultStyles { + /** + * All the styles that are available by default from this plugin + */ public static ParticleStyle NONE = new ParticleStyleNone(); public static ParticleStyle SPIRAL = new ParticleStyleSpiral(); public static ParticleStyle HALO = new ParticleStyleHalo(); @@ -18,7 +21,11 @@ public class DefaultStyles { public static ParticleStyle QUADHELIX = new ParticleStyleQuadhelix(); public static ParticleStyle ORBIT = new ParticleStyleOrbit(); public static ParticleStyle FEET = new ParticleStyleFeet(); + public static ParticleStyle CUBE = new ParticleStyleCube(); + /** + * Registers all the default styles to the ParticleStyleManager + */ public static void registerStyles() { ParticleStyleManager.registerStyle(NONE); ParticleStyleManager.registerStyle(SPIRAL); @@ -29,8 +36,9 @@ public class DefaultStyles { ParticleStyleManager.registerStyle(QUADHELIX); ParticleStyleManager.registerStyle(ORBIT); ParticleStyleManager.registerStyle(FEET); + ParticleStyleManager.registerStyle(CUBE); - Bukkit.getServer().getPluginManager().registerEvents((Listener) MOVE, PlayerParticles.getPlugin()); + Bukkit.getPluginManager().registerEvents((Listener) MOVE, PlayerParticles.getPlugin()); } } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleCube.java b/src/com/esophose/playerparticles/styles/ParticleStyleCube.java new file mode 100644 index 0000000..86f3ed1 --- /dev/null +++ b/src/com/esophose/playerparticles/styles/ParticleStyleCube.java @@ -0,0 +1,93 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2014 Slikey + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.esophose.playerparticles.styles; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.util.Vector; + +import com.esophose.playerparticles.PPlayer; +import com.esophose.playerparticles.library.VectorUtils; +import com.esophose.playerparticles.styles.api.PParticle; +import com.esophose.playerparticles.styles.api.ParticleStyle; + +/** + * Credit goes to Slikey who made all this logic for drawing a cube out of particles + * The project this is from is called EffectLib and can be found here: + * https://github.com/Slikey/EffectLib + */ +public class ParticleStyleCube implements ParticleStyle { + + private float edgeLength = 2; + private double angularVelocityX = (Math.PI / 200) / 5; + private double angularVelocityY = (Math.PI / 170) / 5; + private double angularVelocityZ = (Math.PI / 155) / 5; + private int particles = 8; + private int step = 0; + + public PParticle[] getParticles(PPlayer pplayer, Location location) { + List pparticles = new ArrayList(); + + double xRotation = 0, yRotation = 0, zRotation = 0; + xRotation = step * angularVelocityX; + yRotation = step * angularVelocityY; + zRotation = step * angularVelocityZ; + float a = edgeLength / 2; + double angleX, angleY; + Vector v = new Vector(); + for (int i = 0; i < 4; i++) { + angleY = i * Math.PI / 2; + for (int j = 0; j < 2; j++) { + angleX = j * Math.PI; + for (int p = 0; p <= particles; p++) { + v.setX(a).setY(a); + v.setZ(edgeLength * p / particles - a); + VectorUtils.rotateAroundAxisX(v, angleX); + VectorUtils.rotateAroundAxisY(v, angleY); + VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + pparticles.add(new PParticle(location.clone().add(v))); + } + } + for (int p = 0; p <= particles; p++) { + v.setX(a).setZ(a); + v.setY(edgeLength * p / particles - a); + VectorUtils.rotateAroundAxisY(v, angleY); + VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + pparticles.add(new PParticle(location.clone().add(v))); + } + } + return pparticles.toArray(new PParticle[pparticles.size()]); + } + + public void updateTimers() { + step++; + } + + public String getName() { + return "cube"; + } + +} diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleNone.java b/src/com/esophose/playerparticles/styles/ParticleStyleNone.java index fd195ae..d98accf 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleNone.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleNone.java @@ -109,6 +109,10 @@ public class ParticleStyleNone implements ParticleStyle { for (int i = 0; i < 2; i++) particles[i] = new PParticle(location.add(0, 0.75, 0), 0.6F, 0.4F, 0.6F, 0.0F); return particles; + } else if (particleEffect.equals(ParticleEffect.TOTEM)) { + return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) }; + } else if (particleEffect.equals(ParticleEffect.SPIT)) { + return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) }; } else { return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; } diff --git a/src/com/esophose/playerparticles/styles/api/PParticle.java b/src/com/esophose/playerparticles/styles/api/PParticle.java index cd502f6..04f66b1 100644 --- a/src/com/esophose/playerparticles/styles/api/PParticle.java +++ b/src/com/esophose/playerparticles/styles/api/PParticle.java @@ -1,9 +1,20 @@ +/** + * Copyright Esophose 2016 + * While using any of the code provided by this plugin + * you must not claim it as your own. This plugin may + * be modified and installed on a server, but may not + * be distributed to any person by any means. + */ + package com.esophose.playerparticles.styles.api; import org.bukkit.Location; public class PParticle { + /** + * Data that affects the particle + */ private Location location; private float speed; private float xOff, yOff, zOff; diff --git a/src/com/esophose/playerparticles/styles/api/ParticleStyle.java b/src/com/esophose/playerparticles/styles/api/ParticleStyle.java index 4cb74f3..834240c 100644 --- a/src/com/esophose/playerparticles/styles/api/ParticleStyle.java +++ b/src/com/esophose/playerparticles/styles/api/ParticleStyle.java @@ -14,6 +14,13 @@ import com.esophose.playerparticles.PPlayer; public interface ParticleStyle { + /** + * Gets all the particles to display based on the style's logic + * + * @param pplayer The PPlayer to display the particles for + * @param location The central location of the particles + * @return A list of all PParticles' to spawn + */ public PParticle[] getParticles(PPlayer pplayer, Location location); public void updateTimers(); diff --git a/src/com/esophose/playerparticles/styles/api/ParticleStyleManager.java b/src/com/esophose/playerparticles/styles/api/ParticleStyleManager.java index 980999d..93fbb53 100644 --- a/src/com/esophose/playerparticles/styles/api/ParticleStyleManager.java +++ b/src/com/esophose/playerparticles/styles/api/ParticleStyleManager.java @@ -1,12 +1,28 @@ +/** + * Copyright Esophose 2016 + * While using any of the code provided by this plugin + * you must not claim it as your own. This plugin may + * be modified and installed on a server, but may not + * be distributed to any person by any means. + */ + package com.esophose.playerparticles.styles.api; import java.util.ArrayList; public class ParticleStyleManager { + /** + * Arrays that contain all registered styles + */ private static ArrayList styles = new ArrayList(); private static ArrayList customHandledStyles = new ArrayList(); + /** + * Registers a style that is put into the plugin's update loop + * + * @param style The style to add + */ public static void registerStyle(ParticleStyle style) { for (ParticleStyle testAgainst : styles) { if (testAgainst.getName().replace("_", "").equalsIgnoreCase(style.getName())) { @@ -18,15 +34,30 @@ public class ParticleStyleManager { styles.add(style); } + /** + * Registers a style that isn't updated on the normal update loop + * + * @param style The style to register + */ public static void registerCustomHandledStyle(ParticleStyle style) { registerStyle(style); customHandledStyles.add(style); } + /** + * Returns if a given style is customly handled + * + * @param style The style to check + * @return If the style is handled in a custom manner + */ public static boolean isCustomHandled(ParticleStyle style) { return customHandledStyles.contains(style); } + /** + * Gets all registered styles + * @return An ArrayList of all registered styles + */ public static ArrayList getStyles() { return styles; } diff --git a/src/com/esophose/playerparticles/updater/PluginUpdateListener.java b/src/com/esophose/playerparticles/updater/PluginUpdateListener.java index bb29c77..18d31a5 100644 --- a/src/com/esophose/playerparticles/updater/PluginUpdateListener.java +++ b/src/com/esophose/playerparticles/updater/PluginUpdateListener.java @@ -21,14 +21,14 @@ public class PluginUpdateListener implements Listener { /** * Called when a player joins and notifies ops if an update is available * - * @param e The event + * @param e The join event */ @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { if (e.getPlayer().isOp()) { if (PlayerParticles.updateVersion != null) { - MessageManager.getInstance().sendMessage(e.getPlayer(), "An update (" + ChatColor.AQUA + "v" + PlayerParticles.updateVersion + ChatColor.YELLOW + ") is available! You are running " + ChatColor.AQUA + "v" + PlayerParticles.getPlugin().getDescription().getVersion(), ChatColor.YELLOW); - MessageManager.getInstance().sendMessage(e.getPlayer(), "Download from: http://dev.bukkit.org/bukkit-plugins/playerparticles/", ChatColor.YELLOW); + MessageManager.sendCustomMessage(e.getPlayer(), ChatColor.YELLOW + "An update (" + ChatColor.AQUA + "v" + PlayerParticles.updateVersion + ChatColor.YELLOW + ") is available! You are running " + ChatColor.AQUA + "v" + PlayerParticles.getPlugin().getDescription().getVersion()); + MessageManager.sendCustomMessage(e.getPlayer(), ChatColor.YELLOW + "Download from: http://dev.bukkit.org/bukkit-plugins/playerparticles/"); } } } diff --git a/src/config.yml b/src/config.yml index 590fa5b..bbc978b 100644 --- a/src/config.yml +++ b/src/config.yml @@ -1,5 +1,5 @@ -# __________.__ __________ __ .__ .__ _____ -# \______ \ | _____ ___.__. __________\______ \_____ ________/ |_|__| ____ | | ____ ______ ___ __/ | | +# ____________ __________ __ __ __ _____ +# \______ \ | _____ ___ __ __________\______ \_____ ________/ |_|__| ____ | | ____ ______ ___ __/ | | # | ___/ | \__ \< | |/ __ \_ __ \ ___/\__ \\_ __ \ __\ |/ ___\| | _/ __ \ / ___/ \ \/ / | |_ # | | | |__/ __ \\___ \ ___/| | \/ | / __ \| | \/| | | \ \___| |_\ ___/ \___ \ \ / ^ / # |____| |____(____ / ____|\___ >__| |____| (____ /__| |__| |__|\___ >____/\___ >____ > \_/\____ | @@ -13,7 +13,7 @@ # Changing this value will reset your config on the next server reload/restart. # I don't recommend changing it -version: 4 +version: 4.1 # How many ticks to wait before spawning more particles # Increasing this value may cause less lag, but will decrease prettiness @@ -27,6 +27,7 @@ ticks-per-particle: 1 check-updates: true # The worlds which this plugin is disabled in +# Remove the [] before you enter worlds names # Default: [] disabled-worlds: [] # - your_world_name_here @@ -43,12 +44,13 @@ use-message-prefix: true # The prefix to use for all PlayerParticle messages # Use & to set color / format # This is useless if use-message-prefix is set to false -# Default: '&c[&ePlayerParticles&c]' +# Default: '&7[&3PlayerParticles&7]' message-prefix: '&7[&3PlayerParticles&7]' # ================================================================ # # MESSAGE CONFIGURATION # # Important Notes: # +# * You can use the & symbol to color the messages # # * {TYPE} Will be replaced with whatever that message requires # # * You can not use the apostrophe character! ( ' ) # # ================================================================ # @@ -58,153 +60,146 @@ message-prefix: '&7[&3PlayerParticles&7]' # ------------- # # No Particle Permission -# Default: 'You do not have permission to use {TYPE} particles!' -message-no-permission: 'You do not have permission to use {TYPE} particles!' +# Default: '&cYou do not have permission to use &b{TYPE} &cparticles!' +message-no-permission: '&cYou do not have permission to use &b{TYPE} &cparticles!' # /pp list No Particles -# Default: 'You do not have permission to use any particles!' -message-no-particles: 'You do not have permission to use any particles!' +# Default: '&cYou do not have permission to use any particles!' +message-no-particles: '&cYou do not have permission to use any particles!' # Now Using Particles -# Default: 'Now using {TYPE} particles!' -message-now-using: 'Now using {TYPE} particles!' +# Default: '&aNow using &b{TYPE} &aparticles!' +message-now-using: '&aNow using &b{TYPE} &aparticles!' # Cleared Particles -# Default: 'Your particles have been cleared!' -message-cleared-particles: 'Your particles have been cleared!' - -# You Can Use Particles -# Default: 'You can use:' -message-use: 'You can use:' +# Default: '&aYour particles have been cleared!' +message-cleared-particles: '&aYour particles have been cleared!' # Invalid Particle Type -# Default: 'Invalid particle type!' -message-invalid-type: 'Invalid particle type!' +# Default: '&cInvalid particle type! &b/pp effects' +message-invalid-type: '&cInvalid particle type! &b/pp effects &c| &b/pp effect ' + +# Particle Command Usage +# You should not change the text here, only the coloring +# Default: '&b/pp effect ' +message-particle-usage: '&b/pp effect ' # -------------- # # Styles # # -------------- # # No Style Permission -# Default: 'You do not have permission to use the style type {TYPE}!' -message-no-permission-style: 'You do not have permission to use the style type {TYPE}!' +# Default: '&cYou do not have permission to use the style type &b{TYPE}&c!' +message-no-permission-style: '&cYou do not have permission to use the style type &b{TYPE}&c!' # /pp styles No Styles -# Default: 'You do not have permission to use any particles!' -message-no-styles: 'You do not have permission to use any styles!' +# Default: '&cYou do not have permission to use any styles!' +message-no-styles: '&cYou do not have permission to use any styles!' # Now Using Style -# Default: 'Now using the style type {TYPE}!' -message-now-using-style: 'Now using the style type {TYPE}!' +# Default: '&aNow using the style type &b{TYPE}&a!' +message-now-using-style: '&aNow using the style type &b{TYPE}&a!' # Cleared Style -# Default: 'Cleared your particles!' -message-cleared-style: 'Your style has been cleared!' - -# You Can Use Styles -# Default: 'You can use:' -message-use-style: 'You can use:' +# Default: '&aYour style has been cleared!' +message-cleared-style: '&aYour style has been cleared!' # Invalid Style Type -# Default: 'Invalid style type!' -message-invalid-type-style: 'Invalid style type!' +# Default: '&cInvalid style type! &b/pp styles &c| &b/pp style ' +message-invalid-type-style: '&cInvalid style type! &b/pp styles &c| &b/pp style ' + +# Style Command Usage +# You should not change the text here, only the coloring +# Default: '&b/pp style ' +message-style-usage: '&b/pp style ' # ------------ # # Data # # ------------ # -# Note Data Usage -# Default: 'Your current effect requires note data.' -message-note-data-usage: 'Your current effect requires note data.' - -# Color Data Usage -# Default: 'Your current effect requires color data.' -message-color-data-usage: 'Your current effect requires color data.' - -# Block Data Usage -# Default: 'Your current effect requires block data.' -message-block-data-usage: 'Your current effect requires block data.' - -# Item Data Usage -# Default: 'Your current effect requires item data.' -message-item-data-usage: 'Your current effect requires item data.' +# Data Usage +# Default: '&eYour current effect requires &b{TYPE} &edata!' +message-data-usage: '&eYour current effect requires &b{TYPE} &edata!' # No Data Required -# Default: 'Your current effect does not use any data.' -message-no-data-usage: 'Your current effect does not use any data.' +# Default: '&eYour current effect does not use any data!' +message-no-data-usage: '&eYour current effect does not use any data!' -# Note Data Applied -# Default: 'Your note data has been applied!' -message-note-data-applied: 'Your note data has been applied!' +# Data Applied +# Default: '&aYour &b{TYPE} &adata has been applied!' +message-data-applied: '&aYour &b{TYPE} &adata has been applied!' -# Color Data Applied -# Default: 'Your color data has been applied!' -message-color-data-applied: 'Your color data has been applied!' +# Invalid Data Arguments +# Default: '&cInvalid &b{TYPE} &cdata arguments!' +message-data-invalid-arguments: '&cInvalid &b{TYPE} &cdata arguments!' -# Block Data Applied -# Default: 'Your block data has been applied!' -message-block-data-applied: 'Your block data has been applied!' +# Unknown Material +# Default: '&cThe {TYPE} name you supplied is invalid!' +message-data-material-unknown: '&cThe &b{TYPE} &cname you supplied is invalid!' -# Item Data Applied -# Default: 'Your item data has been applied!' -message-item-data-applied: 'Your item data has been applied!' +# Mismatched Material +# Default: '&cThe material supplied is not of type &b{TYPE}&c!' +message-data-material-mismatch: '&cThe material supplied is not of type &b{TYPE}&c!' -# Invalid Note Data Arguments -# Default: 'Invalid note data arguments!' -message-note-data-invalid-arguments: 'Invalid note data arguments!' +# Note Data Usage +# You should not change the text here, only the coloring +# Default: '&b/pp data <0-23>' +message-note-data-usage: '&b/pp data <0-23>' -# Invalid Color Data Arguments -# Default: 'Invalid color data arguments!' -message-color-data-invalid-arguments: 'Invalid color data arguments!' +# Color Data Usage +# You should not change the text here, only the coloring +# Default: '&b/pp data <0-255> <0-255> <0-255>' +message-color-data-usage: '&b/pp data <0-255> <0-255> <0-255>' -# Invalid Block Data Arguments -# Default: 'Invalid block data arguments!' -message-block-data-invalid-arguments: 'Invalid block data arguments!' +# Item Data Usage +# You should not change the text here, only the coloring +# Default: '&b/pp data <0-15>' +message-item-data-usage: '&b/pp data <0-15>' -# Invalid Item Data Arguments -# Default: 'Invalid item data arguments!' -message-item-data-invalid-arguments: 'Invalid item data arguments!' +# Block Data Usage +# You should not change the text here, only the coloring +# Default: '&b/pp data <0-15>' +message-block-data-usage: '&b/pp data <0-15>' -# Unknown Block Material -# Default: 'The block name you supplied is invalid' -message-block-data-material-unknown: 'The block name you supplied is invalid' +# ---------------- # +# Prefixes # +# ---------------- # -# Unknown Item Material -# Default: 'The item name you supplied is invalid' -message-item-data-material-unknown: 'The item name you supplied is invalid' +# You Can Use Particles +# Default: '&eYou can use:' +message-use: '&eYou can use:&b' -<<<<<<< HEAD -======= +# Usage +# Default: '&eUsage:' +message-usage: '&eUsage:' +# Available Commands +# Default: '&eAvailable commands: &beffect, effects, style, styles, data, reset, worlds, version, help' +message-available-commands: '&eAvailable commands: &beffect, effects, style, styles, data, reset, worlds, version, help' + +# Disabled Worlds +# Default: '&eParticles are disabled in these worlds:&b' +message-disabled-worlds: '&eParticles are disabled in these worlds:&b' ->>>>>>> refs/remotes/origin/master # ------------- # # Other # # ------------- # -# Usage -# Default: 'Usage:' -message-usage: 'Usage:' - # Reset -# Default: 'Your effect, style, and data have all been reset!' -message-reset: 'Your effect, style, and data have all been reset!' +# Default: '&aYour effect, style, and data have all been reset!' +message-reset: '&aYour effect, style, and data have all been reset!' # Invalid Arguments -# Default: 'Invalid arguments!' -message-invalid-arguments: 'Invalid arguments!' - -# Available Commands -# Default: 'Available commands:' -message-available-commands: 'Available commands:' +# Default: '&cInvalid arguments! &a/pp help' +message-invalid-arguments: '&cInvalid arguments! &b/pp help' # Disabled Worlds None -# Default: 'Particles are not disabled in any worlds!' -message-disabled-worlds-none: 'Particles are not disabled in any worlds!' +# Default: '&eParticles are not disabled in any worlds!' +message-disabled-worlds-none: '&eParticles are not disabled in any worlds!' -# Disabled Worlds -# Default: 'Particles are disabled in these worlds:' -message-disabled-worlds: 'Particles are disabled in these worlds:' +# Command Usage +# Default: '&eCommand Usage: /pp ' +message-command-usage: '&eCommand Usage: &b/pp ' # ================================================================ # # DATABASE CONFIGURATION # diff --git a/src/plugin.yml b/src/plugin.yml index 23c3de9..fd399c9 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: PlayerParticles main: com.esophose.playerparticles.PlayerParticles -version: 4 +version: 4.1 description: Make particles around players. author: Esophose website: http://dev.bukkit.org/bukkit-plugins/playerparticles/