This commit is contained in:
Jerom van der Sar 2012-09-17 16:07:16 +02:00
commit 9fcc195959
5 changed files with 230 additions and 27 deletions

View File

@ -16,16 +16,17 @@ public class Command_smite extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (!TFM_Util.isUserSuperadmin(sender))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
}
if (args.length != 1) if (args.length != 1)
{ {
return false; return false;
} }
if (!TFM_Util.isUserSuperadmin(sender))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
Player p; Player p;
try try
{ {

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,11 +444,41 @@ 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("^/gamemode").matcher(command).find())
{
p.sendMessage(ChatColor.GRAY + "Use /creative and /survival to set your gamemode.");
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)
{ {
p.sendMessage(ChatColor.RED + "That command is prohibited."); p.sendMessage(ChatColor.GRAY + "That command is blocked.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

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;
@ -622,36 +624,28 @@ public class TFM_Util
{ {
case STRIKE_ONE: case STRIKE_ONE:
{ {
//Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("tempban %s 1m", p.getName())); Calendar c = new GregorianCalendar();
c.add(Calendar.MINUTE, 1);
Calendar calendar = Calendar.getInstance(); Date expires = c.getTime();
calendar.setTime(new Date());
calendar.add(Calendar.MINUTE, 1);
Date expires = calendar.getTime();
TFM_Util.banIP(player_ip, null, null, expires);
TFM_Util.banUsername(p.getName(), null, null, expires);
TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned for 1 minute."); TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned for 1 minute.");
TFM_Util.banIP(player_ip, kickMessage, "AutoEject", expires);
TFM_Util.banUsername(p.getName(), kickMessage, "AutoEject", expires);
p.kickPlayer(kickMessage); p.kickPlayer(kickMessage);
break; break;
} }
case STRIKE_TWO: case STRIKE_TWO:
{ {
//Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("tempban %s 3m", p.getName())); Calendar c = new GregorianCalendar();
c.add(Calendar.MINUTE, 3);
Calendar calendar = Calendar.getInstance(); Date expires = c.getTime();
calendar.setTime(new Date());
calendar.add(Calendar.MINUTE, 3);
Date expires = calendar.getTime();
TFM_Util.banIP(player_ip, null, null, expires);
TFM_Util.banUsername(p.getName(), null, null, expires);
TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned for 3 minutes."); TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned for 3 minutes.");
TFM_Util.banIP(player_ip, kickMessage, "AutoEject", expires);
TFM_Util.banUsername(p.getName(), kickMessage, "AutoEject", expires);
p.kickPlayer(kickMessage); p.kickPlayer(kickMessage);
break; break;
@ -659,13 +653,13 @@ public class TFM_Util
case STRIKE_THREE: case STRIKE_THREE:
{ {
//Bukkit.banIP(player_ip); //Bukkit.banIP(player_ip);
TFM_Util.banIP(player_ip, null, null, null); TFM_Util.banIP(player_ip, kickMessage, "AutoEject", null);
String[] ip_address_parts = player_ip.split("\\."); String[] ip_address_parts = player_ip.split("\\.");
//Bukkit.banIP(); //Bukkit.banIP();
TFM_Util.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", null, null, null); TFM_Util.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", kickMessage, "AutoEject", null);
//p.setBanned(true); //p.setBanned(true);
TFM_Util.banUsername(p.getName(), null, null, null); TFM_Util.banUsername(p.getName(), kickMessage, "AutoEject", null);
TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned permanently."); TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned permanently.");
@ -822,6 +816,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

@ -166,12 +166,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>