From 69dddacd92b68265c35f7cf0fa88823f8b141cc5 Mon Sep 17 00:00:00 2001 From: Esophose Date: Wed, 15 Feb 2017 22:05:50 -0700 Subject: [PATCH] Updating to v4.3 Implemented Fixed Effects, still working on the command Fixed a few bugs --- PlayerParticles.jardesc | 20 ++ .../playerparticles/FixedParticleEffect.java | 222 ++++++++++++ src/com/esophose/playerparticles/PPlayer.java | 43 ++- .../ParticleCommandCompleter.java | 2 + .../ParticleCommandExecutor.java | 79 +++- .../playerparticles/ParticlesUtil.java | 37 -- .../playerparticles/PlayerParticles.java | 79 ++-- .../playerparticles/gui/GUIHandler.java | 9 + .../playerparticles/library/Database.java | 3 +- .../manager/ConfigManager.java | 336 ++++++++++++++++-- .../manager/MessageManager.java | 8 + .../ParticleManager.java} | 122 ++++++- .../manager/PermissionManager.java | 18 +- .../playerparticles/styles/DefaultStyles.java | 2 + .../styles/ParticleStyleArrows.java | 18 +- .../styles/ParticleStyleBeam.java | 4 + .../styles/ParticleStyleCube.java | 6 +- .../styles/ParticleStyleFeet.java | 4 + .../styles/ParticleStyleHalo.java | 4 + .../styles/ParticleStyleMove.java | 10 +- .../styles/ParticleStyleNone.java | 4 + .../styles/ParticleStyleOrbit.java | 4 + .../styles/ParticleStylePoint.java | 4 + .../styles/ParticleStyleQuadhelix.java | 4 + .../styles/ParticleStyleSpin.java | 4 + .../styles/ParticleStyleSpiral.java | 4 + .../styles/ParticleStyleThick.java | 30 ++ .../styles/api/ParticleStyle.java | 15 + .../playerparticles/util/ParticlesUtils.java | 57 +++ .../{library => util}/VectorUtils.java | 2 +- src/config.yml | 64 +++- src/plugin.yml | 2 +- 32 files changed, 1062 insertions(+), 158 deletions(-) create mode 100644 PlayerParticles.jardesc create mode 100644 src/com/esophose/playerparticles/FixedParticleEffect.java delete mode 100644 src/com/esophose/playerparticles/ParticlesUtil.java create mode 100644 src/com/esophose/playerparticles/gui/GUIHandler.java rename src/com/esophose/playerparticles/{ParticleCreator.java => manager/ParticleManager.java} (60%) create mode 100644 src/com/esophose/playerparticles/styles/ParticleStyleThick.java create mode 100644 src/com/esophose/playerparticles/util/ParticlesUtils.java rename src/com/esophose/playerparticles/{library => util}/VectorUtils.java (99%) diff --git a/PlayerParticles.jardesc b/PlayerParticles.jardesc new file mode 100644 index 0000000..91b1a15 --- /dev/null +++ b/PlayerParticles.jardesc @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/esophose/playerparticles/FixedParticleEffect.java b/src/com/esophose/playerparticles/FixedParticleEffect.java new file mode 100644 index 0000000..19dfcaf --- /dev/null +++ b/src/com/esophose/playerparticles/FixedParticleEffect.java @@ -0,0 +1,222 @@ +/** + * 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; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; + +import com.esophose.playerparticles.library.ParticleEffect; +import com.esophose.playerparticles.library.ParticleEffect.BlockData; +import com.esophose.playerparticles.library.ParticleEffect.ItemData; +import com.esophose.playerparticles.library.ParticleEffect.NoteColor; +import com.esophose.playerparticles.library.ParticleEffect.OrdinaryColor; +import com.esophose.playerparticles.library.ParticleEffect.ParticleColor; +import com.esophose.playerparticles.library.ParticleEffect.ParticleData; +import com.esophose.playerparticles.library.ParticleEffect.ParticleProperty; +import com.esophose.playerparticles.manager.ConfigManager; +import com.esophose.playerparticles.manager.ParticleManager; +import com.esophose.playerparticles.styles.api.ParticleStyle; + +public class FixedParticleEffect { + + /** + * The UUID of the player who owns this effect + */ + private UUID pplayerUUID; + + /** + * The ID of this effect, unique to the owner's UUID + */ + private int id; + + /** + * The location for this effect to be displayed + */ + private Location location; + + /** + * The effect and style this effect uses + */ + private ParticleEffect particleEffect; + private ParticleStyle particleStyle; + + /** + * The data this effect uses + */ + private ItemData particleItemData; + private BlockData particleBlockData; + private OrdinaryColor particleColorData; + private NoteColor particleNoteColorData; + + /** + * Constructs a new FixedParticleEffect + * FixedParticleEffects can NOT use custom handled styles + * This is basically the same thing as a PPlayer, maybe we can extend it in the future? + * + * @param pplayerUUID The UUID of the player who owns the effect + * @param worldName The world name this effect will be displayed in + * @param xPos The X position in the world + * @param yPos The Y position in the world + * @param zPos The Z position in the world + * @param particleEffect The particle effect to use + * @param particleStyle The particle style to use + * @param particleData The particle data to use with the effect + */ + public FixedParticleEffect(UUID pplayerUUID, int id, String worldName, double xPos, double yPos, double zPos, ParticleEffect particleEffect, ParticleStyle particleStyle, ItemData itemData, BlockData blockData, OrdinaryColor colorData, NoteColor noteColorData) { + this.pplayerUUID = pplayerUUID; + this.id = id; + + this.particleEffect = particleEffect; + this.particleStyle = particleStyle; + + this.particleItemData = itemData; + this.particleBlockData = blockData; + this.particleColorData = colorData; + this.particleNoteColorData = noteColorData; + + PPlayer owner = ConfigManager.getInstance().getPPlayer(this.pplayerUUID, false); + + // Check nulls, if any are null set them to the PPlayer's values + if (this.particleItemData == null) this.particleItemData = owner.getItemData(); + if (this.particleBlockData == null) this.particleBlockData = owner.getBlockData(); + if (this.particleColorData == null) this.particleColorData = owner.getColorData(); + if (this.particleNoteColorData == null) this.particleNoteColorData = owner.getNoteColorData(); + + World world = Bukkit.getWorld(worldName); + if (world == null) { // Default to the first world in case it doesn't exist + world = Bukkit.getWorlds().get(0); // All servers will have at least one world + } + + this.location = new Location(world, xPos, yPos, zPos); + } + + /** + * Gets the owner of the effect's UUID + * + * @return The owner of the effect's UUID + */ + public UUID getOwnerUniqueId() { + return this.pplayerUUID; + } + + /** + * Gets the id unique to the owner's UUID + * + * @return This effect's id + */ + public int getId() { + return this.id; + } + + /** + * Gets the particle effect used for this effect + * + * @return The particle effect used for this effect + */ + public ParticleEffect getParticleEffect() { + return this.particleEffect; + } + + /** + * Gets the particle style used for this effect + * + * @return The particle style used for this effect + */ + public ParticleStyle getParticleStyle() { + return this.particleStyle; + } + + /** + * Gets the effect's item data + * + * @return The effect's item data + */ + public ItemData getItemData() { + return this.particleItemData; + } + + /** + * Gets the effect's block data + * + * @return The effect's block data + */ + public BlockData getBlockData() { + return this.particleBlockData; + } + + /** + * Gets the effect's color data + * + * @return The effect's color data + */ + public OrdinaryColor getColorData() { + return this.particleColorData; + } + + /** + * Gets the effect's note color data + * + * @return The effect's note color data + */ + public NoteColor getNoteColorData() { + return this.particleNoteColorData; + } + + /** + * Gets the data the current particle effect will spawn with + * + * @return The ParticleData the current particle effect requires + */ + public ParticleData getParticleSpawnData() { + if (this.particleEffect.hasProperty(ParticleProperty.REQUIRES_DATA)) { + if (this.particleEffect == ParticleEffect.BLOCK_CRACK || this.particleEffect == ParticleEffect.BLOCK_DUST || this.particleEffect == ParticleEffect.FALLING_DUST) { + return particleBlockData; + } else if (this.particleEffect == ParticleEffect.ITEM_CRACK) { + return this.particleItemData; + } + } + 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 (this.particleEffect.hasProperty(ParticleProperty.COLORABLE)) { + if (this.particleEffect == ParticleEffect.NOTE) { + if (this.particleNoteColorData.getValueX() * 24 == 99) { + return ParticleManager.getRainbowNoteParticleColor(); + } + return this.particleNoteColorData; + } else { + if (this.particleColorData.getRed() == 999 && this.particleColorData.getGreen() == 999 && this.particleColorData.getBlue() == 999) { + return ParticleManager.getRainbowParticleColor(); + } else { + return this.particleColorData; + } + } + } + return null; + } + + /** + * Gets the location this effect will be displayed at + * + * @return The effect's location + */ + public Location getLocation() { + return this.location; + } + +} diff --git a/src/com/esophose/playerparticles/PPlayer.java b/src/com/esophose/playerparticles/PPlayer.java index 046e6a6..0b7331e 100644 --- a/src/com/esophose/playerparticles/PPlayer.java +++ b/src/com/esophose/playerparticles/PPlayer.java @@ -20,6 +20,7 @@ import com.esophose.playerparticles.library.ParticleEffect.OrdinaryColor; import com.esophose.playerparticles.library.ParticleEffect.ParticleColor; import com.esophose.playerparticles.library.ParticleEffect.ParticleData; import com.esophose.playerparticles.library.ParticleEffect.ParticleProperty; +import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.styles.DefaultStyles; import com.esophose.playerparticles.styles.api.ParticleStyle; @@ -57,12 +58,12 @@ public class PPlayer { */ public PPlayer(UUID uuid, ParticleEffect effect, ParticleStyle style, ItemData itemData, BlockData blockData, OrdinaryColor colorData, NoteColor noteColorData) { this.playerUUID = uuid; - this.particleEffect = effect; - this.particleStyle = style; - this.particleItemData = itemData; - this.particleBlockData = blockData; - this.particleColorData = colorData; - this.particleNoteColorData = noteColorData; + this.setParticleEffect(effect); + this.setParticleStyle(style); + this.setItemData(itemData); + this.setBlockData(blockData); + this.setColorData(colorData); + this.setNoteColorData(noteColorData); } /** @@ -134,6 +135,7 @@ public class PPlayer { * @param effect The player's new particle effect */ public void setParticleEffect(ParticleEffect effect) { + if (effect == null) effect = ParticleEffect.NONE; this.particleEffect = effect; } @@ -143,6 +145,7 @@ public class PPlayer { * @param effect The player's new particle style */ public void setParticleStyle(ParticleStyle style) { + if (style == null) style = DefaultStyles.NONE; this.particleStyle = style; } @@ -152,6 +155,7 @@ public class PPlayer { * @param effect The player's new item data */ public void setItemData(ItemData itemData) { + if (itemData == null) itemData = new ItemData(Material.IRON_SPADE, (byte) 0); this.particleItemData = itemData; } @@ -161,6 +165,7 @@ public class PPlayer { * @param effect The player's new block data */ public void setBlockData(BlockData blockData) { + if (blockData == null) blockData = new BlockData(Material.STONE, (byte) 0); this.particleBlockData = blockData; } @@ -170,6 +175,7 @@ public class PPlayer { * @param effect The player's new color data */ public void setColorData(OrdinaryColor colorData) { + if (colorData == null) colorData = new OrdinaryColor(0, 0, 0); this.particleColorData = colorData; } @@ -179,6 +185,7 @@ public class PPlayer { * @param effect The player's new note color data */ public void setNoteColorData(NoteColor noteColorData) { + if (noteColorData == null) noteColorData = new NoteColor(0); this.particleNoteColorData = noteColorData; } @@ -188,11 +195,11 @@ public class PPlayer { * @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) { + if (this.particleEffect.hasProperty(ParticleProperty.REQUIRES_DATA)) { + if (this.particleEffect == ParticleEffect.BLOCK_CRACK || this.particleEffect == ParticleEffect.BLOCK_DUST || this.particleEffect == ParticleEffect.FALLING_DUST) { return particleBlockData; - } else if (particleEffect == ParticleEffect.ITEM_CRACK) { - return particleItemData; + } else if (this.particleEffect == ParticleEffect.ITEM_CRACK) { + return this.particleItemData; } } return null; @@ -204,17 +211,17 @@ public class PPlayer { * @return Gets the ParticleColor the current particle effect will spawn with */ public ParticleColor getParticleSpawnColor() { - if (particleEffect.hasProperty(ParticleProperty.COLORABLE)) { - if (particleEffect == ParticleEffect.NOTE) { - if (particleNoteColorData.getValueX() * 24 == 99) { - return ParticleCreator.getRainbowNoteParticleColor(); + if (this.particleEffect.hasProperty(ParticleProperty.COLORABLE)) { + if (this.particleEffect == ParticleEffect.NOTE) { + if (this.particleNoteColorData.getValueX() * 24 == 99) { + return ParticleManager.getRainbowNoteParticleColor(); } - return particleNoteColorData; + return this.particleNoteColorData; } else { - if (particleColorData.getRed() == 999 && particleColorData.getGreen() == 999 && particleColorData.getBlue() == 999) { - return ParticleCreator.getRainbowParticleColor(); + if (this.particleColorData.getRed() == 999 && this.particleColorData.getGreen() == 999 && this.particleColorData.getBlue() == 999) { + return ParticleManager.getRainbowParticleColor(); } else { - return particleColorData; + return this.particleColorData; } } } diff --git a/src/com/esophose/playerparticles/ParticleCommandCompleter.java b/src/com/esophose/playerparticles/ParticleCommandCompleter.java index f870013..fee53d5 100644 --- a/src/com/esophose/playerparticles/ParticleCommandCompleter.java +++ b/src/com/esophose/playerparticles/ParticleCommandCompleter.java @@ -40,6 +40,8 @@ public class ParticleCommandCompleter implements TabCompleter { list.add("styles"); list.add("worlds"); list.add("version"); + list.add("fixed"); + list.add("reset"); return list; } else if (args.length == 1) { if (args[0].equalsIgnoreCase("effect")) { diff --git a/src/com/esophose/playerparticles/ParticleCommandExecutor.java b/src/com/esophose/playerparticles/ParticleCommandExecutor.java index 66ae107..ac0adad 100644 --- a/src/com/esophose/playerparticles/ParticleCommandExecutor.java +++ b/src/com/esophose/playerparticles/ParticleCommandExecutor.java @@ -27,10 +27,12 @@ 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.ParticleManager; import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.styles.DefaultStyles; import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyleManager; +import com.esophose.playerparticles.util.ParticlesUtils; public class ParticleCommandExecutor implements CommandExecutor { @@ -80,6 +82,9 @@ public class ParticleCommandExecutor implements CommandExecutor { case "data": onData(p, cmdArgs); break; + case "fixed": + onFixed(p, cmdArgs); + break; case "reset": onReset(p, cmdArgs); break; @@ -149,7 +154,7 @@ public class ParticleCommandExecutor implements CommandExecutor { * @param args The arguments for the command */ private void onData(Player p, String[] args) { - ParticleEffect effect = ConfigManager.getInstance().getPPlayer(p.getUniqueId()).getParticleEffect(); + ParticleEffect effect = ConfigManager.getInstance().getPPlayer(p.getUniqueId(), false).getParticleEffect(); if ((!effect.hasProperty(ParticleProperty.REQUIRES_DATA) && !effect.hasProperty(ParticleProperty.COLORABLE)) || args.length == 0) { if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect == ParticleEffect.NOTE) { @@ -235,7 +240,7 @@ public class ParticleCommandExecutor implements CommandExecutor { int data = -1; try { - material = ParticlesUtil.closestMatch(args[0]); + material = ParticlesUtils.closestMatch(args[0]); if (material == null) material = Material.matchMaterial(args[0]); if (material == null) throw new Exception(); } catch (Exception e) { @@ -271,7 +276,7 @@ public class ParticleCommandExecutor implements CommandExecutor { int data = -1; try { - material = ParticlesUtil.closestMatch(args[0]); + material = ParticlesUtils.closestMatch(args[0]); if (material == null) material = Material.matchMaterial(args[0]); if (material == null) throw new Exception(); } catch (Exception e) { @@ -308,11 +313,11 @@ public class ParticleCommandExecutor implements CommandExecutor { /** * Called when a player uses /pp reset + * Can be executed for another player by having their name as the final command argument * * @param p The player who used the command - * @param altPlayer The alternate player to reset */ - private void onReset(Player p, String[] args) { // TODO: Apply this to effects, styles, and data(?) + private void onReset(Player p, String[] args) { if (args.length >= 1) { String altPlayerName = args[0]; if (!PermissionManager.canExecuteForOthers(p)) { @@ -320,7 +325,7 @@ public class ParticleCommandExecutor implements CommandExecutor { } else { Player altPlayer = getOnlinePlayerByName(altPlayerName); if (altPlayer == null) { - MessageManager.sendMessage(p, MessageType.FAILED_EXECUTE_NOT_FOUND); + MessageManager.sendMessage(p, MessageType.FAILED_EXECUTE_NOT_FOUND, altPlayerName); } else { ConfigManager.getInstance().resetPPlayer(altPlayer.getUniqueId()); MessageManager.sendMessage(altPlayer, MessageType.RESET); @@ -339,7 +344,6 @@ public class ParticleCommandExecutor implements CommandExecutor { * * @param p The player who used the command * @param args The arguments for the command - * @param altPlayer The alternate player to give the effect */ private void onEffect(Player p, String[] args) { if (args.length == 0) { @@ -347,8 +351,8 @@ public class ParticleCommandExecutor implements CommandExecutor { return; } String argument = args[0].replace("_", ""); - if (ParticleCreator.particleFromString(argument) != null) { - ParticleEffect effect = ParticleCreator.particleFromString(argument); + if (ParticleManager.particleFromString(argument) != null) { + ParticleEffect effect = ParticleManager.particleFromString(argument); if (!PermissionManager.hasEffectPermission(p, effect)) { MessageManager.sendMessage(p, MessageType.NO_PERMISSION, effect.getName().toLowerCase()); return; @@ -393,7 +397,6 @@ public class ParticleCommandExecutor implements CommandExecutor { * * @param p The player who used the command * @param args The arguments for the command - * @param altPlayer The alternate player to give the style */ private void onStyle(Player p, String[] args) { if (args.length == 0) { @@ -441,5 +444,61 @@ public class ParticleCommandExecutor implements CommandExecutor { MessageManager.sendCustomMessage(p, toSend); MessageManager.sendCustomMessage(p, MessageType.USAGE.getMessage() + " " + MessageType.STYLE_USAGE.getMessage()); } + + /* + + + + + Requires permission playerparticles.fixed + Maximum number of fixed effects defined in config.yml, default value 5 + */ + + /** + * Called when a player uses /pp fixed + * + * @param p The player who used the command + * @param args The arguments for the command + */ + private void onFixed(Player p, String[] args) { + if (!PermissionManager.canUseFixedEffects(p)) { + MessageManager.sendMessage(p, MessageType.NO_PERMISSION_FIXED); + return; + } + + if (args.length == 0) { // General information on command + MessageManager.sendMessage(p, MessageType.INVALID_FIXED_COMMAND); + MessageManager.sendMessage(p, MessageType.FIXED_COMMAND_DESC_CREATE); + MessageManager.sendMessage(p, MessageType.FIXED_COMMAND_DESC_REMOVE); + MessageManager.sendMessage(p, MessageType.FIXED_COMMAND_DESC_LIST); + MessageManager.sendMessage(p, MessageType.FIXED_COMMAND_DESC_INFO); + return; + } + + String cmd = args[0]; + + if (cmd.equalsIgnoreCase("create")) { + if (ConfigManager.getInstance().getNumberOfFixedEffectsForPlayer(p.getUniqueId()) > PlayerParticles.getPlugin().getConfig().getInt("max-fixed-effects")) { + + } + + // /pp fixed create