From 15fbd0e1f3698271b50281fd97f59788323f9d65 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Wed, 3 Jul 2013 16:11:57 -0400 Subject: [PATCH] Got rid of dispatchCommand usage (where possible). Added TFM_WorldEditBridge. --- appinfo.properties | 6 +- buildnumber.properties | 4 +- nbproject/project.properties | 3 +- .../Commands/Command_gtfo.java | 16 +-- .../Commands/Command_invis.java | 2 +- .../Commands/Command_setl.java | 27 +--- .../Commands/Command_smite.java | 9 +- .../TotalFreedomMod/TFM_WorldEditBridge.java | 133 ++++++++++++++++++ 8 files changed, 157 insertions(+), 43 deletions(-) create mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_WorldEditBridge.java diff --git a/appinfo.properties b/appinfo.properties index 9a644a7e..a81b7ee2 100644 --- a/appinfo.properties +++ b/appinfo.properties @@ -1,5 +1,5 @@ -#Tue, 02 Jul 2013 19:01:31 -0400 +#Wed, 03 Jul 2013 16:10:19 -0400 program.VERSION=2.20 -program.BUILDNUM=242 -program.BUILDDATE=07/02/2013 07\:01 PM +program.BUILDNUM=247 +program.BUILDDATE=07/03/2013 04\:10 PM diff --git a/buildnumber.properties b/buildnumber.properties index e8fd8781..74505940 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Tue Jul 02 19:01:31 EDT 2013 -build.number=243 +#Wed Jul 03 16:10:19 EDT 2013 +build.number=248 diff --git a/nbproject/project.properties b/nbproject/project.properties index 08662639..28b755bc 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -32,7 +32,8 @@ jar.archive.disabled=${jnlp.enabled} jar.compress=false jar.index=${jnlp.enabled} javac.classpath=\ - ${libs.CraftBukkit.classpath} + ${libs.CraftBukkit.classpath}:\ + ${libs.WorldEdit.classpath} # Space-separated list of extra javac options javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.deprecation=false diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java index 40c703fb..147b11ce 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gtfo.java @@ -1,7 +1,9 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager; import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_WorldEditBridge; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; @@ -34,17 +36,11 @@ public class Command_gtfo extends TFM_Command TFM_Util.bcastMsg(p.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED); + // Undo WorldEdits: + TFM_WorldEditBridge.getInstance().undo(p, 15); - // Op Player - p.setOp(true); - - //Undo WorldEdits: - server.dispatchCommand(p, "/undo 15"); - - //rollback - - server.dispatchCommand(sender, "rollback " + p.getName()); - + // rollback + TFM_RollbackManager.rollback(p); // deop p.setOp(false); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_invis.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_invis.java index ec9c4e8b..13ec235f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_invis.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_invis.java @@ -40,7 +40,7 @@ public class Command_invis extends TFM_Command players.add(p.getName()); if (smite && !TFM_SuperadminList.isUserSuperadmin(p)) { - server.dispatchCommand(sender, "smite " + p.getName()); + Command_smite.smite(p); smites++; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setl.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setl.java index ca6212b7..f8fe4858 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setl.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_setl.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TFM_WorldEditBridge; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -12,34 +13,12 @@ public class Command_setl extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - //server.dispatchCommand(sender, "wildcard gcmd ? /limit 500"); - Madgeek: No, no, hell no. - TFM_Util.adminAction(sender.getName(), "Setting everyone's Worldedit block modification limit to 500.", true); - + TFM_WorldEditBridge web = TFM_WorldEditBridge.getInstance(); for (final Player p : server.getOnlinePlayers()) { - final boolean isOp = p.isOp(); - - if (!isOp) - { - p.setOp(true); - } - - server.dispatchCommand(p, "/limit 500"); - - if (!isOp) - { - server.getScheduler().runTaskLater(plugin, new Runnable() - { - @Override - public void run() - { - p.setOp(false); - } - }, 20L); - } + web.setLimit(p, 500); } - return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java index 595b00e0..1e3babea 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_smite.java @@ -32,6 +32,13 @@ public class Command_smite extends TFM_Command return true; } + smite(p); + + return true; + } + + public static void smite(final Player p) + { TFM_Util.bcastMsg(p.getName() + " has been a naughty, naughty boy.", ChatColor.RED); //Deop @@ -57,7 +64,5 @@ public class Command_smite extends TFM_Command //Kill: p.setHealth(0.0); - - return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_WorldEditBridge.java b/src/me/StevenLawson/TotalFreedomMod/TFM_WorldEditBridge.java new file mode 100644 index 00000000..722d29c2 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_WorldEditBridge.java @@ -0,0 +1,133 @@ +package me.StevenLawson.TotalFreedomMod; + +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.bukkit.BukkitPlayer; +import com.sk89q.worldedit.bukkit.BukkitServerInterface; +import com.sk89q.worldedit.bukkit.WorldEditAPI; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class TFM_WorldEditBridge +{ + private WorldEditPlugin worldEditPlugin = null; + private WorldEditAPI worldEditAPI = null; + private BukkitServerInterface bukkitServerInterface = null; + + private TFM_WorldEditBridge() + { + } + + public WorldEditPlugin getWorldEditPlugin() + { + if (this.worldEditPlugin == null) + { + Plugin we = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); + if (we != null) + { + if (we instanceof WorldEditPlugin) + { + this.worldEditPlugin = (WorldEditPlugin) we; + } + } + } + + return this.worldEditPlugin; + } + + public WorldEditAPI getWorldEditAPI() + { + if (this.worldEditAPI == null) + { + WorldEditPlugin wep = getWorldEditPlugin(); + if (wep != null) + { + this.worldEditAPI = new WorldEditAPI(wep); + } + } + + return this.worldEditAPI; + } + + public BukkitServerInterface getBukkitServerInterface() + { + if (this.bukkitServerInterface == null) + { + WorldEditPlugin wep = this.getWorldEditPlugin(); + if (wep != null) + { + this.bukkitServerInterface = new BukkitServerInterface(wep, Bukkit.getServer()); + } + } + + return this.bukkitServerInterface; + } + + public BukkitPlayer getBukkitPlayer(Player p) + { + WorldEditPlugin wep = this.getWorldEditPlugin(); + BukkitServerInterface bsi = this.getBukkitServerInterface(); + + if (wep != null && bsi != null) + { + return new BukkitPlayer(wep, bsi, p); + } + + return null; + } + + public void undo(Player p, int count) + { + try + { + WorldEditAPI api = this.getWorldEditAPI(); + if (api != null) + { + LocalSession session = api.getSession(p); + if (session != null) + { + BukkitPlayer bukkitPlayer = this.getBukkitPlayer(p); + for (int i = 0; i < count; i++) + { + session.undo(session.getBlockBag(bukkitPlayer), bukkitPlayer); + } + } + } + } + catch (Exception ex) + { + TFM_Log.severe(ex); + } + } + + public void setLimit(Player p, int limit) + { + try + { + WorldEditAPI api = this.getWorldEditAPI(); + if (api != null) + { + LocalSession session = api.getSession(p); + if (session != null) + { + session.setBlockChangeLimit(limit); + } + } + } + catch (Exception ex) + { + TFM_Log.severe(ex); + } + } + + public static TFM_WorldEditBridge getInstance() + { + return TFM_WorldEditBridgeHolder.INSTANCE; + } + + private static class TFM_WorldEditBridgeHolder + { + private static final TFM_WorldEditBridge INSTANCE = new TFM_WorldEditBridge(); + } +}