CreativeBoundaries: Started work on protecting natural creatives

This commit is contained in:
alisolarflare 2016-11-05 06:26:03 -04:00
parent a925a7117f
commit 788943f50b
2 changed files with 44 additions and 29 deletions

View file

@ -1,6 +1,10 @@
package alisolarflare.creativeboundaries;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -11,37 +15,48 @@ import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
public class PlotChangeListener implements Listener{
public boolean isInTown;
private boolean dickmode;
public CreativeBoundariesModule plugin;
public List<Player> cbCreatives = new ArrayList<Player>();
public PlotChangeListener(CreativeBoundariesModule plugin){
this.plugin = plugin;
this.dickmode = plugin.dickmode;
}
@EventHandler
public void onPlayerPlotChange(PlayerChangePlotEvent plotEvent){
if (plugin.dickmode == false){
if (dickmode == false)
return;
if (plotEvent.getPlayer().getGameMode() != GameMode.CREATIVE)
return;
if (!(cbCreatives.contains(plotEvent.getPlayer())))
return;
Player player = plotEvent.getPlayer();
Resident currentResident = new Resident(player.getName());
Town town;
try {
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());
if (plotEvent.getTo().getTownBlock().hasTown())
town = plotEvent.getTo().getTownBlock().getTown();
else{
player.setGameMode(GameMode.SURVIVAL);
return;
}
} catch (NotRegisteredException e) {
e.printStackTrace();
debug(player, "6"+e.toString());
return;
}
try{
Resident currentResident = new Resident(plotEvent.getPlayer().getName().toLowerCase());
TownBlock plot = plotEvent.getTo().getTownBlock();
if(plot.hasTown()){
Town plotTown = plot.getTown();
if(!(plotTown.hasResident(currentResident))){
plotEvent.getPlayer().setGameMode(GameMode.SURVIVAL);
}
} else {
plotEvent.getPlayer().setGameMode(GameMode.SURVIVAL);
}
}catch(NotRegisteredException e){
//thrown by plotEvent.getTo().getTownBlock()
//thrown by plotEvent.getTo().getTownBlock().getTown();
plotEvent.getPlayer().setGameMode(GameMode.SURVIVAL);
}
debug(player, "7"+currentResident.toString());
if(!(town.hasResident(currentResident)))
player.setGameMode(GameMode.SURVIVAL);
}
private void debug(Player player, String string){
if (player.getName() == "alisolarflare")
player.sendMessage(string);
}
}

View file

@ -26,20 +26,20 @@ public class Cbgm1 extends TBMCCommandBase {
TownBlock tb = TownyUniverse.getTownBlock(player.getLocation());
if (tb == null) {
player.sendMessage("<EFBFBD>cYou aren't standing in a town or some other error occured.");
player.sendMessage("<EFBFBD>cTownBlock is null.");
player.sendMessage("You aren't standing in a town or some other error occured.");
player.sendMessage("TownBlock is null.");
return false;
}
Town town;
try {
town = tb.getTown();
} catch (NotRegisteredException e) {
player.sendMessage("<EFBFBD>cYou aren't standing in a town or some other error occured.");
player.sendMessage("<EFBFBD>cTownBlock's town is not registered.");
player.sendMessage("You aren't standing in a town or some other error occured.");
player.sendMessage("TownBlock's town is not registered.");
return false;
}
if (town == null) {
player.sendMessage("<EFBFBD>cERROR: The town you're standing in is Null.");
player.sendMessage("ERROR: The town you're standing in is Null.");
return false;
}