I'm a horrible person - /lockup

Fixed a glitch with /permban
This commit is contained in:
Steven Lawson 2012-09-18 22:21:25 -04:00
parent bf13858d47
commit 1551d29cc2
5 changed files with 185 additions and 28 deletions

View file

@ -0,0 +1,88 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.Random;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
public class Command_lockup 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.MSG_NO_PERMS);
return true;
}
if (args.length != 2)
{
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()
{
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));
sender.sendMessage(ChatColor.GRAY + "Locking up " + p.getName());
}
else if (args[1].equalsIgnoreCase("off"))
{
cancelLockup(playerdata);
sender.sendMessage(ChatColor.GRAY + "Not locking up " + p.getName() + " anymore.");
}
else
{
return false;
}
return true;
}
private void cancelLockup(TFM_UserInfo playerdata)
{
BukkitScheduler scheduler = server.getScheduler();
int lockupScheduleID = playerdata.getLockupScheduleID();
if (lockupScheduleID != -1)
{
scheduler.cancelTask(lockupScheduleID);
playerdata.setLockupScheduleID(-1);
}
}
}

View file

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -24,34 +25,7 @@ public class Command_permban extends TFM_Command
if (args[0].equalsIgnoreCase("list"))
{
if (TotalFreedomMod.permbanned_players.size() > 0)
{
TFM_Util.playerMsg(sender, "No permanently banned player names.");
}
else
{
TFM_Util.playerMsg(sender, TotalFreedomMod.permbanned_players.size() + " permanently banned players:");
for (String player_name : TotalFreedomMod.permbanned_players)
{
TFM_Util.playerMsg(sender, "- " + player_name);
}
}
if (TotalFreedomMod.permbanned_ips.size() > 0)
{
TFM_Util.playerMsg(sender, "No permanently banned IPs.");
}
else
{
TFM_Util.playerMsg(sender, TotalFreedomMod.permbanned_ips.size() + " permanently banned IPs:");
for (String ip_address : TotalFreedomMod.permbanned_ips)
{
TFM_Util.playerMsg(sender, "- " + ip_address);
}
}
dumplist(sender);
return true;
}
@ -63,10 +37,41 @@ public class Command_permban extends TFM_Command
if (args[0].equalsIgnoreCase("reload"))
{
TFM_Util.playerMsg(sender, "Reloading permban list...", ChatColor.RED);
plugin.loadPermbanConfig();
dumplist(sender);
return true;
}
return false;
}
private void dumplist(CommandSender sender)
{
if (TotalFreedomMod.permbanned_players.isEmpty())
{
TFM_Util.playerMsg(sender, "No permanently banned player names.");
}
else
{
TFM_Util.playerMsg(sender, TotalFreedomMod.permbanned_players.size() + " permanently banned players:");
for (String player_name : TotalFreedomMod.permbanned_players)
{
TFM_Util.playerMsg(sender, "- " + player_name);
}
}
if (TotalFreedomMod.permbanned_ips.isEmpty())
{
TFM_Util.playerMsg(sender, "No permanently banned IPs.");
}
else
{
TFM_Util.playerMsg(sender, TotalFreedomMod.permbanned_ips.size() + " permanently banned IPs:");
for (String ip_address : TotalFreedomMod.permbanned_ips)
{
TFM_Util.playerMsg(sender, "- " + ip_address);
}
}
}
}

View file

@ -0,0 +1,47 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
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;
public class Command_potion 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;
}
if (args.length < 1)
{
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;
}
}

View file

@ -37,6 +37,7 @@ public class TFM_UserInfo
private int mp44_schedule_id = -1;
private boolean mp44_armed = false;
private boolean mp44_firing = false;
private int lockup_schedule_id = -1;
public static Map<Player, TFM_UserInfo> userinfo = new HashMap<Player, TFM_UserInfo>();
private TFM_UserInfo(Player player)
@ -348,4 +349,14 @@ public class TFM_UserInfo
{
this.is_halted = is_halted;
}
public int getLockupScheduleID()
{
return lockup_schedule_id;
}
public void setLockupScheduleID(int lockup_schedule_id)
{
this.lockup_schedule_id = lockup_schedule_id;
}
}

View file

@ -95,6 +95,9 @@ commands:
description: Lists the real names of all online players.
usage: /<command>
aliases: [who]
lockup:
description: Console command - Block target's minecraft input. This is evil, and I never should have wrote it.
usage: /<command> <partialname> <on | off>
moblimiter:
description: Owner command - Controll mob rezzing parameters.
usage: /<command> <on|off|setmax <count>|dragon|giant|ghast|slime>
@ -131,6 +134,9 @@ commands:
permban:
description: Manage permanently banned players and IPs
usage: /<command> <list | reload>
# potion:
# description: Manipulate potion effects.
# usage: /<command> <list>
prelog:
description: Superadmin command - Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages.
usage: /<command> <on | off>