From c8cda48209069c0aa299ece073cc2e99cceecd7f Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sat, 5 Nov 2016 10:32:52 -0400 Subject: [PATCH] Cleaned up Creative Boundaries for public use --- .../CreativeBoundariesModule.java | 2 +- .../PlotChangeListener.java | 47 ++++++++----------- .../creativeboundaries/commands/Cbgm0.java | 8 ++++ 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/alisolarflare/creativeboundaries/CreativeBoundariesModule.java b/src/alisolarflare/creativeboundaries/CreativeBoundariesModule.java index 6a36180..6de650f 100644 --- a/src/alisolarflare/creativeboundaries/CreativeBoundariesModule.java +++ b/src/alisolarflare/creativeboundaries/CreativeBoundariesModule.java @@ -18,7 +18,7 @@ public class CreativeBoundariesModule extends Module{ @Override public void register(JavaPlugin plugin) { registerCommand(plugin, new Cbgm1(this)); - registerCommand(plugin, new Cbgm0()); + registerCommand(plugin, new Cbgm0(this)); registerCommand(plugin, new SetDickmode(this)); diff --git a/src/alisolarflare/creativeboundaries/PlotChangeListener.java b/src/alisolarflare/creativeboundaries/PlotChangeListener.java index e0b7aa1..ddd69b4 100644 --- a/src/alisolarflare/creativeboundaries/PlotChangeListener.java +++ b/src/alisolarflare/creativeboundaries/PlotChangeListener.java @@ -1,8 +1,5 @@ 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; @@ -16,61 +13,55 @@ import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownyUniverse; public class PlotChangeListener implements Listener{ - private List cbCreatives = new ArrayList(); - public CreativeBoundariesModule plugin; - public PlotChangeListener(CreativeBoundariesModule plugin){ - this.plugin = plugin; - this.cbCreatives = plugin.cbCreatives; + public CreativeBoundariesModule module; + public PlotChangeListener(CreativeBoundariesModule module){ + this.module = module; } @EventHandler public void onPlayerPlotChange(PlayerChangePlotEvent plotEvent){ Player player = plotEvent.getPlayer(); - player.sendMessage("PING"); - if (plugin.dickmode == false){ - debug(player, "dickies"); + if (module.dickmode == false){ return; } if (plotEvent.getPlayer().getGameMode() != GameMode.CREATIVE){ - debug(player, "cray cray"); return; } - if (!(cbCreatives.contains(plotEvent.getPlayer()))){ - debug(player, "racism"); + if (!(module.cbCreatives.contains(plotEvent.getPlayer()))){ return; } - player.sendMessage("PONG"); 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."); + player.setGameMode(GameMode.SURVIVAL); + player.sendMessage("You have left your town boundaries!"); + module.cbCreatives.remove(player); return; } Town town; 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."); + player.setGameMode(GameMode.SURVIVAL); + player.sendMessage("You have left your town boundaries!!"); + module.cbCreatives.remove(player); return; } + if (town == null) { + player.setGameMode(GameMode.SURVIVAL); + player.sendMessage("You have left your town boundaries!!!"); + module.cbCreatives.remove(player); + 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.sendMessage("You have left your town boundaries!!!!"); + module.cbCreatives.remove(player); } } - private void debug(Player player, String string){ - if (player.getName().equalsIgnoreCase("alisolarflare")) - player.sendMessage(string); - } } diff --git a/src/alisolarflare/creativeboundaries/commands/Cbgm0.java b/src/alisolarflare/creativeboundaries/commands/Cbgm0.java index 88ba03a..6e5fd2a 100644 --- a/src/alisolarflare/creativeboundaries/commands/Cbgm0.java +++ b/src/alisolarflare/creativeboundaries/commands/Cbgm0.java @@ -4,9 +4,16 @@ import org.bukkit.GameMode; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import alisolarflare.creativeboundaries.CreativeBoundariesModule; import buttondevteam.lib.chat.TBMCCommandBase; public class Cbgm0 extends TBMCCommandBase{ + + private CreativeBoundariesModule module; + + public Cbgm0(CreativeBoundariesModule module) { + this.module = module; + } @Override public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) { @@ -17,6 +24,7 @@ public class Cbgm0 extends TBMCCommandBase{ Player player = (Player) sender; player.setGameMode(GameMode.SURVIVAL); + module.cbCreatives.remove(player); return false; }