Cleaned up PortalListener code
This commit is contained in:
parent
70d8f93597
commit
cf4bf48fb2
2 changed files with 46 additions and 52 deletions
|
@ -11,7 +11,6 @@ public class FlairMe extends PlayerCommand {
|
||||||
public boolean OnCommand(CommandSender sender, String label, String[] args) {
|
public boolean OnCommand(CommandSender sender, String label, String[] args) {
|
||||||
PortalListener.playersToBeFlaired.add(sender.getName());
|
PortalListener.playersToBeFlaired.add(sender.getName());
|
||||||
sender.sendMessage("Setup Successful! Walk through a portal to get your flair");
|
sender.sendMessage("Setup Successful! Walk through a portal to get your flair");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerPortalEvent;
|
import org.bukkit.event.player.PlayerPortalEvent;
|
||||||
import org.bukkit.material.MaterialData;
|
|
||||||
import org.bukkit.material.Wool;
|
import org.bukkit.material.Wool;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
@ -30,109 +29,105 @@ public class PortalListener implements Listener{
|
||||||
}
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPortalEnter(PlayerPortalEvent event){
|
public void onPortalEnter(PlayerPortalEvent event){
|
||||||
//SANITATION - Player
|
|
||||||
if(!(event.getPlayer() instanceof Player)){
|
if(!(event.getPlayer() instanceof Player)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//INIT - Player
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
//SANITATION - PlayersToBeFlaired
|
|
||||||
if(!(playersToBeFlaired.contains(player.getName()))){
|
if(!(playersToBeFlaired.contains(player.getName()))){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.sendMessage("-MAY THE FLAIRING COMMENCE-");
|
|
||||||
event.setTo(player.getLocation());
|
event.setTo(player.getLocation());
|
||||||
|
|
||||||
//INIT - x,y,z
|
|
||||||
int x = player.getLocation().getBlockX();
|
int x = player.getLocation().getBlockX();
|
||||||
int y = player.getLocation().getBlockY();
|
int y = player.getLocation().getBlockY();
|
||||||
int z = player.getLocation().getBlockZ();
|
int z = player.getLocation().getBlockZ();
|
||||||
|
|
||||||
//INIT - Blocks Under Portal
|
Block HigherBlock = player.getWorld().getBlockAt(x,y-2,z); //Block under obsidian
|
||||||
Block HigherBlock = player.getWorld().getBlockAt(x,y-2,z);
|
Block MiddleBlock = player.getWorld().getBlockAt(x,y-3,z); //Block under higher block
|
||||||
Block MiddleBlock = player.getWorld().getBlockAt(x,y-3,z);
|
Block BottomBlock = player.getWorld().getBlockAt(x,y-4,z); //Block under middle block
|
||||||
Block BottomBlock = player.getWorld().getBlockAt(x,y-4,z);
|
|
||||||
|
|
||||||
//RECOLOUR PLAYER
|
|
||||||
if(HigherBlock.getType() == Material.STONE){
|
if(HigherBlock.getType() == Material.STONE){
|
||||||
recolourPlayer(player, DyeColor.GRAY);
|
recolourPlayer(player, DyeColor.GRAY);
|
||||||
|
return;
|
||||||
//TOP BLOCK IS WOOL?
|
|
||||||
}else if(HigherBlock.getType() == Material.WOOL){
|
|
||||||
Wool wool = (Wool) HigherBlock.getState().getData();
|
|
||||||
recolourPlayer(player, wool.getColor());
|
|
||||||
|
|
||||||
//MIDDLE BLOCK IS WOOL?
|
|
||||||
}else if(MiddleBlock.getType() == Material.WOOL){
|
|
||||||
MaterialData mData = MiddleBlock.getState().getData();
|
|
||||||
Wool wool = (Wool) mData;
|
|
||||||
|
|
||||||
recolourPlayer(player, wool.getColor());
|
|
||||||
|
|
||||||
//BOTTOM BLOCK IS WOOL?
|
|
||||||
}else if (BottomBlock.getType() == Material.WOOL){
|
|
||||||
Wool wool = (Wool) BottomBlock.getState().getData();
|
|
||||||
recolourPlayer(player, wool.getColor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DyeColor woolColour = DyeColor.PINK; //Illegal value
|
||||||
|
if(HigherBlock.getType() == Material.WOOL){
|
||||||
|
woolColour = ((Wool) HigherBlock.getState().getData()).getColor();
|
||||||
|
}else if(MiddleBlock.getType() == Material.WOOL){
|
||||||
|
woolColour = ((Wool) MiddleBlock.getState().getData()).getColor();
|
||||||
|
}else if (BottomBlock.getType() == Material.WOOL){
|
||||||
|
woolColour = ((Wool) BottomBlock.getState().getData()).getColor();
|
||||||
|
}else{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
recolourPlayer(player, woolColour);
|
||||||
|
|
||||||
}
|
}
|
||||||
public void recolourPlayer(Player player, DyeColor dyecolour){
|
public void recolourPlayer(Player player, DyeColor dyecolour){
|
||||||
User user = essentials.getUser(player);
|
User user = essentials.getUser(player);
|
||||||
|
|
||||||
String name = user._getNickname();
|
String name = user._getNickname();
|
||||||
String tempName = "";
|
String sanitizedName = "";
|
||||||
for(int i = 0; i < name.length(); i++){
|
for(int i = 0; i < name.length(); i++){
|
||||||
if (name.charAt(i) != '§'){
|
if (name.charAt(i) != '§'){
|
||||||
tempName += name.charAt(i);
|
sanitizedName += name.charAt(i);
|
||||||
}else{
|
}else{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name = tempName;
|
|
||||||
|
String colourChanger = "";
|
||||||
|
|
||||||
switch(dyecolour){
|
switch(dyecolour){
|
||||||
case GRAY:
|
case GRAY:
|
||||||
player.sendMessage("Adding §7GRAY!§f");
|
colourChanger = "§7";
|
||||||
name = "§7" + name;
|
|
||||||
break;
|
break;
|
||||||
case RED:
|
case RED:
|
||||||
player.sendMessage("Adding §4RED!§f");
|
colourChanger = "§4";
|
||||||
name = "§4" + name;
|
|
||||||
break;
|
break;
|
||||||
case ORANGE:
|
case ORANGE:
|
||||||
player.sendMessage("Adding §6ORANGE!§f");
|
colourChanger = "§6";
|
||||||
name = "§6" + name;
|
|
||||||
break;
|
break;
|
||||||
case YELLOW:
|
case YELLOW:
|
||||||
player.sendMessage("Adding §eYELLOW!§f");
|
colourChanger = "§e";
|
||||||
name = "§e" + name;
|
|
||||||
break;
|
break;
|
||||||
case LIME:
|
case LIME:
|
||||||
|
colourChanger = "§a";
|
||||||
|
break;
|
||||||
case GREEN:
|
case GREEN:
|
||||||
player.sendMessage("Adding §aGREEN!§f");
|
colourChanger = "§a";
|
||||||
name = "§a" + name;
|
|
||||||
break;
|
break;
|
||||||
case CYAN:
|
case CYAN:
|
||||||
|
colourChanger = "§9";
|
||||||
|
break;
|
||||||
case LIGHT_BLUE:
|
case LIGHT_BLUE:
|
||||||
case BLUE:
|
colourChanger = "§9";
|
||||||
player.sendMessage("Adding §9BLUE!§f");
|
break;
|
||||||
name = "§9" + name;
|
case BLUE:
|
||||||
|
colourChanger = "§9";
|
||||||
break;
|
break;
|
||||||
case PURPLE:
|
case PURPLE:
|
||||||
player.sendMessage("Adding §5PURPLE!§f");
|
colourChanger = "§5";
|
||||||
name = "§5" + name;
|
|
||||||
break;
|
break;
|
||||||
case WHITE:
|
case WHITE:
|
||||||
player.sendMessage("Adding §fWHITE!§f");
|
colourChanger = "§f";
|
||||||
name = "§f" + name;
|
break;
|
||||||
default:
|
default:
|
||||||
player.sendMessage("ERROR, PORTAL HAS INVALID UNDER-BLOCK");
|
player.sendMessage("ERROR, PORTAL HAS INVALID UNDER-BLOCK");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
user.setNickname(name);
|
|
||||||
|
String newName = colourChanger + sanitizedName;
|
||||||
|
user.setNickname(newName);
|
||||||
|
|
||||||
|
player.sendMessage("Adding the colour " + colourChanger + dyecolour.name() + "§f!");
|
||||||
player.sendMessage("Your name is now: " + user.getNickname() +"!");
|
player.sendMessage("Your name is now: " + user.getNickname() +"!");
|
||||||
|
|
||||||
playersToBeFlaired.remove(player.getName());
|
playersToBeFlaired.remove(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue