From 0a01494c4ab55b29cd4aaa4c134a33fe082228f9 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sat, 5 Nov 2016 07:59:35 -0400 Subject: [PATCH] Linked GPowers and refactored FlairDoors --- .../flairdoor/listeners/PortalListener.java | 67 ++++++++++--------- .../components/gpowers/GPowerMemory.java | 2 +- .../components/gpowers/GPowerModule.java | 4 ++ .../components/gpowers/commands/GPower.java | 17 +++-- .../gpowers/commands/PowerDown.java | 15 ++++- .../components/gpowers/commands/PowerUp.java | 13 +++- 6 files changed, 72 insertions(+), 46 deletions(-) diff --git a/src/alisolarflare/components/flairdoor/listeners/PortalListener.java b/src/alisolarflare/components/flairdoor/listeners/PortalListener.java index a41d3bb..a905dbd 100644 --- a/src/alisolarflare/components/flairdoor/listeners/PortalListener.java +++ b/src/alisolarflare/components/flairdoor/listeners/PortalListener.java @@ -1,12 +1,9 @@ package alisolarflare.components.flairdoor.listeners; -import java.util.AbstractMap; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import org.bukkit.DyeColor; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -18,12 +15,9 @@ import org.bukkit.material.Wool; import org.bukkit.plugin.java.JavaPlugin; public class PortalListener implements Listener{ - AbstractMap portalMap = new HashMap(); public static List playersToBeFlaired = new ArrayList(); public JavaPlugin plugin; - //TODO: CREATE - LIST OF PORTALS (only x-z values) - public PortalListener(JavaPlugin plugin) { this.plugin = plugin; @@ -95,47 +89,54 @@ public class PortalListener implements Listener{ player.sendMessage("Recolouring Player as..." + dyecolour.toString()); String name = player.getName(); player.sendMessage("name:" + name); + String tempName = ""; for(int i = 0; i < name.length(); i++){ - if (name.charAt(i) == '&'){ - //TODO: Remove all &* symbols - name = name.substring(0, i) + name.substring(i + 1, name.length()); - + if (name.charAt(i) != '&'){ + tempName += name.charAt(i); + }else{ + i++; } } + name = tempName; player.sendMessage("Adjusted Name: " + name); - if(dyecolour == DyeColor.GRAY){ + switch(dyecolour){ + case GRAY: player.sendMessage("Adding GRAY"); - player.setCustomName("&7" + name); - - }else if(dyecolour == DyeColor.RED){ + name = "&7" + name; + break; + case RED: player.sendMessage("Adding RED"); - player.setCustomName("&4" + name); - - }else if(dyecolour == DyeColor.ORANGE){ + name = "&4" + name; + break; + case ORANGE: player.sendMessage("Adding ORANGE"); - player.setCustomName("&6" + name); - - }else if(dyecolour == DyeColor.YELLOW){ + name = "&6" + name; + break; + case YELLOW: player.sendMessage("Adding YELLOW"); - player.setCustomName("&e" + name); - - }else if(dyecolour == DyeColor.GREEN){ + name = "&e" + name; + break; + case LIME: + case GREEN: player.sendMessage("Adding GREEN"); - player.setCustomName("&a" + name); - - }else if(dyecolour == DyeColor.BLUE){ + name = "&a" + name; + break; + case CYAN: + case LIGHT_BLUE: + case BLUE: player.sendMessage("Adding BLUE"); - player.setCustomName("&9" + name); - - }else if(dyecolour == DyeColor.PURPLE){ + name = "&9" + name; + break; + case PURPLE: player.sendMessage("Adding PURPLE"); - player.setCustomName("&5" + name); - - }else{ + name = "&5" + name; + break; + default: player.sendMessage("ERROR, PORTAL HAS INVALID UNDER-BLOCK"); - return; + break; } + player.setCustomName(name); player.sendMessage("Your name is now: " + player.getCustomName() +"! Removing you from playersToBeFlaired..."); playersToBeFlaired.remove(player.getName()); } diff --git a/src/alisolarflare/components/gpowers/GPowerMemory.java b/src/alisolarflare/components/gpowers/GPowerMemory.java index 5a99b16..0dda7b9 100644 --- a/src/alisolarflare/components/gpowers/GPowerMemory.java +++ b/src/alisolarflare/components/gpowers/GPowerMemory.java @@ -9,7 +9,7 @@ import org.bukkit.entity.Player; public class GPowerMemory{ public Map poweredPlayerList = new HashMap(); - public void PowerUpPlayer(Player player, String colour){ + public void configurePlayer(Player player, String colour, boolean powerIsActive){ poweredPlayerList.put(player.getUniqueId(), new poweredPlayer(player.getUniqueId(), colour, true)); } public void PowerUpPlayer(Player player){ diff --git a/src/alisolarflare/components/gpowers/GPowerModule.java b/src/alisolarflare/components/gpowers/GPowerModule.java index c3c4a53..3148ee0 100644 --- a/src/alisolarflare/components/gpowers/GPowerModule.java +++ b/src/alisolarflare/components/gpowers/GPowerModule.java @@ -4,6 +4,8 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.Module; import alisolarflare.components.gpowers.commands.GPower; +import alisolarflare.components.gpowers.commands.PowerDown; +import alisolarflare.components.gpowers.commands.PowerUp; import alisolarflare.components.gpowers.listeners.gPowerListener; public class GPowerModule extends Module { @@ -12,6 +14,8 @@ public class GPowerModule extends Module { public void register(JavaPlugin plugin) { GPowerMemory gPowerMemory = new GPowerMemory(); registerCommand(plugin, new GPower(gPowerMemory)); + registerCommand(plugin, new PowerUp(gPowerMemory)); + registerCommand(plugin, new PowerDown(gPowerMemory)); registerListener(plugin, new gPowerListener(plugin, gPowerMemory)); } diff --git a/src/alisolarflare/components/gpowers/commands/GPower.java b/src/alisolarflare/components/gpowers/commands/GPower.java index 6c2fcd9..4b68ff0 100644 --- a/src/alisolarflare/components/gpowers/commands/GPower.java +++ b/src/alisolarflare/components/gpowers/commands/GPower.java @@ -3,6 +3,8 @@ package alisolarflare.components.gpowers.commands; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import com.mysql.fabric.xmlrpc.base.Data; + import alisolarflare.components.gpowers.GPowerMemory; import buttondevteam.lib.chat.TBMCCommandBase; @@ -24,13 +26,12 @@ public class GPower extends TBMCCommandBase { return false; } String colour; - player.sendMessage("Checking terms..."); if (args[0].startsWith("r") || args[0].startsWith("o") || args[0].startsWith("y") || args[0].startsWith("g") || args[0].startsWith("b") || args[0].startsWith("p")) { colour = args[0]; } else { - player.sendMessage("Term Fail: COLOUR. Proper Usage to test G-Powers:"); - player.sendMessage("/gpowertest [colour=red,orange,yellow,green,blue,purple] [active=true/false]"); + player.sendMessage("error: colour. Proper Usage to configure G-Powers:"); + player.sendMessage("/gpowertest [colour=red,orange,yellow,green,blue,purple,grey] [active=true/false]"); return false; } boolean isActive; @@ -39,16 +40,14 @@ public class GPower extends TBMCCommandBase { } else if (args[1].startsWith("f")) { isActive = false; } else { - player.sendMessage("Term Fail: ACTIVE. Proper Usage to test G-Powers:"); + player.sendMessage("error: active. Proper Usage to configure G-Powers:"); player.sendMessage("/gpowertest [colour=red,orange,yellow,green,blue,purple] [active=true/false]"); return false; } player.sendMessage("Terms Vaild!"); - if (isActive) { - gPowerMemory.PowerUpPlayer(player, colour); - } else { - gPowerMemory.PowerDownPlayer(player); - } + player.sendMessage("Saving Data: "+ player.getName() + "|" + colour + "|" + isActive); + gPowerMemory.configurePlayer(player, colour, isActive); + return false; } diff --git a/src/alisolarflare/components/gpowers/commands/PowerDown.java b/src/alisolarflare/components/gpowers/commands/PowerDown.java index d94c407..8f3467b 100644 --- a/src/alisolarflare/components/gpowers/commands/PowerDown.java +++ b/src/alisolarflare/components/gpowers/commands/PowerDown.java @@ -1,14 +1,25 @@ package alisolarflare.components.gpowers.commands; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import alisolarflare.components.gpowers.GPowerMemory; import buttondevteam.lib.chat.TBMCCommandBase; public class PowerDown extends TBMCCommandBase { + private GPowerMemory gPowerMemory; + + public PowerDown(GPowerMemory gPowerMemory) { + this.gPowerMemory = gPowerMemory; + } + @Override - public boolean OnCommand(CommandSender arg0, String arg2, String[] arg3) { - // TODO Auto-generated method stub + public boolean OnCommand(CommandSender sender, String label, String[] args) { + if (!(sender instanceof Player)) + sender.sendMessage("You must be a player to use this command! Contact dev/ali if you think this is wrong"); + Player player = (Player) sender; + gPowerMemory.PowerDownPlayer(player); return false; } diff --git a/src/alisolarflare/components/gpowers/commands/PowerUp.java b/src/alisolarflare/components/gpowers/commands/PowerUp.java index 4392bbe..2e50db8 100644 --- a/src/alisolarflare/components/gpowers/commands/PowerUp.java +++ b/src/alisolarflare/components/gpowers/commands/PowerUp.java @@ -1,14 +1,25 @@ package alisolarflare.components.gpowers.commands; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import alisolarflare.components.gpowers.GPowerMemory; import buttondevteam.lib.chat.TBMCCommandBase; public class PowerUp extends TBMCCommandBase { + private GPowerMemory gPowerMemory; + + public PowerUp(GPowerMemory gPowerMemory) { + this.gPowerMemory = gPowerMemory; + } + @Override public boolean OnCommand(CommandSender sender, String label, String[] args) { - // gPowerMemory.PowerUpPlayer(player, colour); + if (!(sender instanceof Player)) + sender.sendMessage("You must be a player to use this command! Contact a dev/ali if you think this is wrong"); + Player player = (Player) sender; + gPowerMemory.PowerUpPlayer(player); return false; }