From c517296a0a1d1b29325844fc8e1fa25c39a99249 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 28 Dec 2016 23:41:15 -0500 Subject: [PATCH 1/2] Started work on refactoring Gpowers --- .../components/gpower/ApplyPowerUp.java | 55 +++++++++++++++++++ .../components/gpower/GPowerComponent.java | 4 +- .../components/gpower/api/GPowerAPI.java | 8 ++- .../components/magic/MagicComponent.java | 8 ++- .../magic/tricks/CannonBowListener.java | 34 ++++++------ 5 files changed, 87 insertions(+), 22 deletions(-) create mode 100644 src/buttondevteam/alipresents/components/gpower/ApplyPowerUp.java diff --git a/src/buttondevteam/alipresents/components/gpower/ApplyPowerUp.java b/src/buttondevteam/alipresents/components/gpower/ApplyPowerUp.java new file mode 100644 index 0000000..52c6d93 --- /dev/null +++ b/src/buttondevteam/alipresents/components/gpower/ApplyPowerUp.java @@ -0,0 +1,55 @@ +package buttondevteam.alipresents.components.gpower; + +import org.bukkit.entity.Player; + +import buttondevteam.alipresents.architecture.commands.ModCommand; +import buttondevteam.alipresents.components.gpower.api.GPowerAPI; + +public class ApplyPowerUp extends ModCommand { + + @Override + public boolean OnCommand(Player player, String alias, String[] args) { + if (args.length > 1) //No one's online + return false; + + String playerArgument = args[0]; + + Player argPlayer = player.getServer().getPlayer(playerArgument); + + if (argPlayer == null) + { + + // Attempted player is not online + player.sendMessage(playerArgument + " is not online right now. Players online are: "); + player.sendMessage(player.getServer().getOnlinePlayers().toString()); + + if (args.length < 2){ + player.sendMessage("You may apply the effect " + args[1] + "to them"); + } + + } + if (args.length < 2){ + //recolour no colour + GPowerAPI.PowerUpPlayer(player); + return true; + }else{ + GPowerAPI.PowerUpPlayer(player); + //recolour with colour + return true; + } + + + } + @Override + public String[] GetHelpText(String string){ + return new String[]{ + "Usage: /"+GetCommandPath()+" ", + "Use this command to apply a gpower colour to players", + }; + } + @Override + public String GetCommandPath(){ + return "gpower applypowerup"; + } + +} diff --git a/src/buttondevteam/alipresents/components/gpower/GPowerComponent.java b/src/buttondevteam/alipresents/components/gpower/GPowerComponent.java index 1d85e84..7fda859 100644 --- a/src/buttondevteam/alipresents/components/gpower/GPowerComponent.java +++ b/src/buttondevteam/alipresents/components/gpower/GPowerComponent.java @@ -15,7 +15,9 @@ public class GPowerComponent extends Component { registerCommand(plugin, new Test()); registerCommand(plugin, new PowerUp()); registerCommand(plugin, new PowerDown()); - + + registerCommand(plugin, new ApplyPowerUp()); + registerCommand(plugin, new ApplyPowerDown()); registerListener(plugin, new EnchantingLoop(plugin)); } diff --git a/src/buttondevteam/alipresents/components/gpower/api/GPowerAPI.java b/src/buttondevteam/alipresents/components/gpower/api/GPowerAPI.java index 3596613..d497f69 100644 --- a/src/buttondevteam/alipresents/components/gpower/api/GPowerAPI.java +++ b/src/buttondevteam/alipresents/components/gpower/api/GPowerAPI.java @@ -18,6 +18,9 @@ public class GPowerAPI{ public static void addPlayer(Player player, String colour, boolean powerIsActive){ poweredPlayerList.put(player.getUniqueId(), new PoweredPlayer(player.getUniqueId(), colour, true)); } + public static void PowerUpPlayer(Player player, String colour){ + PowerUpPlayer(player); + } public static void PowerUpPlayer(Player player){ player.sendMessage("Powering up!"); if(poweredPlayerList.containsKey(player.getUniqueId())){ @@ -33,14 +36,15 @@ public class GPowerAPI{ } } - public static void PowerDownPlayer(Player player){ + public static boolean PowerDownPlayer(Player player){ player.sendMessage("Powering down!"); if (poweredPlayerList.containsKey(player.getUniqueId())){ player.sendMessage("Powered down!"); poweredPlayerList.get(player.getUniqueId()).isPowersActive = false; + return true; }else{ player.sendMessage("P down!"); - return; + return false; } } diff --git a/src/buttondevteam/alipresents/components/magic/MagicComponent.java b/src/buttondevteam/alipresents/components/magic/MagicComponent.java index 8aa4b27..444cc74 100644 --- a/src/buttondevteam/alipresents/components/magic/MagicComponent.java +++ b/src/buttondevteam/alipresents/components/magic/MagicComponent.java @@ -7,17 +7,19 @@ import buttondevteam.alipresents.components.magic.tricks.AliArrowListener; import buttondevteam.alipresents.components.magic.tricks.BoomBowDeathListener; import buttondevteam.alipresents.components.magic.tricks.BoomBowListener; import buttondevteam.alipresents.components.magic.tricks.CannonBowListener; -import buttondevteam.alipresents.components.magic.tricks.CannonBowSettings; public class MagicComponent extends Component{ @Override public void register(JavaPlugin plugin) { - registerCommand(plugin, new CannonBowSettings()); + //registerCommand(plugin, new CannonBowSettings()); registerListener(plugin, new AliArrowListener(plugin)); registerListener(plugin, new BoomBowDeathListener()); registerListener(plugin, new BoomBowListener(plugin)); - registerListener(plugin, new CannonBowListener(plugin)); + + CannonBowListener cbl = new CannonBowListener(plugin); + //cbl.loadSettings(plugin.getConfig()); + registerListener(plugin, cbl); } } diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java index cee7da0..ef321f3 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java @@ -56,23 +56,8 @@ public class CannonBowListener implements Listener { static FileConfiguration config; public CannonBowListener(JavaPlugin plugin){ config = plugin.getConfig(); - - if (config.isDouble(speedMultiplierPath)) - setSpeedMultiplier(config.getDouble(speedMultiplierPath)); - - if (config.isDouble(minForcePath)) - setMinforce(config.getDouble(minForcePath)); - - if (config.isInt(fuseTicksPath)) - setFuseticks(config.getInt(fuseTicksPath)); - - if (config.isDouble(recoilPath)) - setRecoil(config.getDouble(recoilPath)); - - if (config.isBoolean(isDestructivePath)) - setIsDestructive(config.getBoolean(isDestructivePath)); } - + @EventHandler public void onProjectileLaunch(EntityShootBowEvent event){ //Entity Sanitation @@ -247,4 +232,21 @@ public class CannonBowListener implements Listener { CannonBowListener.isDestructive = isDestructive; config.set(speedMultiplierPath, isDestructive); } + + public void loadSettings(FileConfiguration config){ + if (config.isDouble(speedMultiplierPath)) + setSpeedMultiplier(config.getDouble(speedMultiplierPath)); + + if (config.isDouble(minForcePath)) + setMinforce(config.getDouble(minForcePath)); + + if (config.isInt(fuseTicksPath)) + setFuseticks(config.getInt(fuseTicksPath)); + + if (config.isDouble(recoilPath)) + setRecoil(config.getDouble(recoilPath)); + + if (config.isBoolean(isDestructivePath)) + setIsDestructive(config.getBoolean(isDestructivePath)); + } } \ No newline at end of file From 50f5ccf9c145fa8a702db73dd5e9e24c38c16529 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Thu, 29 Dec 2016 20:45:28 -0500 Subject: [PATCH 2/2] Revert "Started work on refactoring Gpowers" This reverts commit c517296a0a1d1b29325844fc8e1fa25c39a99249. --- .../components/gpower/ApplyPowerUp.java | 55 ------------------- .../components/gpower/GPowerComponent.java | 4 +- .../components/gpower/api/GPowerAPI.java | 8 +-- .../components/magic/MagicComponent.java | 8 +-- .../magic/tricks/CannonBowListener.java | 34 ++++++------ 5 files changed, 22 insertions(+), 87 deletions(-) delete mode 100644 src/buttondevteam/alipresents/components/gpower/ApplyPowerUp.java diff --git a/src/buttondevteam/alipresents/components/gpower/ApplyPowerUp.java b/src/buttondevteam/alipresents/components/gpower/ApplyPowerUp.java deleted file mode 100644 index 52c6d93..0000000 --- a/src/buttondevteam/alipresents/components/gpower/ApplyPowerUp.java +++ /dev/null @@ -1,55 +0,0 @@ -package buttondevteam.alipresents.components.gpower; - -import org.bukkit.entity.Player; - -import buttondevteam.alipresents.architecture.commands.ModCommand; -import buttondevteam.alipresents.components.gpower.api.GPowerAPI; - -public class ApplyPowerUp extends ModCommand { - - @Override - public boolean OnCommand(Player player, String alias, String[] args) { - if (args.length > 1) //No one's online - return false; - - String playerArgument = args[0]; - - Player argPlayer = player.getServer().getPlayer(playerArgument); - - if (argPlayer == null) - { - - // Attempted player is not online - player.sendMessage(playerArgument + " is not online right now. Players online are: "); - player.sendMessage(player.getServer().getOnlinePlayers().toString()); - - if (args.length < 2){ - player.sendMessage("You may apply the effect " + args[1] + "to them"); - } - - } - if (args.length < 2){ - //recolour no colour - GPowerAPI.PowerUpPlayer(player); - return true; - }else{ - GPowerAPI.PowerUpPlayer(player); - //recolour with colour - return true; - } - - - } - @Override - public String[] GetHelpText(String string){ - return new String[]{ - "Usage: /"+GetCommandPath()+" ", - "Use this command to apply a gpower colour to players", - }; - } - @Override - public String GetCommandPath(){ - return "gpower applypowerup"; - } - -} diff --git a/src/buttondevteam/alipresents/components/gpower/GPowerComponent.java b/src/buttondevteam/alipresents/components/gpower/GPowerComponent.java index 7fda859..1d85e84 100644 --- a/src/buttondevteam/alipresents/components/gpower/GPowerComponent.java +++ b/src/buttondevteam/alipresents/components/gpower/GPowerComponent.java @@ -15,9 +15,7 @@ public class GPowerComponent extends Component { registerCommand(plugin, new Test()); registerCommand(plugin, new PowerUp()); registerCommand(plugin, new PowerDown()); - - registerCommand(plugin, new ApplyPowerUp()); - registerCommand(plugin, new ApplyPowerDown()); + registerListener(plugin, new EnchantingLoop(plugin)); } diff --git a/src/buttondevteam/alipresents/components/gpower/api/GPowerAPI.java b/src/buttondevteam/alipresents/components/gpower/api/GPowerAPI.java index d497f69..3596613 100644 --- a/src/buttondevteam/alipresents/components/gpower/api/GPowerAPI.java +++ b/src/buttondevteam/alipresents/components/gpower/api/GPowerAPI.java @@ -18,9 +18,6 @@ public class GPowerAPI{ public static void addPlayer(Player player, String colour, boolean powerIsActive){ poweredPlayerList.put(player.getUniqueId(), new PoweredPlayer(player.getUniqueId(), colour, true)); } - public static void PowerUpPlayer(Player player, String colour){ - PowerUpPlayer(player); - } public static void PowerUpPlayer(Player player){ player.sendMessage("Powering up!"); if(poweredPlayerList.containsKey(player.getUniqueId())){ @@ -36,15 +33,14 @@ public class GPowerAPI{ } } - public static boolean PowerDownPlayer(Player player){ + public static void PowerDownPlayer(Player player){ player.sendMessage("Powering down!"); if (poweredPlayerList.containsKey(player.getUniqueId())){ player.sendMessage("Powered down!"); poweredPlayerList.get(player.getUniqueId()).isPowersActive = false; - return true; }else{ player.sendMessage("P down!"); - return false; + return; } } diff --git a/src/buttondevteam/alipresents/components/magic/MagicComponent.java b/src/buttondevteam/alipresents/components/magic/MagicComponent.java index 444cc74..8aa4b27 100644 --- a/src/buttondevteam/alipresents/components/magic/MagicComponent.java +++ b/src/buttondevteam/alipresents/components/magic/MagicComponent.java @@ -7,19 +7,17 @@ import buttondevteam.alipresents.components.magic.tricks.AliArrowListener; import buttondevteam.alipresents.components.magic.tricks.BoomBowDeathListener; import buttondevteam.alipresents.components.magic.tricks.BoomBowListener; import buttondevteam.alipresents.components.magic.tricks.CannonBowListener; +import buttondevteam.alipresents.components.magic.tricks.CannonBowSettings; public class MagicComponent extends Component{ @Override public void register(JavaPlugin plugin) { - //registerCommand(plugin, new CannonBowSettings()); + registerCommand(plugin, new CannonBowSettings()); registerListener(plugin, new AliArrowListener(plugin)); registerListener(plugin, new BoomBowDeathListener()); registerListener(plugin, new BoomBowListener(plugin)); - - CannonBowListener cbl = new CannonBowListener(plugin); - //cbl.loadSettings(plugin.getConfig()); - registerListener(plugin, cbl); + registerListener(plugin, new CannonBowListener(plugin)); } } diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java index ef321f3..cee7da0 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java @@ -56,8 +56,23 @@ public class CannonBowListener implements Listener { static FileConfiguration config; public CannonBowListener(JavaPlugin plugin){ config = plugin.getConfig(); + + if (config.isDouble(speedMultiplierPath)) + setSpeedMultiplier(config.getDouble(speedMultiplierPath)); + + if (config.isDouble(minForcePath)) + setMinforce(config.getDouble(minForcePath)); + + if (config.isInt(fuseTicksPath)) + setFuseticks(config.getInt(fuseTicksPath)); + + if (config.isDouble(recoilPath)) + setRecoil(config.getDouble(recoilPath)); + + if (config.isBoolean(isDestructivePath)) + setIsDestructive(config.getBoolean(isDestructivePath)); } - + @EventHandler public void onProjectileLaunch(EntityShootBowEvent event){ //Entity Sanitation @@ -232,21 +247,4 @@ public class CannonBowListener implements Listener { CannonBowListener.isDestructive = isDestructive; config.set(speedMultiplierPath, isDestructive); } - - public void loadSettings(FileConfiguration config){ - if (config.isDouble(speedMultiplierPath)) - setSpeedMultiplier(config.getDouble(speedMultiplierPath)); - - if (config.isDouble(minForcePath)) - setMinforce(config.getDouble(minForcePath)); - - if (config.isInt(fuseTicksPath)) - setFuseticks(config.getInt(fuseTicksPath)); - - if (config.isDouble(recoilPath)) - setRecoil(config.getDouble(recoilPath)); - - if (config.isBoolean(isDestructivePath)) - setIsDestructive(config.getBoolean(isDestructivePath)); - } } \ No newline at end of file