added a SHIIIIT ton of colours (and made the flaircolourAPI)

This commit is contained in:
alisolarflare 2016-12-02 09:52:15 -05:00
parent 913c430a11
commit 7bee64db7d
2 changed files with 87 additions and 65 deletions

View file

@ -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() +"!");
}
}

View file

@ -12,8 +12,8 @@ import org.bukkit.material.Wool;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.earth2me.essentials.Essentials; import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import alisolarflare.components.flairdoor.FlairColouringAPI;
import alisolarflare.components.flairdoor.FlairDoorComponent; import alisolarflare.components.flairdoor.FlairDoorComponent;
public class PortalListener implements Listener{ 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 Block BottomBlock = player.getWorld().getBlockAt(x,y-4,z); //Block under middle block
if(HigherBlock.getType() == Material.STONE){ if(HigherBlock.getType() == Material.STONE){
recolourPlayer(player, DyeColor.GRAY); FlairColouringAPI.recolourPlayer(essentials.getUser(player), DyeColor.GRAY);
component.playersToBeFlaired.remove(player.getName());
return; return;
} }
@ -66,69 +67,8 @@ public class PortalListener implements Listener{
return; return;
} }
recolourPlayer(player, woolColour); FlairColouringAPI.recolourPlayer(essentials.getUser(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() +"!");
component.playersToBeFlaired.remove(player.getName()); component.playersToBeFlaired.remove(player.getName());
} }
} }