Took code from cbgm1, moved it to plotChange

This commit is contained in:
alisolarflare 2016-11-05 10:20:02 -04:00
parent b53bcc041c
commit 6b4a21d2ca

View file

@ -12,6 +12,8 @@ import com.palmergames.bukkit.towny.event.PlayerChangePlotEvent;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownyUniverse;
public class PlotChangeListener implements Listener{ public class PlotChangeListener implements Listener{
private List<Player> cbCreatives = new ArrayList<Player>(); private List<Player> cbCreatives = new ArrayList<Player>();
@ -37,31 +39,35 @@ public class PlotChangeListener implements Listener{
return; return;
} }
player.sendMessage("PONG"); player.sendMessage("PONG");
Resident currentResident = new Resident(player.getName()); TownBlock tb = TownyUniverse.getTownBlock(player.getLocation());
Town town; if (tb == null) {
try { player.sendMessage("You aren't standing in a town or some other error occured.");
player.sendMessage("PYONG"); player.sendMessage("TownBlock is null.");
debug(player, "1"+plotEvent.toString());
debug(player, "2"+plotEvent.getTo().toString());
debug(player, "3"+plotEvent.getTo().getTownBlock().toString());
debug(player, "4"+Boolean.toString(plotEvent.getTo().getTownBlock().hasTown()));
debug(player, "5"+plotEvent.getTo().getTownBlock().getTown().toString());
player.sendMessage("-");
if (plotEvent.getTo().getTownBlock().hasTown()){
player.sendMessage("YANG");
town = plotEvent.getTo().getTownBlock().getTown();
}else{
player.setGameMode(GameMode.SURVIVAL);
return;
}
} catch (NotRegisteredException e) {
e.printStackTrace();
debug(player, "6"+e.toString());
return; return;
} }
debug(player, "7"+currentResident.toString()); Town town;
if(!(town.hasResident(currentResident))) try {
town = tb.getTown();
} catch (NotRegisteredException e) {
player.sendMessage("You aren't standing in a town or some other error occured.");
player.sendMessage("TownBlock's town is not registered.");
return;
}
if (town == null) {
player.sendMessage("ERROR: The town you're standing in is Null.");
return;
}
boolean townHasRes = false;
for(Resident res : town.getResidents()){
if (res.getName().toString().equals(player.getName().toString())){
player.sendMessage("DINGDINGDING");
townHasRes = true;
}
}
if (!townHasRes){
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
}
} }
private void debug(Player player, String string){ private void debug(Player player, String string){
if (player.getName().equalsIgnoreCase("alisolarflare")) if (player.getName().equalsIgnoreCase("alisolarflare"))