From e47da74d22fc38726bdc29f3d4d91cb403106d45 Mon Sep 17 00:00:00 2001 From: Esophose Date: Sun, 4 Mar 2018 03:02:02 -0700 Subject: [PATCH] Add new styles Add five new event-based styles, make it so the message manager doesn't have an extra system.out.println, fix a somewhat critical bug with fixed effect clear permissions, make it so the ParticleStyleManager doesn't absolutely break the plugin if somebody registers a style incorrectly in an extension plugin. --- .../ParticleCommandExecutor.java | 5 +- .../playerparticles/PlayerParticles.java | 42 ++++++----- .../manager/MessageManager.java | 14 ++-- .../manager/PermissionManager.java | 13 +--- .../playerparticles/styles/DefaultStyles.java | 25 ++++++- .../styles/ParticleStyleBlockBreak.java | 53 ++++++++++++++ .../styles/ParticleStyleBlockEdit.java | 56 +++++++++++++++ .../styles/ParticleStyleBlockPlace.java | 53 ++++++++++++++ .../styles/ParticleStyleHurt.java | 55 +++++++++++++++ .../styles/ParticleStyleMove.java | 28 +++++--- .../styles/ParticleStyleSwords.java | 70 +++++++++++++++++++ .../styles/ParticleStyleThick.java | 9 ++- .../styles/ParticleStyleWings.java | 2 +- .../styles/api/ParticleStyleManager.java | 19 ++--- src/config.yml | 10 ++- 15 files changed, 374 insertions(+), 80 deletions(-) create mode 100644 src/com/esophose/playerparticles/styles/ParticleStyleBlockBreak.java create mode 100644 src/com/esophose/playerparticles/styles/ParticleStyleBlockEdit.java create mode 100644 src/com/esophose/playerparticles/styles/ParticleStyleBlockPlace.java create mode 100644 src/com/esophose/playerparticles/styles/ParticleStyleHurt.java create mode 100644 src/com/esophose/playerparticles/styles/ParticleStyleSwords.java diff --git a/src/com/esophose/playerparticles/ParticleCommandExecutor.java b/src/com/esophose/playerparticles/ParticleCommandExecutor.java index 80912c2..c5e7e60 100644 --- a/src/com/esophose/playerparticles/ParticleCommandExecutor.java +++ b/src/com/esophose/playerparticles/ParticleCommandExecutor.java @@ -524,7 +524,7 @@ public class ParticleCommandExecutor implements CommandExecutor { args = cmdArgs; if (cmd.equalsIgnoreCase("create")) { - String[] f_args = args; + final String[] f_args = args; ConfigManager.getInstance().hasPlayerReachedMaxFixedEffects(p.getUniqueId(), (reachedMax) -> { if (reachedMax) { MessageManager.sendMessage(p, MessageType.MAX_FIXED_EFFECTS_REACHED); @@ -815,7 +815,8 @@ public class ParticleCommandExecutor implements CommandExecutor { ArrayList fixedEffectsToRemove = new ArrayList(); for (FixedParticleEffect fixedEffect : ParticleManager.fixedParticleEffects) - if (fixedEffect.getLocation().getWorld() == p.getLocation().getWorld() && fixedEffect.getLocation().distance(p.getLocation()) <= radius) fixedEffectsToRemove.add(fixedEffect); + if (fixedEffect.getLocation().getWorld() == p.getLocation().getWorld() && fixedEffect.getLocation().distance(p.getLocation()) <= radius) + fixedEffectsToRemove.add(fixedEffect); for (FixedParticleEffect fixedEffect : fixedEffectsToRemove) ConfigManager.getInstance().removeFixedEffect(fixedEffect.getOwnerUniqueId(), fixedEffect.getId(), (successful) -> { }); diff --git a/src/com/esophose/playerparticles/PlayerParticles.java b/src/com/esophose/playerparticles/PlayerParticles.java index 8d1c01c..c2371cd 100644 --- a/src/com/esophose/playerparticles/PlayerParticles.java +++ b/src/com/esophose/playerparticles/PlayerParticles.java @@ -7,37 +7,35 @@ */ /* - * TODO: v5 - * + Add new style 'tornado' - * + Add new style 'fairy' - * + Add new style 'atom' - * + Add new style 'rings' - * + Add new style 'jump' - * + Add new style 'blockbreak' - * + Add new style 'blockplace' - * + Add new style 'hurt' - * + Add new style 'swords' - * + Make database queries async + * TODO: v5.1 * + Command to force set an effect/style for a player * + Tab completion for fixed effects + * + Add new style 'tornado' + * + Add new style 'companion' + * + Add new style 'atom' + * + Add new style 'rings' */ /* * Changelog v5: - * + Added GUI. Opens with /pp or /pp gui. Icons and messages are completely customizable from the config. + * + Added a GUI. Opens with /pp or /pp gui. Icons and messages are completely customizable from the config. * + Added a way to disable the GUI, because I know somebody will ask * + Added new style 'wings' * + Added new style 'sphere' - * - Minecraft 1.7 and 1.8 are no longer supported. There is no reason to still be on a version that old. - * Fixed a bug where typing /pp data when you haven't been added to the playerData.yml/database yet threw an error - * Switched over to the Spigot Particle API - * Plugin is now built against Java 1.8.0_161 and Spigot 1.9.4 - * Servers running Java 7 are no longer supported. Please upgrade to Java 8 if you haven't yet. - * Rewrote database connection system, should fix any memory leaks from before - * Reduced particle render distance from 512 to 192 (12 chunks), you won't notice a difference - * Database management should no longer contain memory leaks - * Fixed missing command 'fixed' from '/pp help' list - * Fixed missing command 'fixed' from tab completion + * + Added new style 'hurt' + * + Added new style 'swords' + * + Added new style 'blockbreak' + * + Added new style 'blockplace' + * + Added new style 'blockedit' + * - Minecraft 1.7 and 1.8 are no longer supported, there is no reason to still be on a version that old + * - Servers running Java 7 are no longer supported, please upgrade to Java 8 if you haven't yet + * * Fixed a bug where typing /pp data when you haven't been added to the playerData.yml/database yet threw an error + * * Switched over to the Spigot Particle API + * * Plugin is now built against Java 1.8.0_161 and Spigot 1.9.4-R0.1 + * * Rewrote database connection system, should fix any memory leaks from before + * * Reduced particle render distance from 512 to 192 (12 chunks), you won't notice a difference + * * Fixed missing command 'fixed' from '/pp help' list + * * Fixed missing command 'fixed' from tab completion */ package com.esophose.playerparticles; diff --git a/src/com/esophose/playerparticles/manager/MessageManager.java b/src/com/esophose/playerparticles/manager/MessageManager.java index add25f8..6bfc438 100644 --- a/src/com/esophose/playerparticles/manager/MessageManager.java +++ b/src/com/esophose/playerparticles/manager/MessageManager.java @@ -122,16 +122,12 @@ public class MessageManager { * @param config The config to pull the message from */ protected void setMessage(FileConfiguration config) { - try { - String messageFromConfig = config.getString(configLocation); - if (messageFromConfig == null || messageFromConfig.length() == 0) { - messageFromConfig = "&cMissing message in config.yml. Contact a server administrator."; - PlayerParticles.getPlugin().getLogger().warning("Missing message in config.yml: " + this.configLocation); - } - this.message = ChatColor.translateAlternateColorCodes('&', messageFromConfig); - } catch (Exception ex) { - System.out.println(this.name()); + String messageFromConfig = config.getString(configLocation); + if (messageFromConfig == null || messageFromConfig.length() == 0) { + messageFromConfig = "&cMissing message in config.yml. Contact a server administrator."; + PlayerParticles.getPlugin().getLogger().warning("Missing message in config.yml: " + this.configLocation); } + this.message = ChatColor.translateAlternateColorCodes('&', messageFromConfig); } /** diff --git a/src/com/esophose/playerparticles/manager/PermissionManager.java b/src/com/esophose/playerparticles/manager/PermissionManager.java index 3532c98..638d605 100644 --- a/src/com/esophose/playerparticles/manager/PermissionManager.java +++ b/src/com/esophose/playerparticles/manager/PermissionManager.java @@ -85,7 +85,7 @@ public class PermissionManager { * @return True if the player has permission */ public static boolean canUseForceReset(Player player) { - return player.hasPermission("playerparticles.*") || player.hasPermission("playerparticles.forcereset"); + return player.hasPermission("playerparticles.forcereset"); } /** @@ -98,15 +98,4 @@ public class PermissionManager { return player.hasPermission("playerparticles.*") || player.hasPermission("playerparticles.fixed"); } - /** - * Checks if a player has permission to open the GUI - * Access is restricted if they have the following permission - * - * @param player The player to check the permission for - * @return False if the player's access to the GUI is revoked - */ - public static boolean canUseGui(Player player) { - return !player.hasPermission("playerparticles.gui.revoke"); - } - } diff --git a/src/com/esophose/playerparticles/styles/DefaultStyles.java b/src/com/esophose/playerparticles/styles/DefaultStyles.java index bf49d6d..0a69637 100644 --- a/src/com/esophose/playerparticles/styles/DefaultStyles.java +++ b/src/com/esophose/playerparticles/styles/DefaultStyles.java @@ -2,6 +2,8 @@ package com.esophose.playerparticles.styles; import org.bukkit.Bukkit; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; import com.esophose.playerparticles.PlayerParticles; import com.esophose.playerparticles.styles.api.ParticleStyle; @@ -27,6 +29,11 @@ public class DefaultStyles { public static final ParticleStyle THICK = new ParticleStyleThick(); public static final ParticleStyle WINGS = new ParticleStyleWings(); public static final ParticleStyle SPHERE = new ParticleStyleSphere(); + public static final ParticleStyle SWORDS = new ParticleStyleSwords(); + public static final ParticleStyle HURT = new ParticleStyleHurt(); + public static final ParticleStyle BLOCKPLACE = new ParticleStyleBlockPlace(); + public static final ParticleStyle BLOCKBREAK = new ParticleStyleBlockBreak(); + public static final ParticleStyle BLOCKEDIT = new ParticleStyleBlockEdit(); /** * Registers all the default styles to the ParticleStyleManager @@ -47,9 +54,21 @@ public class DefaultStyles { ParticleStyleManager.registerStyle(THICK); ParticleStyleManager.registerStyle(WINGS); ParticleStyleManager.registerStyle(SPHERE); - - Bukkit.getPluginManager().registerEvents((Listener) MOVE, PlayerParticles.getPlugin()); - Bukkit.getPluginManager().registerEvents((Listener) ARROWS, PlayerParticles.getPlugin()); + ParticleStyleManager.registerCustomHandledStyle(SWORDS); + ParticleStyleManager.registerCustomHandledStyle(HURT); + ParticleStyleManager.registerCustomHandledStyle(BLOCKPLACE); + ParticleStyleManager.registerCustomHandledStyle(BLOCKBREAK); + ParticleStyleManager.registerCustomHandledStyle(BLOCKEDIT); + + PluginManager manager = Bukkit.getPluginManager(); + Plugin playerParticles = PlayerParticles.getPlugin(); + manager.registerEvents((Listener) MOVE, playerParticles); + manager.registerEvents((Listener) ARROWS, playerParticles); + manager.registerEvents((Listener) SWORDS, playerParticles); + manager.registerEvents((Listener) HURT, playerParticles); + manager.registerEvents((Listener) BLOCKPLACE, playerParticles); + manager.registerEvents((Listener) BLOCKBREAK, playerParticles); + manager.registerEvents((Listener) BLOCKEDIT, playerParticles); } } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleBlockBreak.java b/src/com/esophose/playerparticles/styles/ParticleStyleBlockBreak.java new file mode 100644 index 0000000..e0e9d18 --- /dev/null +++ b/src/com/esophose/playerparticles/styles/ParticleStyleBlockBreak.java @@ -0,0 +1,53 @@ +package com.esophose.playerparticles.styles; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; + +import com.esophose.playerparticles.PPlayer; +import com.esophose.playerparticles.manager.ConfigManager; +import com.esophose.playerparticles.manager.ParticleManager; +import com.esophose.playerparticles.manager.PermissionManager; +import com.esophose.playerparticles.styles.api.PParticle; +import com.esophose.playerparticles.styles.api.ParticleStyle; + +public class ParticleStyleBlockBreak implements ParticleStyle, Listener { + + public PParticle[] getParticles(PPlayer pplayer, Location location) { + 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)); + + return particles.toArray(new PParticle[particles.size()]); + } + + public void updateTimers() { + + } + + public String getName() { + return "blockbreak"; + } + + public boolean canBeFixed() { + return false; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId()); + if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKBREAK && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKBREAK)) { + Location loc = event.getBlock().getLocation(); + ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKBREAK.getParticles(pplayer, loc)); + } + } + +} diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleBlockEdit.java b/src/com/esophose/playerparticles/styles/ParticleStyleBlockEdit.java new file mode 100644 index 0000000..b2af3a0 --- /dev/null +++ b/src/com/esophose/playerparticles/styles/ParticleStyleBlockEdit.java @@ -0,0 +1,56 @@ +package com.esophose.playerparticles.styles; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; + +import com.esophose.playerparticles.PPlayer; +import com.esophose.playerparticles.manager.ConfigManager; +import com.esophose.playerparticles.manager.ParticleManager; +import com.esophose.playerparticles.manager.PermissionManager; +import com.esophose.playerparticles.styles.api.PParticle; +import com.esophose.playerparticles.styles.api.ParticleStyle; + +public class ParticleStyleBlockEdit implements ParticleStyle, Listener { + + public PParticle[] getParticles(PPlayer pplayer, Location location) { + return new PParticle[0]; // Particles are taken from DefaultStyles.BLOCKPLACE or DefaultStyles.BLOCKBREAK + } + + public void updateTimers() { + + } + + public String getName() { + return "blockedit"; + } + + public boolean canBeFixed() { + return false; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId()); + if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKEDIT && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKEDIT)) { + Location loc = event.getBlock().getLocation(); + ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKBREAK.getParticles(pplayer, loc)); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onBlockPlace(BlockPlaceEvent event) { + Player player = event.getPlayer(); + PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId()); + if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKEDIT && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKEDIT)) { + Location loc = event.getBlockPlaced().getLocation(); + ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKPLACE.getParticles(pplayer, loc)); + } + } + +} diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleBlockPlace.java b/src/com/esophose/playerparticles/styles/ParticleStyleBlockPlace.java new file mode 100644 index 0000000..1b78253 --- /dev/null +++ b/src/com/esophose/playerparticles/styles/ParticleStyleBlockPlace.java @@ -0,0 +1,53 @@ +package com.esophose.playerparticles.styles; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; + +import com.esophose.playerparticles.PPlayer; +import com.esophose.playerparticles.manager.ConfigManager; +import com.esophose.playerparticles.manager.ParticleManager; +import com.esophose.playerparticles.manager.PermissionManager; +import com.esophose.playerparticles.styles.api.PParticle; +import com.esophose.playerparticles.styles.api.ParticleStyle; + +public class ParticleStyleBlockPlace implements ParticleStyle, Listener { + + public PParticle[] getParticles(PPlayer pplayer, Location location) { + 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)); + + return particles.toArray(new PParticle[particles.size()]); + } + + public void updateTimers() { + + } + + public String getName() { + return "blockplace"; + } + + public boolean canBeFixed() { + return false; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onBlockPlace(BlockPlaceEvent event) { + Player player = event.getPlayer(); + PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId()); + if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKPLACE && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKPLACE)) { + Location loc = event.getBlockPlaced().getLocation(); + ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKPLACE.getParticles(pplayer, loc)); + } + } + +} diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleHurt.java b/src/com/esophose/playerparticles/styles/ParticleStyleHurt.java new file mode 100644 index 0000000..678cb71 --- /dev/null +++ b/src/com/esophose/playerparticles/styles/ParticleStyleHurt.java @@ -0,0 +1,55 @@ +package com.esophose.playerparticles.styles; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; + +import com.esophose.playerparticles.PPlayer; +import com.esophose.playerparticles.manager.ConfigManager; +import com.esophose.playerparticles.manager.ParticleManager; +import com.esophose.playerparticles.manager.PermissionManager; +import com.esophose.playerparticles.styles.api.PParticle; +import com.esophose.playerparticles.styles.api.ParticleStyle; + +public class ParticleStyleHurt implements ParticleStyle, Listener { + + public PParticle[] getParticles(PPlayer pplayer, Location location) { + PParticle[] baseParticles = DefaultStyles.THICK.getParticles(pplayer, location); + + int multiplyingFactor = 3; // Uses the same logic as ParticleStyleThick except multiplies the resulting particles by 3x + PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor]; + for (int i = 0; i < baseParticles.length * multiplyingFactor; i++) { + particles[i] = baseParticles[i % baseParticles.length]; + } + + return particles; + } + + public void updateTimers() { + + } + + public String getName() { + return "hurt"; + } + + public boolean canBeFixed() { + return false; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onEntityDamage(EntityDamageEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId()); + if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.HURT && PermissionManager.hasStylePermission(player, DefaultStyles.HURT)) { + Location loc = player.getLocation().clone().add(0, 1, 0); + ParticleManager.displayParticles(pplayer, DefaultStyles.HURT.getParticles(pplayer, loc)); + } + } + } + +} \ No newline at end of file diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleMove.java b/src/com/esophose/playerparticles/styles/ParticleStyleMove.java index c833c07..21d9548 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleMove.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleMove.java @@ -2,6 +2,7 @@ package com.esophose.playerparticles.styles; import org.bukkit.Location; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; @@ -9,19 +10,28 @@ import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.manager.ConfigManager; import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.PermissionManager; +import com.esophose.playerparticles.styles.api.PParticle; +import com.esophose.playerparticles.styles.api.ParticleStyle; -public class ParticleStyleMove extends ParticleStyleNone implements Listener { +public class ParticleStyleMove implements ParticleStyle, Listener { + + public PParticle[] getParticles(PPlayer pplayer, Location location) { + return DefaultStyles.NONE.getParticles(pplayer, location); + } + + public void updateTimers() { + + } public String getName() { return "move"; } - /** - * The event used to update the move style - * - * @param e The event - */ - @EventHandler + public boolean canBeFixed() { + return false; + } + + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerMove(PlayerMoveEvent e) { PPlayer pplayer = ConfigManager.getInstance().getPPlayer(e.getPlayer().getUniqueId()); if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.MOVE) { @@ -33,8 +43,4 @@ public class ParticleStyleMove extends ParticleStyleNone implements Listener { } } - public boolean canBeFixed() { - return false; - } - } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleSwords.java b/src/com/esophose/playerparticles/styles/ParticleStyleSwords.java new file mode 100644 index 0000000..bd274ca --- /dev/null +++ b/src/com/esophose/playerparticles/styles/ParticleStyleSwords.java @@ -0,0 +1,70 @@ +package com.esophose.playerparticles.styles; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +import com.esophose.playerparticles.PPlayer; +import com.esophose.playerparticles.manager.ConfigManager; +import com.esophose.playerparticles.manager.ParticleManager; +import com.esophose.playerparticles.manager.PermissionManager; +import com.esophose.playerparticles.styles.api.PParticle; +import com.esophose.playerparticles.styles.api.ParticleStyle; + +public class ParticleStyleSwords implements ParticleStyle, Listener { + + private static final List SWORD_NAMES; + + static { + SWORD_NAMES = new ArrayList(); + SWORD_NAMES.addAll(Arrays.asList("WOOD_SWORD", "STONE_SWORD", "IRON_SWORD", "GOLD_SWORD", "DIAMOND_SWORD")); + } + + public PParticle[] getParticles(PPlayer pplayer, Location location) { + PParticle[] baseParticles = DefaultStyles.THICK.getParticles(pplayer, location); + + int multiplyingFactor = 3; // Uses the same logic as ParticleStyleThick except multiplies the resulting particles by 3x + PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor]; + for (int i = 0; i < baseParticles.length * multiplyingFactor; i++) { + particles[i] = baseParticles[i % baseParticles.length]; + } + + return particles; + } + + public void updateTimers() { + + } + + public String getName() { + return "swords"; + } + + public boolean canBeFixed() { + return false; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onEntityDamageEntity(EntityDamageByEntityEvent event) { + if (event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity) { + Player player = (Player) event.getDamager(); + LivingEntity entity = (LivingEntity) event.getEntity(); + PPlayer pplayer = ConfigManager.getInstance().getPPlayer(player.getUniqueId()); + if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.SWORDS && PermissionManager.hasStylePermission(player, DefaultStyles.SWORDS)) { + if (player.getInventory().getItemInMainHand() != null && SWORD_NAMES.contains(player.getInventory().getItemInMainHand().getType().name())) { + Location loc = entity.getLocation().clone().add(0, 1, 0); + ParticleManager.displayParticles(pplayer, DefaultStyles.SWORDS.getParticles(pplayer, loc)); + } + } + } + } + +} \ No newline at end of file diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleThick.java b/src/com/esophose/playerparticles/styles/ParticleStyleThick.java index 03bc18b..96657cc 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleThick.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleThick.java @@ -4,11 +4,12 @@ import org.bukkit.Location; import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.styles.api.PParticle; +import com.esophose.playerparticles.styles.api.ParticleStyle; -public class ParticleStyleThick extends ParticleStyleNone { +public class ParticleStyleThick implements ParticleStyle { public PParticle[] getParticles(PPlayer pplayer, Location location) { - PParticle[] baseParticles = super.getParticles(pplayer, location); + PParticle[] baseParticles = DefaultStyles.NONE.getParticles(pplayer, location); int multiplyingFactor = 15; // Uses the same logic as ParticleStyleNone except multiplies the resulting particles by 15x PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor]; @@ -26,5 +27,9 @@ public class ParticleStyleThick extends ParticleStyleNone { public String getName() { return "thick"; } + + public boolean canBeFixed() { + return true; + } } diff --git a/src/com/esophose/playerparticles/styles/ParticleStyleWings.java b/src/com/esophose/playerparticles/styles/ParticleStyleWings.java index de05319..696ff92 100644 --- a/src/com/esophose/playerparticles/styles/ParticleStyleWings.java +++ b/src/com/esophose/playerparticles/styles/ParticleStyleWings.java @@ -13,7 +13,7 @@ import com.esophose.playerparticles.util.VectorUtils; public class ParticleStyleWings implements ParticleStyle { - int spawnTimer = 0; // Spawn particles every 3 ticks + private int spawnTimer = 0; // Spawn particles every 3 ticks public PParticle[] getParticles(PPlayer pplayer, Location location) { List particles = new ArrayList(); diff --git a/src/com/esophose/playerparticles/styles/api/ParticleStyleManager.java b/src/com/esophose/playerparticles/styles/api/ParticleStyleManager.java index ead9d7a..57514a4 100644 --- a/src/com/esophose/playerparticles/styles/api/ParticleStyleManager.java +++ b/src/com/esophose/playerparticles/styles/api/ParticleStyleManager.java @@ -10,6 +10,8 @@ package com.esophose.playerparticles.styles.api; import java.util.ArrayList; +import com.esophose.playerparticles.PlayerParticles; + public class ParticleStyleManager { /** @@ -26,9 +28,9 @@ public class ParticleStyleManager { public static void registerStyle(ParticleStyle style) { for (ParticleStyle testAgainst : styles) { if (testAgainst.getName().replace("_", "").equalsIgnoreCase(style.getName())) { - throw new ParticleStyleAlreadyRegisteredException("Tried to register two styles with the same name!"); + PlayerParticles.getPlugin().getLogger().severe("Tried to register two styles with the same (or too similar) name: " + style.getName()); } else if (testAgainst.equals(style)) { - throw new ParticleStyleAlreadyRegisteredException("Tried to register the same style twice!"); + PlayerParticles.getPlugin().getLogger().severe("Tried to register the same style twice: " + style.getName()); } } styles.add(style); @@ -85,17 +87,4 @@ public class ParticleStyleManager { style.updateTimers(); } - /** - * The exception to throw if a style is already registered - */ - private static final class ParticleStyleAlreadyRegisteredException extends RuntimeException { - - private static final long serialVersionUID = -6116170395810178020L; - - private ParticleStyleAlreadyRegisteredException(String message) { - super(message); - } - - } - } diff --git a/src/config.yml b/src/config.yml index f6cb8d0..2f2c961 100644 --- a/src/config.yml +++ b/src/config.yml @@ -475,9 +475,8 @@ database-user-password: '' # icons to whatever block/item you want. # # # # Important Notes: # -# * If any of the block/item names are invalid it will notify you # -# in console and the icon in the GUI will be the barrier icon to # -# show that it failed to load. # +# * If any of the block/item names are invalid the icon in the GUI # +# will be the barrier icon to show that it failed to load. # # * Do NOT change the particle/style name # # * You MUST use the Spigot-given name for it to work. You can see # # all the Spigot-given names at the link below: # @@ -552,6 +551,11 @@ gui-icon: THICK: VINE WINGS: ELYTRA SPHERE: SNOW_BALL + SWORDS: IRON_SWORD + HURT: CACTUS + BLOCKPLACE: WOOD + BLOCKBREAK: IRON_PICKAXE + BLOCKEDIT: DISPENSER # That's everything! You reached the end of the configuration.