Took code from cbgm1, moved it to plotChange
This commit is contained in:
parent
b53bcc041c
commit
6b4a21d2ca
1 changed files with 28 additions and 22 deletions
|
@ -12,6 +12,8 @@ import com.palmergames.bukkit.towny.event.PlayerChangePlotEvent;
|
|||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
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{
|
||||
private List<Player> cbCreatives = new ArrayList<Player>();
|
||||
|
@ -37,32 +39,36 @@ public class PlotChangeListener implements Listener{
|
|||
return;
|
||||
}
|
||||
player.sendMessage("PONG");
|
||||
Resident currentResident = new Resident(player.getName());
|
||||
TownBlock tb = TownyUniverse.getTownBlock(player.getLocation());
|
||||
if (tb == null) {
|
||||
player.sendMessage("You aren't standing in a town or some other error occured.");
|
||||
player.sendMessage("TownBlock is null.");
|
||||
return;
|
||||
}
|
||||
Town town;
|
||||
try {
|
||||
player.sendMessage("PYONG");
|
||||
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;
|
||||
}
|
||||
town = tb.getTown();
|
||||
} catch (NotRegisteredException e) {
|
||||
e.printStackTrace();
|
||||
debug(player, "6"+e.toString());
|
||||
player.sendMessage("You aren't standing in a town or some other error occured.");
|
||||
player.sendMessage("TownBlock's town is not registered.");
|
||||
return;
|
||||
}
|
||||
debug(player, "7"+currentResident.toString());
|
||||
if(!(town.hasResident(currentResident)))
|
||||
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);
|
||||
}
|
||||
}
|
||||
private void debug(Player player, String string){
|
||||
if (player.getName().equalsIgnoreCase("alisolarflare"))
|
||||
player.sendMessage(string);
|
||||
|
|
Loading…
Reference in a new issue