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.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,32 +39,36 @@ 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());
|
||||||
|
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;
|
Town town;
|
||||||
try {
|
try {
|
||||||
player.sendMessage("PYONG");
|
town = tb.getTown();
|
||||||
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) {
|
} catch (NotRegisteredException e) {
|
||||||
e.printStackTrace();
|
player.sendMessage("You aren't standing in a town or some other error occured.");
|
||||||
debug(player, "6"+e.toString());
|
player.sendMessage("TownBlock's town is not registered.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debug(player, "7"+currentResident.toString());
|
if (town == null) {
|
||||||
if(!(town.hasResident(currentResident)))
|
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"))
|
||||||
player.sendMessage(string);
|
player.sendMessage(string);
|
||||||
|
|
Loading…
Reference in a new issue