Cleaned up Creative Boundaries for public use

This commit is contained in:
alisolarflare 2016-11-05 10:32:52 -04:00
parent 6b4a21d2ca
commit c8cda48209
3 changed files with 28 additions and 29 deletions

View file

@ -18,7 +18,7 @@ public class CreativeBoundariesModule extends Module{
@Override @Override
public void register(JavaPlugin plugin) { public void register(JavaPlugin plugin) {
registerCommand(plugin, new Cbgm1(this)); registerCommand(plugin, new Cbgm1(this));
registerCommand(plugin, new Cbgm0()); registerCommand(plugin, new Cbgm0(this));
registerCommand(plugin, new SetDickmode(this)); registerCommand(plugin, new SetDickmode(this));

View file

@ -1,8 +1,5 @@
package alisolarflare.creativeboundaries; package alisolarflare.creativeboundaries;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -16,61 +13,55 @@ import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownyUniverse; import com.palmergames.bukkit.towny.object.TownyUniverse;
public class PlotChangeListener implements Listener{ public class PlotChangeListener implements Listener{
private List<Player> cbCreatives = new ArrayList<Player>(); public CreativeBoundariesModule module;
public CreativeBoundariesModule plugin; public PlotChangeListener(CreativeBoundariesModule module){
public PlotChangeListener(CreativeBoundariesModule plugin){ this.module = module;
this.plugin = plugin;
this.cbCreatives = plugin.cbCreatives;
} }
@EventHandler @EventHandler
public void onPlayerPlotChange(PlayerChangePlotEvent plotEvent){ public void onPlayerPlotChange(PlayerChangePlotEvent plotEvent){
Player player = plotEvent.getPlayer(); Player player = plotEvent.getPlayer();
player.sendMessage("PING"); if (module.dickmode == false){
if (plugin.dickmode == false){
debug(player, "dickies");
return; return;
} }
if (plotEvent.getPlayer().getGameMode() != GameMode.CREATIVE){ if (plotEvent.getPlayer().getGameMode() != GameMode.CREATIVE){
debug(player, "cray cray");
return; return;
} }
if (!(cbCreatives.contains(plotEvent.getPlayer()))){ if (!(module.cbCreatives.contains(plotEvent.getPlayer()))){
debug(player, "racism");
return; return;
} }
player.sendMessage("PONG");
TownBlock tb = TownyUniverse.getTownBlock(player.getLocation()); TownBlock tb = TownyUniverse.getTownBlock(player.getLocation());
if (tb == null) { if (tb == null) {
player.sendMessage("You aren't standing in a town or some other error occured."); player.setGameMode(GameMode.SURVIVAL);
player.sendMessage("TownBlock is null."); player.sendMessage("You have left your town boundaries!");
module.cbCreatives.remove(player);
return; return;
} }
Town town; Town town;
try { try {
town = tb.getTown(); town = tb.getTown();
} catch (NotRegisteredException e) { } catch (NotRegisteredException e) {
player.sendMessage("You aren't standing in a town or some other error occured."); player.setGameMode(GameMode.SURVIVAL);
player.sendMessage("TownBlock's town is not registered."); player.sendMessage("You have left your town boundaries!!");
return; module.cbCreatives.remove(player);
}
if (town == null) {
player.sendMessage("ERROR: The town you're standing in is Null.");
return; return;
} }
if (town == null) {
player.setGameMode(GameMode.SURVIVAL);
player.sendMessage("You have left your town boundaries!!!");
module.cbCreatives.remove(player);
return;
}
boolean townHasRes = false; boolean townHasRes = false;
for(Resident res : town.getResidents()){ for(Resident res : town.getResidents()){
if (res.getName().toString().equals(player.getName().toString())){ if (res.getName().toString().equals(player.getName().toString())){
player.sendMessage("DINGDINGDING");
townHasRes = true; townHasRes = true;
} }
} }
if (!townHasRes){ if (!townHasRes){
player.setGameMode(GameMode.SURVIVAL); 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);
}
} }

View file

@ -4,10 +4,17 @@ import org.bukkit.GameMode;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import alisolarflare.creativeboundaries.CreativeBoundariesModule;
import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.chat.TBMCCommandBase;
public class Cbgm0 extends TBMCCommandBase{ public class Cbgm0 extends TBMCCommandBase{
private CreativeBoundariesModule module;
public Cbgm0(CreativeBoundariesModule module) {
this.module = module;
}
@Override @Override
public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) { public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) {
if (!(sender instanceof Player)){ if (!(sender instanceof Player)){
@ -17,6 +24,7 @@ public class Cbgm0 extends TBMCCommandBase{
Player player = (Player) sender; Player player = (Player) sender;
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
module.cbCreatives.remove(player);
return false; return false;
} }