From a6e5c2ad2693d30c97bac7420eec138daa32daba Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Thu, 3 Nov 2016 18:05:55 -0400 Subject: [PATCH] OM NOM NOM NOM NOM --- src/alisolarflare/townylearn/MainPlugin.java | 34 ++++++++++++ .../townylearn/PlotChangeListener.java | 47 ++++++++++++++++ .../townylearn/commands/Cbgm0.java | 23 ++++++++ .../townylearn/commands/Cbgm1.java | 53 +++++++++++++++++++ .../townylearn/commands/SetDickmode.java | 37 +++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 src/alisolarflare/townylearn/MainPlugin.java create mode 100644 src/alisolarflare/townylearn/PlotChangeListener.java create mode 100644 src/alisolarflare/townylearn/commands/Cbgm0.java create mode 100644 src/alisolarflare/townylearn/commands/Cbgm1.java create mode 100644 src/alisolarflare/townylearn/commands/SetDickmode.java diff --git a/src/alisolarflare/townylearn/MainPlugin.java b/src/alisolarflare/townylearn/MainPlugin.java new file mode 100644 index 0000000..1adf4dd --- /dev/null +++ b/src/alisolarflare/townylearn/MainPlugin.java @@ -0,0 +1,34 @@ +package alisolarflare.townylearn; + +import org.bukkit.plugin.java.JavaPlugin; +import alisolarflare.townylearn.commands.Cbgm0; +import alisolarflare.townylearn.commands.Cbgm1; +import alisolarflare.townylearn.commands.SetDickmode; + + +public class MainPlugin extends JavaPlugin{ + public boolean dickmode; + public void onEnable(){ + registerCommands(); + registerEvents(); + } + public void registerCommands(){ + getCommand("cbgm1").setExecutor(new Cbgm1()); + getCommand("cbgm0").setExecutor(new Cbgm0()); + getCommand("setdickmode").setExecutor(new SetDickmode(this)); + } + public void registerEvents(){ + PlotChangeListener plotChangeListener = new PlotChangeListener(this); + + getServer().getPluginManager().registerEvents(plotChangeListener, this); + } + public void setDickmode(boolean YES){ + dickmode = YES; + this.getConfig().set("dickmode", YES); + } + public boolean getDickmode(){ + boolean dickmode = this.getConfig().getBoolean("dickmode"); + this.dickmode = dickmode; + return dickmode; + } +} diff --git a/src/alisolarflare/townylearn/PlotChangeListener.java b/src/alisolarflare/townylearn/PlotChangeListener.java new file mode 100644 index 0000000..3e9421b --- /dev/null +++ b/src/alisolarflare/townylearn/PlotChangeListener.java @@ -0,0 +1,47 @@ +package alisolarflare.townylearn; + +import org.bukkit.GameMode; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import com.palmergames.bukkit.towny.event.PlayerChangePlotEvent; +import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; +import com.palmergames.bukkit.towny.object.Resident; +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.TownBlock; + +public class PlotChangeListener implements Listener{ + public boolean isInTown; + public MainPlugin plugin; + public PlotChangeListener(MainPlugin plugin){ + this.plugin = plugin; + } + @EventHandler + public void onPlayerPlotChange(PlayerChangePlotEvent plotEvent){ + if (plugin.dickmode == false){ + 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); + + } + } +} diff --git a/src/alisolarflare/townylearn/commands/Cbgm0.java b/src/alisolarflare/townylearn/commands/Cbgm0.java new file mode 100644 index 0000000..12a0bc1 --- /dev/null +++ b/src/alisolarflare/townylearn/commands/Cbgm0.java @@ -0,0 +1,23 @@ +package alisolarflare.townylearn.commands; + +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Cbgm0 implements CommandExecutor{ + + @Override + public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) { + if (!(sender instanceof Player)){ + sender.sendMessage("You must be a player to use this command!"); + return false; + } + + Player player = (Player) sender; + player.setGameMode(GameMode.SURVIVAL); + return false; + } + +} diff --git a/src/alisolarflare/townylearn/commands/Cbgm1.java b/src/alisolarflare/townylearn/commands/Cbgm1.java new file mode 100644 index 0000000..4a3f2ac --- /dev/null +++ b/src/alisolarflare/townylearn/commands/Cbgm1.java @@ -0,0 +1,53 @@ +package alisolarflare.townylearn.commands; + +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; +import com.palmergames.bukkit.towny.object.*; + +public class Cbgm1 implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) { + + if (!(sender instanceof Player)) { + sender.sendMessage("You must be a player to use this command!"); + return false; + } + + Player player = (Player) sender; + + 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."); + 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."); + return false; + } + if (town == null) { + player.sendMessage("§cERROR: The town you're standing in is Null."); + return false; + } + + for(Resident res : town.getResidents()){ + if (res.getName().toString().equals(player.getName().toString())){ + player.setGameMode(GameMode.CREATIVE); + return true; + } + } + player.sendMessage("Sorry, you're not part of this town"); + return false; + } + +} diff --git a/src/alisolarflare/townylearn/commands/SetDickmode.java b/src/alisolarflare/townylearn/commands/SetDickmode.java new file mode 100644 index 0000000..a83a019 --- /dev/null +++ b/src/alisolarflare/townylearn/commands/SetDickmode.java @@ -0,0 +1,37 @@ +package alisolarflare.townylearn.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import alisolarflare.townylearn.MainPlugin; + +public class SetDickmode implements CommandExecutor{ + private MainPlugin plugin; + + public SetDickmode(MainPlugin plugin){ + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender.getName().equals("Alisolarflare") || sender.getName().equals("iie")){ + if(args[0] == null){ + sender.sendMessage("You must use True, False, 1, or 0 as arguments!"); + return false; + } + if(args[0].equalsIgnoreCase("TRUE") || args[0].equalsIgnoreCase("1")){ + sender.sendMessage("Dickmode has been turned on!"); + plugin.setDickmode(true); + return true; + } + if(args[0].equalsIgnoreCase("FALSE") || args[0].equalsIgnoreCase("0")){ + sender.sendMessage("Dickmode has been turned off!"); + plugin.setDickmode(false); + return true; + } + return false; + } + return false; + } +}