From 5ed6df2306209b2187f41492282d589be5a9acef Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Wed, 19 Sep 2012 21:43:12 -0400 Subject: [PATCH] Finished /potion command. Added /lockup all and /lockup purge. --- .../Commands/Command_levelup.java | 32 ----- .../Commands/Command_lockup.java | 120 +++++++++++----- .../Commands/Command_potion.java | 135 ++++++++++++++++-- .../Listener/TFM_PlayerListener.java | 4 + src/plugin.yml | 13 +- 5 files changed, 213 insertions(+), 91 deletions(-) delete mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_levelup.java diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_levelup.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_levelup.java deleted file mode 100644 index d21cfdc6..00000000 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_levelup.java +++ /dev/null @@ -1,32 +0,0 @@ -package me.StevenLawson.TotalFreedomMod.Commands; - -import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class Command_levelup extends TFM_Command -{ - @Override - public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (senderIsConsole) - { - sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); - return true; - } - - if (!sender.isOp()) - { - sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); - return true; - } - - sender_p.setExp(1.0f); - - sender.sendMessage(ChatColor.AQUA + "Level up!"); - - return true; - } -} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java index 7091d96b..f5e69ecc 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_lockup.java @@ -21,51 +21,67 @@ public class Command_lockup extends TFM_Command return true; } - if (args.length != 2) + if (args.length == 1) { - return false; - } - - final Player p; - try - { - p = getPlayer(args[0]); - } - catch (CantFindPlayerException ex) - { - sender.sendMessage(ex.getMessage()); - return true; - } - - TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); - - if (args[1].equalsIgnoreCase("on")) - { - cancelLockup(playerdata); - - playerdata.setLockupScheduleID(server.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() + if (args[0].equalsIgnoreCase("all")) { - private Random random = new Random(); - - @Override - public void run() + for (Player p : server.getOnlinePlayers()) { - p.openWorkbench(null, true); - - Location l = p.getLocation().clone(); - l.setPitch(random.nextFloat() * 360.0f); - l.setYaw(random.nextFloat() * 360.0f); - p.teleport(l); + startLockup(p); } - }, 0L, 5L)); - - sender.sendMessage(ChatColor.GRAY + "Locking up " + p.getName()); + sender.sendMessage(ChatColor.GRAY + "Locking up all players."); + } + else if (args[0].equalsIgnoreCase("purge")) + { + for (Player p : server.getOnlinePlayers()) + { + cancelLockup(p); + } + sender.sendMessage(ChatColor.GRAY + "Not locking up all players."); + } + else + { + return false; + } } - else if (args[1].equalsIgnoreCase("off")) + else if (args.length == 2) { - cancelLockup(playerdata); + if (args[1].equalsIgnoreCase("on")) + { + final Player p; + try + { + p = getPlayer(args[0]); + } + catch (CantFindPlayerException ex) + { + sender.sendMessage(ex.getMessage()); + return true; + } - sender.sendMessage(ChatColor.GRAY + "Not locking up " + p.getName() + " anymore."); + startLockup(p); + sender.sendMessage(ChatColor.GRAY + "Locking up " + p.getName()); + } + else if (args[1].equalsIgnoreCase("off")) + { + final Player p; + try + { + p = getPlayer(args[0]); + } + catch (CantFindPlayerException ex) + { + sender.sendMessage(ex.getMessage()); + return true; + } + + cancelLockup(p); + sender.sendMessage(ChatColor.GRAY + "Not locking up " + p.getName() + " anymore."); + } + else + { + return false; + } } else { @@ -85,4 +101,32 @@ public class Command_lockup extends TFM_Command playerdata.setLockupScheduleID(-1); } } + + private void cancelLockup(final Player p) + { + cancelLockup(TFM_UserInfo.getPlayerData(p)); + } + + private void startLockup(final Player p) + { + TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); + + cancelLockup(playerdata); + + playerdata.setLockupScheduleID(server.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() + { + private Random random = new Random(); + + @Override + public void run() + { + p.openWorkbench(null, true); + + Location l = p.getLocation().clone(); + l.setPitch(random.nextFloat() * 360.0f); + l.setYaw(random.nextFloat() * 360.0f); + p.teleport(l); + } + }, 0L, 5L)); + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java index 8be0c577..635b219b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_potion.java @@ -2,13 +2,15 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.ArrayList; import java.util.List; +import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.potion.PotionType; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; public class Command_potion extends TFM_Command { @@ -27,21 +29,128 @@ public class Command_potion extends TFM_Command return true; } - if (args.length < 1) + if (args.length == 1 || args.length == 2) + { + if (args[0].equalsIgnoreCase("list")) + { + List potionEffectTypeNames = new ArrayList(); + for (PotionEffectType potion_effect_type : PotionEffectType.values()) + { + if (potion_effect_type != null) + { + potionEffectTypeNames.add(potion_effect_type.getName()); + } + } + sender.sendMessage(ChatColor.AQUA + "Potion effect types: " + StringUtils.join(potionEffectTypeNames, ", ")); + } + else if (args[0].equalsIgnoreCase("clear")) + { + Player target = sender_p; + + if (args.length == 2) + { + try + { + target = getPlayer(args[1]); + } + catch (CantFindPlayerException ex) + { + sender.sendMessage(ex.getMessage()); + return true; + } + } + + if (!target.equals(sender_p) && !TFM_Util.isUserSuperadmin(sender)) + { + sender.sendMessage("Only superadmins can clear potion effects from other players."); + return true; + } + + for (PotionEffect potion_effect : sender_p.getActivePotionEffects()) + { + target.removePotionEffect(potion_effect.getType()); + } + + sender.sendMessage(ChatColor.AQUA + "Cleared all active potion effects " + (!target.equals(sender_p) ? "from player " + target.getName() + "." : "from yourself.")); + } + else + { + return false; + } + } + else if (args.length == 4 || args.length == 5) + { + if (args[0].equalsIgnoreCase("add")) + { + Player target = sender_p; + + if (args.length == 5) + { + try + { + target = getPlayer(args[4]); + } + catch (CantFindPlayerException ex) + { + sender.sendMessage(ex.getMessage()); + return true; + } + } + + if (!target.equals(sender_p) && !TFM_Util.isUserSuperadmin(sender)) + { + sender.sendMessage("Only superadmins can apply potion effects to other players."); + return true; + } + + PotionEffectType potion_effect_type = PotionEffectType.getByName(args[1]); + if (potion_effect_type == null) + { + sender.sendMessage(ChatColor.AQUA + "Invalid potion effect type."); + return true; + } + + int duration; + try + { + duration = Integer.parseInt(args[2]); + } + catch (NumberFormatException ex) + { + sender.sendMessage(ChatColor.AQUA + "Invalid potion duration."); + return true; + } + + int amplifier; + try + { + amplifier = Integer.parseInt(args[3]); + } + catch (NumberFormatException ex) + { + sender.sendMessage(ChatColor.AQUA + "Invalid potion amplifier."); + return true; + } + + PotionEffect new_effect = potion_effect_type.createEffect(duration, amplifier); + target.addPotionEffect(new_effect, true); + sender.sendMessage(ChatColor.AQUA + + "Added potion effect: " + new_effect.getType().getName() + + ", Duration: " + new_effect.getDuration() + + ", Amplifier: " + new_effect.getAmplifier() + + (!target.equals(sender_p) ? " to player " + target.getName() + "." : " to yourself.")); + + return true; + } + else + { + return false; + } + } + else { return false; } - - if (args[0].equalsIgnoreCase("list")) - { - List potionTypeNames = new ArrayList(); - for (PotionType potion_type : PotionType.values()) - { - potionTypeNames.add(potion_type.name()); - } - sender.sendMessage(ChatColor.AQUA + "Potion types: " + StringUtils.join(potionTypeNames, ", ")); - } - return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index c58f7093..716b4f52 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -455,6 +455,10 @@ public class TFM_PlayerListener implements Listener { block_command = true; } + else if (Pattern.compile("^/toggledownfall").matcher(command).find()) + { + block_command = true; + } } if (block_command) diff --git a/src/plugin.yml b/src/plugin.yml index b8ec6db3..5d0e895b 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -88,16 +88,13 @@ commands: lavaplace: description: Superadmin command - Enable/disable lava placement. usage: / -# levelup: -# description: Level up! -# usage: / list: description: Lists the real names of all online players. usage: / aliases: [who] lockup: description: Console command - Block target's minecraft input. This is evil, and I never should have wrote it. - usage: / + usage: / on | off>> moblimiter: description: Owner command - Controll mob rezzing parameters. usage: / |dragon|giant|ghast|slime> @@ -134,9 +131,9 @@ commands: permban: description: Manage permanently banned players and IPs usage: / -# potion: -# description: Manipulate potion effects. -# usage: / + potion: + description: Manipulate potion effects. Duration is measured in server ticks (~20 ticks per second). + usage: / [target_name]> prelog: description: Superadmin command - Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages. usage: / @@ -216,7 +213,7 @@ commands: wildcard: description: Superadmin command - Run any command on all users, username placeholder = ?. usage: / [fluff] ? [fluff] ? -# wipeflatlands: +# wipeflatlands: - Currently broken. # description: Owner command - Wipe the flatlands map. # usage: / ziptool: