mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Merge branch 'master' of https://github.com/StevenLawson/TotalFreedomMod
This commit is contained in:
commit
9fcc195959
@ -16,16 +16,17 @@ public class Command_smite extends TFM_Command
|
||||
@Override
|
||||
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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TFM_Util.isUserSuperadmin(sender))
|
||||
{
|
||||
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p;
|
||||
try
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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.");
|
||||
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)
|
||||
{
|
||||
p.sendMessage(ChatColor.RED + "That command is prohibited.");
|
||||
p.sendMessage(ChatColor.GRAY + "That command is blocked.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
@ -622,36 +624,28 @@ public class TFM_Util
|
||||
{
|
||||
case STRIKE_ONE:
|
||||
{
|
||||
//Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("tempban %s 1m", p.getName()));
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
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);
|
||||
Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.MINUTE, 1);
|
||||
Date expires = c.getTime();
|
||||
|
||||
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);
|
||||
|
||||
break;
|
||||
}
|
||||
case STRIKE_TWO:
|
||||
{
|
||||
//Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("tempban %s 3m", p.getName()));
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
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);
|
||||
Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.MINUTE, 3);
|
||||
Date expires = c.getTime();
|
||||
|
||||
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);
|
||||
|
||||
break;
|
||||
@ -659,13 +653,13 @@ public class TFM_Util
|
||||
case STRIKE_THREE:
|
||||
{
|
||||
//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("\\.");
|
||||
//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);
|
||||
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.");
|
||||
|
||||
@ -822,6 +816,111 @@ public class TFM_Util
|
||||
ipBans.removeExpired();
|
||||
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...
|
||||
// public static final double LOOKAT_VIEW_HEIGHT = 1.65;
|
||||
// public static final double LOOKAT_STEP_DISTANCE = 0.2;
|
||||
|
@ -166,12 +166,16 @@ commands:
|
||||
stfu:
|
||||
description: Superadmin Command - Mutes a player with brute force.
|
||||
usage: /<command> [list | purge | <player>]
|
||||
aliases: [mute]
|
||||
stop:
|
||||
description: Superadmin command - Kicks everyone and stops the server.
|
||||
usage: /<command>
|
||||
survival:
|
||||
description: Quickly change your own gamemode to survival, or define someone's username to change theirs.
|
||||
usage: /<command> [partialname]
|
||||
tempban:
|
||||
description: Superadmin Command - Temporarily ban someone.
|
||||
usage: /<command> [playername] [duration] [reason]
|
||||
terminal:
|
||||
description: Execute a system command.
|
||||
usage: /<command> <syscmd>
|
||||
|
Loading…
Reference in New Issue
Block a user