From b46bbd3ebafebd6568db184dc57397d84e4f2e94 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Fri, 2 Nov 2012 21:03:12 -0400 Subject: [PATCH] Stuff for new the new Command Block, mostly. Added /cartsit, mainly for command blocks. Added -s (silent) switch to qop and qdeop, for command blocks. Removed TFM_Messages class, since it was just clutter. Added proprietary handler for CommandBlockChangeEvent, you'll need to implement this yourself in CraftBukkit or remove the event if you want to compile. --- .../Commands/Command_cartsit.java | 77 +++++++++++++++++++ .../Commands/Command_qdeop.java | 13 +++- .../TotalFreedomMod/Commands/Command_qop.java | 13 +++- .../Listener/TFM_BlockListener.java | 21 +++++ .../TotalFreedomMod/TFM_Messages.java | 27 ------- src/plugin.yml | 3 + 6 files changed, 123 insertions(+), 31 deletions(-) create mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java delete mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_Messages.java diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java new file mode 100644 index 0000000..a73584e --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cartsit.java @@ -0,0 +1,77 @@ +package me.StevenLawson.TotalFreedomMod.Commands; + +import me.StevenLawson.TotalFreedomMod.TFM_Util; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Minecart; +import org.bukkit.entity.Player; + +public class Command_cartsit extends TFM_Command +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + Player target_player = sender_p; + + if (args.length == 1) + { + try + { + target_player = getPlayer(args[0]); + } + catch (CantFindPlayerException ex) + { + sender.sendMessage(ex.getMessage()); + return true; + } + } + + if (senderIsConsole) + { + if (target_player == null) + { + sender.sendMessage("When used from the console, you must define a target player: /cartsit "); + return true; + } + } + else if (target_player != sender_p && !TFM_Util.isUserSuperadmin(sender)) + { + sender.sendMessage("Only superadmins can select another player as a /cartsit target."); + return true; + } + + if (target_player.isInsideVehicle()) + { + target_player.getVehicle().eject(); + } + else + { + Minecart nearest_cart = null; + for (Minecart cart : target_player.getWorld().getEntitiesByClass(Minecart.class)) + { + if (nearest_cart == null) + { + nearest_cart = cart; + } + else + { + if (cart.getLocation().distance(target_player.getLocation()) < nearest_cart.getLocation().distance(target_player.getLocation())) + { + nearest_cart = cart; + } + } + } + + if (nearest_cart != null) + { + nearest_cart.setPassenger(target_player); + } + else + { + sender.sendMessage("There are no minecarts in the target world."); + } + } + + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qdeop.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qdeop.java index bd4d650..82bd69a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qdeop.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qdeop.java @@ -11,7 +11,7 @@ public class Command_qdeop extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (args.length != 1) + if (args.length < 1) { return false; } @@ -22,6 +22,12 @@ public class Command_qdeop extends TFM_Command return true; } + boolean silent = false; + if (args.length == 2) + { + silent = args[1].equalsIgnoreCase("-s"); + } + boolean matched_player = false; String target_name = args[0].toLowerCase(); @@ -32,7 +38,10 @@ public class Command_qdeop extends TFM_Command { matched_player = true; - TFM_Util.adminAction(sender.getName(), "De-opping " + p.getName(), false); + if (!silent) + { + TFM_Util.adminAction(sender.getName(), "De-opping " + p.getName(), false); + } p.setOp(false); p.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qop.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qop.java index 0e3bb84..81d4e70 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qop.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qop.java @@ -11,7 +11,7 @@ public class Command_qop extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (args.length != 1) + if (args.length < 1) { return false; } @@ -22,6 +22,12 @@ public class Command_qop extends TFM_Command return true; } + boolean silent = false; + if (args.length == 2) + { + silent = args[1].equalsIgnoreCase("-s"); + } + boolean matched_player = false; String target_name = args[0].toLowerCase(); @@ -32,7 +38,10 @@ public class Command_qop extends TFM_Command { matched_player = true; - TFM_Util.adminAction(sender.getName(), "Opping " + p.getName(), false); + if (!silent) + { + TFM_Util.adminAction(sender.getName(), "Opping " + p.getName(), false); + } p.setOp(true); p.sendMessage(TotalFreedomMod.YOU_ARE_OP); } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java index ff0bbbd..510d695 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_BlockListener.java @@ -224,4 +224,25 @@ public class TFM_BlockListener implements Listener event.setCancelled(true); } } + + //This event is not in the standard Bukkit / CraftBukkit server, only my custom version. Remove it if you want to compile this plugin yourself. + @EventHandler(priority = EventPriority.NORMAL) + public void onCommandBlockChangeEvent(CommandBlockChangeEvent event) + { + Player player = event.getPlayer(); + + if (!TFM_Util.isUserSuperadmin(player)) + { + TFM_Util.playerMsg(player, "You do not have permission to set Command Block commands."); + event.setCancelled(true); + return; + } + + if (!TotalFreedomMod.superAwesomeAdmins.contains(player.getName().toLowerCase())) + { + TFM_Util.playerMsg(player, "You do not have permission to set Command Block commands."); + event.setCancelled(true); + return; + } + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Messages.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Messages.java deleted file mode 100644 index c287896..0000000 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Messages.java +++ /dev/null @@ -1,27 +0,0 @@ -package me.StevenLawson.TotalFreedomMod; - -import org.bukkit.ChatColor; - -// Work in progress -@Deprecated -public enum TFM_Messages -{ - NO_PERMS(ChatColor.YELLOW + "You do not have permission to use this command."), - YOU_ARE_OP(ChatColor.YELLOW + "You are now op!"), - YOU_ARE_NOT_OP(ChatColor.YELLOW + "You are no longer op!"), - CAKE_LYRICS("But there's no sense crying over every mistake. You just keep on trying till you run out of cake."), - NOT_FROM_CONSOLE("This command may not be used from the console."); - - private final String message; - - TFM_Messages(String message) - { - this.message = message; - } - - @Override - public String toString() - { - return message; - } -} diff --git a/src/plugin.yml b/src/plugin.yml index c22fbc3..37b1f2f 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -13,6 +13,9 @@ commands: cake: description: Superadmin command - For the people that are still alive. usage: / + cartsit: + description: Sit in nearest minecart. If target is in a minecart already, they will disembark. + usage: / [partialname] clearall: description: Superadmin command - Removes all entities, nicks and disguises usage: /