From 7bee64db7df3276c7537002b5e2b8c562ea9464d Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Fri, 2 Dec 2016 09:52:15 -0500 Subject: [PATCH] added a SHIIIIT ton of colours (and made the flaircolourAPI) --- .../flairdoor/FlairColouringAPI.java | 82 +++++++++++++++++++ .../flairdoor/listeners/PortalListener.java | 70 ++-------------- 2 files changed, 87 insertions(+), 65 deletions(-) create mode 100644 src/alisolarflare/components/flairdoor/FlairColouringAPI.java diff --git a/src/alisolarflare/components/flairdoor/FlairColouringAPI.java b/src/alisolarflare/components/flairdoor/FlairColouringAPI.java new file mode 100644 index 0000000..2163e12 --- /dev/null +++ b/src/alisolarflare/components/flairdoor/FlairColouringAPI.java @@ -0,0 +1,82 @@ +package alisolarflare.components.flairdoor; + +import org.bukkit.DyeColor; + +import com.earth2me.essentials.User; + +public class FlairColouringAPI { + + public static void recolourPlayer(User user, DyeColor dyecolour){ + String name = user._getNickname(); + String sanitizedName = ""; + for(int i = 0; i < name.length(); i++){ + if (name.charAt(i) != '§'){ + sanitizedName += name.charAt(i); + }else{ + i++; + } + } + + String colourChanger = ""; + + switch(dyecolour){ + case WHITE: + colourChanger = "§f"; + break; + case SILVER: + colourChanger = "§7"; + break; + case GRAY: + colourChanger = "§8"; + break; + case BLACK: + colourChanger = "§0"; + break; + case PINK: + colourChanger = "§d"; + break; + case RED: + colourChanger = "§c"; + break; + case ORANGE: + colourChanger = "§6"; + break; + case YELLOW: + colourChanger = "§e"; + break; + case LIME: + colourChanger = "§a"; + break; + case GREEN: + colourChanger = "§2"; + break; + case LIGHT_BLUE: + colourChanger = "&b"; + break; + case CYAN: + colourChanger = "§3"; + break; + case BLUE: + colourChanger = "§9"; + break; + case PURPLE: + colourChanger = "§5"; + break; + case MAGENTA: + colourChanger = "§d"; + break; + case BROWN: + colourChanger = "§4"; //Technically a dark red + break; + default: + colourChanger = "§m"; + break; + } + + String newName = colourChanger + sanitizedName; + user.setNickname(newName); + + user.sendMessage("Adding the colour " + colourChanger + dyecolour.name() + "§f!"); + user.sendMessage("Your name is now: " + user.getNickname() +"!"); + } +} diff --git a/src/alisolarflare/components/flairdoor/listeners/PortalListener.java b/src/alisolarflare/components/flairdoor/listeners/PortalListener.java index 9d85a62..82f8ba5 100644 --- a/src/alisolarflare/components/flairdoor/listeners/PortalListener.java +++ b/src/alisolarflare/components/flairdoor/listeners/PortalListener.java @@ -12,8 +12,8 @@ import org.bukkit.material.Wool; import org.bukkit.plugin.java.JavaPlugin; import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.User; +import alisolarflare.components.flairdoor.FlairColouringAPI; import alisolarflare.components.flairdoor.FlairDoorComponent; public class PortalListener implements Listener{ @@ -51,7 +51,8 @@ public class PortalListener implements Listener{ Block BottomBlock = player.getWorld().getBlockAt(x,y-4,z); //Block under middle block if(HigherBlock.getType() == Material.STONE){ - recolourPlayer(player, DyeColor.GRAY); + FlairColouringAPI.recolourPlayer(essentials.getUser(player), DyeColor.GRAY); + component.playersToBeFlaired.remove(player.getName()); return; } @@ -66,69 +67,8 @@ public class PortalListener implements Listener{ return; } - recolourPlayer(player, woolColour); - - } - public void recolourPlayer(Player player, DyeColor dyecolour){ - User user = essentials.getUser(player); - - String name = user._getNickname(); - String sanitizedName = ""; - for(int i = 0; i < name.length(); i++){ - if (name.charAt(i) != '§'){ - sanitizedName += name.charAt(i); - }else{ - i++; - } - } - - String colourChanger = ""; - - switch(dyecolour){ - case GRAY: - colourChanger = "§7"; - break; - case RED: - colourChanger = "§4"; - break; - case ORANGE: - colourChanger = "§6"; - break; - case YELLOW: - colourChanger = "§e"; - break; - case LIME: - colourChanger = "§a"; - break; - case GREEN: - colourChanger = "§a"; - break; - case CYAN: - colourChanger = "§9"; - break; - case LIGHT_BLUE: - colourChanger = "§9"; - break; - case BLUE: - colourChanger = "§9"; - break; - case PURPLE: - colourChanger = "§5"; - break; - case WHITE: - colourChanger = "§f"; - break; - default: - player.sendMessage("ERROR, PORTAL HAS INVALID UNDER-BLOCK"); - break; - } - - String newName = colourChanger + sanitizedName; - user.setNickname(newName); - - player.sendMessage("Adding the colour " + colourChanger + dyecolour.name() + "§f!"); - player.sendMessage("Your name is now: " + user.getNickname() +"!"); - + FlairColouringAPI.recolourPlayer(essentials.getUser(player), woolColour); component.playersToBeFlaired.remove(player.getName()); + } }