Added TFM based tempban.

Blocked vanilla admin commands.
This commit is contained in:
Steven Lawson 2012-09-16 17:18:30 -04:00
parent 90e696a5b0
commit b323b6318b
4 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,69 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.text.SimpleDateFormat;
import java.util.Date;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Command_tempban extends TFM_Command
{
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
if (!(senderIsConsole || TFM_Util.isUserSuperadmin(sender)))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
Player p;
try
{
p = getPlayer(args[0]);
}
catch (CantFindPlayerException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
StringBuilder bcast_msg = new StringBuilder("Temporarily banned " + p.getName());
Date ban_duration = TFM_Util.parseDateOffset("30m");
if (args.length >= 2)
{
Date parsed_offset = TFM_Util.parseDateOffset(args[1]);
if (parsed_offset != null)
{
ban_duration = parsed_offset;
}
}
bcast_msg.append(" until ").append(date_format.format(ban_duration));
String ban_reason = "Banned by " + sender.getName();
if (args.length >= 3)
{
ban_reason = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ") + " (" + sender.getName() + ")";
bcast_msg.append(", Reason: \"").append(ban_reason).append("\"");
}
TFM_Util.adminAction(sender.getName(), bcast_msg.toString(), true);
TFM_Util.banUsername(p.getName(), ban_reason, sender.getName(), ban_duration);
TFM_Util.banIP(p.getAddress().getAddress().getHostAddress().trim(), ban_reason, sender.getName(), ban_duration);
p.kickPlayer(sender.getName() + " - " + bcast_msg.toString());
return true;
}
}

View File

@ -444,6 +444,31 @@ public class TFM_PlayerListener implements Listener
p.sendMessage(ChatColor.GRAY + "This server now uses DisguiseCraft instead of MobDisguise. Type /d to disguise and /u to undisguise."); p.sendMessage(ChatColor.GRAY + "This server now uses DisguiseCraft instead of MobDisguise. Type /d to disguise and /u to undisguise.");
block_command = true; block_command = true;
} }
else if (Pattern.compile("^/ban").matcher(command).find())
{
if (!Pattern.compile("^/banlist").matcher(command).find())
{
block_command = true;
}
}
else if (Pattern.compile("^/kick").matcher(command).find())
{
if (!TFM_Util.isUserSuperadmin(p))
{
block_command = true;
}
}
else if (Pattern.compile("^/kill").matcher(command).find())
{
if (!TFM_Util.isUserSuperadmin(p))
{
block_command = true;
}
}
else if (Pattern.compile("^/pardon").matcher(command).find())
{
block_command = true;
}
} }
if (block_command) if (block_command)

View File

@ -5,6 +5,8 @@ import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.util.*; import java.util.*;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -822,6 +824,111 @@ public class TFM_Util
ipBans.removeExpired(); ipBans.removeExpired();
return ipBans.getEntries().containsKey(ip); return ipBans.getEntries().containsKey(ip);
} }
public static Date parseDateOffset(String time)
{
Pattern timePattern = Pattern.compile(
"(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?"
+ "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?"
+ "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?"
+ "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?"
+ "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?"
+ "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?"
+ "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE);
Matcher m = timePattern.matcher(time);
int years = 0;
int months = 0;
int weeks = 0;
int days = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
boolean found = false;
while (m.find())
{
if (m.group() == null || m.group().isEmpty())
{
continue;
}
for (int i = 0; i < m.groupCount(); i++)
{
if (m.group(i) != null && !m.group(i).isEmpty())
{
found = true;
break;
}
}
if (found)
{
if (m.group(1) != null && !m.group(1).isEmpty())
{
years = Integer.parseInt(m.group(1));
}
if (m.group(2) != null && !m.group(2).isEmpty())
{
months = Integer.parseInt(m.group(2));
}
if (m.group(3) != null && !m.group(3).isEmpty())
{
weeks = Integer.parseInt(m.group(3));
}
if (m.group(4) != null && !m.group(4).isEmpty())
{
days = Integer.parseInt(m.group(4));
}
if (m.group(5) != null && !m.group(5).isEmpty())
{
hours = Integer.parseInt(m.group(5));
}
if (m.group(6) != null && !m.group(6).isEmpty())
{
minutes = Integer.parseInt(m.group(6));
}
if (m.group(7) != null && !m.group(7).isEmpty())
{
seconds = Integer.parseInt(m.group(7));
}
break;
}
}
if (!found)
{
return null;
}
Calendar c = new GregorianCalendar();
if (years > 0)
{
c.add(Calendar.YEAR, years);
}
if (months > 0)
{
c.add(Calendar.MONTH, months);
}
if (weeks > 0)
{
c.add(Calendar.WEEK_OF_YEAR, weeks);
}
if (days > 0)
{
c.add(Calendar.DAY_OF_MONTH, days);
}
if (hours > 0)
{
c.add(Calendar.HOUR_OF_DAY, hours);
}
if (minutes > 0)
{
c.add(Calendar.MINUTE, minutes);
}
if (seconds > 0)
{
c.add(Calendar.SECOND, seconds);
}
return c.getTime();
}
// I wrote all this before i discovered getTargetBlock >.> - might come in handy some day... // I wrote all this before i discovered getTargetBlock >.> - might come in handy some day...
// public static final double LOOKAT_VIEW_HEIGHT = 1.65; // public static final double LOOKAT_VIEW_HEIGHT = 1.65;
// public static final double LOOKAT_STEP_DISTANCE = 0.2; // public static final double LOOKAT_STEP_DISTANCE = 0.2;

View File

@ -163,12 +163,16 @@ commands:
stfu: stfu:
description: Superadmin Command - Mutes a player with brute force. description: Superadmin Command - Mutes a player with brute force.
usage: /<command> [list | purge | <player>] usage: /<command> [list | purge | <player>]
aliases: [mute]
stop: stop:
description: Superadmin command - Kicks everyone and stops the server. description: Superadmin command - Kicks everyone and stops the server.
usage: /<command> usage: /<command>
survival: survival:
description: Quickly change your own gamemode to survival, or define someone's username to change theirs. description: Quickly change your own gamemode to survival, or define someone's username to change theirs.
usage: /<command> [partialname] usage: /<command> [partialname]
tempban:
description: Superadmin Command - Temporarily ban someone.
usage: /<command> [playername] [duration] [reason]
terminal: terminal:
description: Execute a system command. description: Execute a system command.
usage: /<command> <syscmd> usage: /<command> <syscmd>