Finished /potion command.

Added /lockup all and /lockup purge.
This commit is contained in:
Steven Lawson 2012-09-19 21:43:12 -04:00
parent 1551d29cc2
commit 5ed6df2306
5 changed files with 213 additions and 91 deletions

View File

@ -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;
}
}

View File

@ -21,51 +21,67 @@ public class Command_lockup extends TFM_Command
return true; return true;
} }
if (args.length != 2) if (args.length == 1)
{ {
return false; if (args[0].equalsIgnoreCase("all"))
}
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()
{ {
private Random random = new Random(); for (Player p : server.getOnlinePlayers())
@Override
public void run()
{ {
p.openWorkbench(null, true); startLockup(p);
Location l = p.getLocation().clone();
l.setPitch(random.nextFloat() * 360.0f);
l.setYaw(random.nextFloat() * 360.0f);
p.teleport(l);
} }
}, 0L, 5L)); sender.sendMessage(ChatColor.GRAY + "Locking up all players.");
}
sender.sendMessage(ChatColor.GRAY + "Locking up " + p.getName()); 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 else
{ {
@ -85,4 +101,32 @@ public class Command_lockup extends TFM_Command
playerdata.setLockupScheduleID(-1); 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));
}
} }

View File

@ -2,13 +2,15 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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 public class Command_potion extends TFM_Command
{ {
@ -27,21 +29,128 @@ public class Command_potion extends TFM_Command
return true; return true;
} }
if (args.length < 1) if (args.length == 1 || args.length == 2)
{
if (args[0].equalsIgnoreCase("list"))
{
List<String> potionEffectTypeNames = new ArrayList<String>();
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; return false;
} }
if (args[0].equalsIgnoreCase("list"))
{
List potionTypeNames = new ArrayList<String>();
for (PotionType potion_type : PotionType.values())
{
potionTypeNames.add(potion_type.name());
}
sender.sendMessage(ChatColor.AQUA + "Potion types: " + StringUtils.join(potionTypeNames, ", "));
}
return true; return true;
} }
} }

View File

@ -455,6 +455,10 @@ public class TFM_PlayerListener implements Listener
{ {
block_command = true; block_command = true;
} }
else if (Pattern.compile("^/toggledownfall").matcher(command).find())
{
block_command = true;
}
} }
if (block_command) if (block_command)

View File

@ -88,16 +88,13 @@ commands:
lavaplace: lavaplace:
description: Superadmin command - Enable/disable lava placement. description: Superadmin command - Enable/disable lava placement.
usage: /<command> <on | off> usage: /<command> <on | off>
# levelup:
# description: Level up!
# usage: /<command>
list: list:
description: Lists the real names of all online players. description: Lists the real names of all online players.
usage: /<command> usage: /<command>
aliases: [who] aliases: [who]
lockup: lockup:
description: Console command - Block target's minecraft input. This is evil, and I never should have wrote it. description: Console command - Block target's minecraft input. This is evil, and I never should have wrote it.
usage: /<command> <partialname> <on | off> usage: /<command> <all | purge | <<partialname> on | off>>
moblimiter: moblimiter:
description: Owner command - Controll mob rezzing parameters. description: Owner command - Controll mob rezzing parameters.
usage: /<command> <on|off|setmax <count>|dragon|giant|ghast|slime> usage: /<command> <on|off|setmax <count>|dragon|giant|ghast|slime>
@ -134,9 +131,9 @@ commands:
permban: permban:
description: Manage permanently banned players and IPs description: Manage permanently banned players and IPs
usage: /<command> <list | reload> usage: /<command> <list | reload>
# potion: potion:
# description: Manipulate potion effects. description: Manipulate potion effects. Duration is measured in server ticks (~20 ticks per second).
# usage: /<command> <list> usage: /<command> <list | clear [target_name] | add <type> <duration> <amplifier> [target_name]>
prelog: prelog:
description: Superadmin command - Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages. description: Superadmin command - Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages.
usage: /<command> <on | off> usage: /<command> <on | off>
@ -216,7 +213,7 @@ commands:
wildcard: wildcard:
description: Superadmin command - Run any command on all users, username placeholder = ?. description: Superadmin command - Run any command on all users, username placeholder = ?.
usage: /<command> [fluff] ? [fluff] ? usage: /<command> [fluff] ? [fluff] ?
# wipeflatlands: # wipeflatlands: - Currently broken.
# description: Owner command - Wipe the flatlands map. # description: Owner command - Wipe the flatlands map.
# usage: /<command> # usage: /<command>
ziptool: ziptool: