From 788943f50b1ddab5315c50c4588ca8bd0ae67705 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sat, 5 Nov 2016 06:26:03 -0400 Subject: [PATCH] CreativeBoundaries: Started work on protecting natural creatives --- .../PlotChangeListener.java | 63 ++++++++++++------- .../creativeboundaries/commands/Cbgm1.java | 10 +-- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/alisolarflare/creativeboundaries/PlotChangeListener.java b/src/alisolarflare/creativeboundaries/PlotChangeListener.java index e815539..0a5820e 100644 --- a/src/alisolarflare/creativeboundaries/PlotChangeListener.java +++ b/src/alisolarflare/creativeboundaries/PlotChangeListener.java @@ -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 cbCreatives = new ArrayList(); 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); } } diff --git a/src/alisolarflare/creativeboundaries/commands/Cbgm1.java b/src/alisolarflare/creativeboundaries/commands/Cbgm1.java index 09753cc..14c69ce 100644 --- a/src/alisolarflare/creativeboundaries/commands/Cbgm1.java +++ b/src/alisolarflare/creativeboundaries/commands/Cbgm1.java @@ -26,20 +26,20 @@ public class Cbgm1 extends TBMCCommandBase { TownBlock tb = TownyUniverse.getTownBlock(player.getLocation()); if (tb == null) { - player.sendMessage("�cYou aren't standing in a town or some other error occured."); - player.sendMessage("�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("�cYou aren't standing in a town or some other error occured."); - player.sendMessage("�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("�cERROR: The town you're standing in is Null."); + player.sendMessage("ERROR: The town you're standing in is Null."); return false; }