Linked GPowers and refactored FlairDoors

This commit is contained in:
alisolarflare 2016-11-05 07:59:35 -04:00
parent 48a30f8c7f
commit 0a01494c4a
6 changed files with 72 additions and 46 deletions

View file

@ -1,12 +1,9 @@
package alisolarflare.components.flairdoor.listeners; package alisolarflare.components.flairdoor.listeners;
import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -18,12 +15,9 @@ import org.bukkit.material.Wool;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class PortalListener implements Listener{ public class PortalListener implements Listener{
AbstractMap<String,Location> portalMap = new HashMap<String,Location>();
public static List<String> playersToBeFlaired = new ArrayList<String>(); public static List<String> playersToBeFlaired = new ArrayList<String>();
public JavaPlugin plugin; public JavaPlugin plugin;
//TODO: CREATE - LIST OF PORTALS (only x-z values)
public PortalListener(JavaPlugin plugin) { public PortalListener(JavaPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -95,47 +89,54 @@ public class PortalListener implements Listener{
player.sendMessage("Recolouring Player as..." + dyecolour.toString()); player.sendMessage("Recolouring Player as..." + dyecolour.toString());
String name = player.getName(); String name = player.getName();
player.sendMessage("name:" + name); player.sendMessage("name:" + name);
String tempName = "";
for(int i = 0; i < name.length(); i++){ for(int i = 0; i < name.length(); i++){
if (name.charAt(i) == '&'){ if (name.charAt(i) != '&'){
//TODO: Remove all &* symbols tempName += name.charAt(i);
name = name.substring(0, i) + name.substring(i + 1, name.length()); }else{
i++;
} }
} }
name = tempName;
player.sendMessage("Adjusted Name: " + name); player.sendMessage("Adjusted Name: " + name);
if(dyecolour == DyeColor.GRAY){ switch(dyecolour){
case GRAY:
player.sendMessage("Adding GRAY"); player.sendMessage("Adding GRAY");
player.setCustomName("&7" + name); name = "&7" + name;
break;
}else if(dyecolour == DyeColor.RED){ case RED:
player.sendMessage("Adding RED"); player.sendMessage("Adding RED");
player.setCustomName("&4" + name); name = "&4" + name;
break;
}else if(dyecolour == DyeColor.ORANGE){ case ORANGE:
player.sendMessage("Adding ORANGE"); player.sendMessage("Adding ORANGE");
player.setCustomName("&6" + name); name = "&6" + name;
break;
}else if(dyecolour == DyeColor.YELLOW){ case YELLOW:
player.sendMessage("Adding YELLOW"); player.sendMessage("Adding YELLOW");
player.setCustomName("&e" + name); name = "&e" + name;
break;
}else if(dyecolour == DyeColor.GREEN){ case LIME:
case GREEN:
player.sendMessage("Adding GREEN"); player.sendMessage("Adding GREEN");
player.setCustomName("&a" + name); name = "&a" + name;
break;
}else if(dyecolour == DyeColor.BLUE){ case CYAN:
case LIGHT_BLUE:
case BLUE:
player.sendMessage("Adding BLUE"); player.sendMessage("Adding BLUE");
player.setCustomName("&9" + name); name = "&9" + name;
break;
}else if(dyecolour == DyeColor.PURPLE){ case PURPLE:
player.sendMessage("Adding PURPLE"); player.sendMessage("Adding PURPLE");
player.setCustomName("&5" + name); name = "&5" + name;
break;
}else{ default:
player.sendMessage("ERROR, PORTAL HAS INVALID UNDER-BLOCK"); 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..."); player.sendMessage("Your name is now: " + player.getCustomName() +"! Removing you from playersToBeFlaired...");
playersToBeFlaired.remove(player.getName()); playersToBeFlaired.remove(player.getName());
} }

View file

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
public class GPowerMemory{ public class GPowerMemory{
public Map<UUID, poweredPlayer> poweredPlayerList = new HashMap<UUID, poweredPlayer>(); public Map<UUID, poweredPlayer> poweredPlayerList = new HashMap<UUID, poweredPlayer>();
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)); poweredPlayerList.put(player.getUniqueId(), new poweredPlayer(player.getUniqueId(), colour, true));
} }
public void PowerUpPlayer(Player player){ public void PowerUpPlayer(Player player){

View file

@ -4,6 +4,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.Module; import alisolarflare.Module;
import alisolarflare.components.gpowers.commands.GPower; import alisolarflare.components.gpowers.commands.GPower;
import alisolarflare.components.gpowers.commands.PowerDown;
import alisolarflare.components.gpowers.commands.PowerUp;
import alisolarflare.components.gpowers.listeners.gPowerListener; import alisolarflare.components.gpowers.listeners.gPowerListener;
public class GPowerModule extends Module { public class GPowerModule extends Module {
@ -12,6 +14,8 @@ public class GPowerModule extends Module {
public void register(JavaPlugin plugin) { public void register(JavaPlugin plugin) {
GPowerMemory gPowerMemory = new GPowerMemory(); GPowerMemory gPowerMemory = new GPowerMemory();
registerCommand(plugin, new GPower(gPowerMemory)); registerCommand(plugin, new GPower(gPowerMemory));
registerCommand(plugin, new PowerUp(gPowerMemory));
registerCommand(plugin, new PowerDown(gPowerMemory));
registerListener(plugin, new gPowerListener(plugin, gPowerMemory)); registerListener(plugin, new gPowerListener(plugin, gPowerMemory));
} }

View file

@ -3,6 +3,8 @@ package alisolarflare.components.gpowers.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.mysql.fabric.xmlrpc.base.Data;
import alisolarflare.components.gpowers.GPowerMemory; import alisolarflare.components.gpowers.GPowerMemory;
import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.chat.TBMCCommandBase;
@ -24,13 +26,12 @@ public class GPower extends TBMCCommandBase {
return false; return false;
} }
String colour; String colour;
player.sendMessage("Checking terms...");
if (args[0].startsWith("r") || args[0].startsWith("o") || args[0].startsWith("y") || args[0].startsWith("g") 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")) { || args[0].startsWith("b") || args[0].startsWith("p")) {
colour = args[0]; colour = args[0];
} else { } else {
player.sendMessage("Term Fail: COLOUR. Proper Usage to test G-Powers:"); player.sendMessage("error: colour. Proper Usage to configure G-Powers:");
player.sendMessage("/gpowertest [colour=red,orange,yellow,green,blue,purple] [active=true/false]"); player.sendMessage("/gpowertest [colour=red,orange,yellow,green,blue,purple,grey] [active=true/false]");
return false; return false;
} }
boolean isActive; boolean isActive;
@ -39,16 +40,14 @@ public class GPower extends TBMCCommandBase {
} else if (args[1].startsWith("f")) { } else if (args[1].startsWith("f")) {
isActive = false; isActive = false;
} else { } 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]"); player.sendMessage("/gpowertest [colour=red,orange,yellow,green,blue,purple] [active=true/false]");
return false; return false;
} }
player.sendMessage("Terms Vaild!"); player.sendMessage("Terms Vaild!");
if (isActive) { player.sendMessage("Saving Data: "+ player.getName() + "|" + colour + "|" + isActive);
gPowerMemory.PowerUpPlayer(player, colour); gPowerMemory.configurePlayer(player, colour, isActive);
} else {
gPowerMemory.PowerDownPlayer(player);
}
return false; return false;
} }

View file

@ -1,14 +1,25 @@
package alisolarflare.components.gpowers.commands; package alisolarflare.components.gpowers.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.gpowers.GPowerMemory;
import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.chat.TBMCCommandBase;
public class PowerDown extends TBMCCommandBase { public class PowerDown extends TBMCCommandBase {
private GPowerMemory gPowerMemory;
public PowerDown(GPowerMemory gPowerMemory) {
this.gPowerMemory = gPowerMemory;
}
@Override @Override
public boolean OnCommand(CommandSender arg0, String arg2, String[] arg3) { public boolean OnCommand(CommandSender sender, String label, String[] args) {
// TODO Auto-generated method stub 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; return false;
} }

View file

@ -1,14 +1,25 @@
package alisolarflare.components.gpowers.commands; package alisolarflare.components.gpowers.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import alisolarflare.components.gpowers.GPowerMemory;
import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.chat.TBMCCommandBase;
public class PowerUp extends TBMCCommandBase { public class PowerUp extends TBMCCommandBase {
private GPowerMemory gPowerMemory;
public PowerUp(GPowerMemory gPowerMemory) {
this.gPowerMemory = gPowerMemory;
}
@Override @Override
public boolean OnCommand(CommandSender sender, String label, String[] args) { 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; return false;
} }