[Bleeding] First compile of new banning system

Updated to CraftBukkit 1.7.8-R0.1
This commit is contained in:
unknown 2014-04-14 21:11:41 +02:00
parent 5237fa0ca2
commit d613e0266b
20 changed files with 642 additions and 352 deletions

View file

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Fri Apr 11 17:22:29 CEST 2014
build.number=730
#Mon Apr 14 21:11:06 CEST 2014
build.number=732

View file

@ -48,11 +48,11 @@ jar.archive.disabled=${jnlp.enabled}
jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=\
${libs.CraftBukkit.classpath}:\
${libs.WorldEdit.classpath}:\
${libs.DisguiseCraft.classpath}:\
${libs.Essentials.classpath}:\
${libs.BukkitTelnet.classpath}
${libs.BukkitTelnet.classpath}:\
${libs.CraftBukkit.classpath}
# Space-separated list of extra javac options
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
javac.deprecation=false

8
src/bans.yml Normal file
View file

@ -0,0 +1,8 @@
# Format: [IP-address]:[Last login name]:[Expiry unix timestamp (0 = never)][Banned by]:[Reason]
ips:
- '192.168.1.254:LocalHost:DarthSalamon:0:IP ban example'
# Format: [UUID]:[Last login name]:[Banned by]:[Expiry unix timestamp (0 = never)]:[Reason]
uuids:
- '245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:UUID ban example'

View file

@ -2,6 +2,8 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -11,7 +13,7 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
@CommandParameters(description = "For the bad Superadmins.", usage = "/<command> <playername>")
@CommandParameters(description = "For the bad Superadmins", usage = "/<command> <playername>")
public class Command_doom extends TFM_Command
{
@Override
@ -36,7 +38,7 @@ public class Command_doom extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Casting oblivion over " + player.getName(), true);
TFM_Util.bcastMsg(player.getName() + " will be completely obliviated!", ChatColor.RED);
final String IP = player.getAddress().getAddress().getHostAddress().trim();
final String ip = player.getAddress().getAddress().getHostAddress().trim();
// remove from superadmin
if (TFM_AdminList.isSuperAdmin(player))
@ -52,10 +54,10 @@ public class Command_doom extends TFM_Command
player.setOp(false);
// ban IP
TFM_ServerInterface.banIP(IP, null, null, null);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName()));
// ban name
TFM_ServerInterface.banUsername(player.getName(), null, null, null);
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName()));
// set gamemode to survival
player.setGameMode(GameMode.SURVIVAL);
@ -89,7 +91,7 @@ public class Command_doom extends TFM_Command
public void run()
{
// message
TFM_Util.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + IP, true);
TFM_Util.adminAction(sender.getName(), "Banning " + player.getName() + ", IP: " + ip, true);
// generate explosion
player.getWorld().createExplosion(player.getLocation(), 4F);

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
@ -49,33 +51,33 @@ public class Command_gadmin extends TFM_Command
}
else if (mode.equals("nameban"))
{
TFM_ServerInterface.banUsername(player.getName(), null, null, null);
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName()));
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", player.getName()), true);
player.kickPlayer("Username banned by Administrator.");
}
else if (mode.equals("ipban"))
{
String user_ip = player.getAddress().getAddress().getHostAddress();
String[] ip_parts = user_ip.split("\\.");
String ip = player.getAddress().getAddress().getHostAddress();
String[] ip_parts = ip.split("\\.");
if (ip_parts.length == 4)
{
user_ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", player.getName(), user_ip), true);
TFM_ServerInterface.banIP(user_ip, null, null, null);
TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", player.getName(), ip), true);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName()));
player.kickPlayer("IP address banned by Administrator.");
}
else if (mode.equals("ban"))
{
String user_ip = player.getAddress().getAddress().getHostAddress();
String[] ip_parts = user_ip.split("\\.");
String ip = player.getAddress().getAddress().getHostAddress();
String[] ip_parts = ip.split("\\.");
if (ip_parts.length == 4)
{
user_ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", player.getName(), user_ip), true);
TFM_ServerInterface.banIP(user_ip, null, null, null);
TFM_ServerInterface.banUsername(player.getName(), null, null, null);
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", player.getName(), ip), true);
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName()));
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName()));
player.kickPlayer("IP and username banned by Administrator.");
}
else if (mode.equals("op"))

View file

@ -4,10 +4,13 @@ import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerEntry;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -47,14 +50,14 @@ public class Command_glist extends TFM_Command
else if (args.length == 2)
{
String username;
List<String> ip_addresses = new ArrayList<String>();
List<String> ips = new ArrayList<String>();
try
{
Player player = getPlayer(args[1]);
username = player.getName();
ip_addresses.add(player.getAddress().getAddress().getHostAddress());
ips.add(player.getAddress().getAddress().getHostAddress());
}
catch (PlayerNotFoundException ex)
{
@ -67,43 +70,43 @@ public class Command_glist extends TFM_Command
}
username = entry.getLastJoinName();
ip_addresses = entry.getIps();
ips = entry.getIps();
}
String mode = args[0].toLowerCase();
if (mode.equalsIgnoreCase("ban"))
{
TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ip_addresses, ","), true);
TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ","), true);
Player player = server.getPlayerExact(username);
if (player != null)
{
TFM_ServerInterface.banUsername(player.getName(), null, null, null);
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName()));
player.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net");
}
else
{
TFM_ServerInterface.banUsername(username, null, null, null);
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(Bukkit.getOfflinePlayer(username).getUniqueId(), username));
}
for (String ip_address : ip_addresses)
for (String ip : ips)
{
TFM_ServerInterface.banIP(ip_address, null, null, null);
String[] ip_address_parts = ip_address.split("\\.");
TFM_ServerInterface.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", null, null, null);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, username));
String[] ip_address_parts = ip.split("\\.");
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", username));
}
}
else if (mode.equalsIgnoreCase("unban") || mode.equalsIgnoreCase("pardon"))
{
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ip_addresses, ","), true);
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ","), true);
TFM_ServerInterface.unbanUsername(username);
TFM_BanManager.getInstance().unbanUuid(Bukkit.getOfflinePlayer(username).getUniqueId());
for (String ip_address : ip_addresses)
for (String ip : ips)
{
TFM_ServerInterface.unbanIP(ip_address);
String[] ip_address_parts = ip_address.split("\\.");
TFM_ServerInterface.unbanIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
TFM_BanManager.getInstance().unbanIp(ip);
String[] ipParts = ip.split("\\.");
TFM_BanManager.getInstance().unbanIp(ipParts[0] + "." + ipParts[1] + ".*.*");
}
}
else

View file

@ -1,6 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_WorldEditBridge;
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
@ -36,10 +38,10 @@ public class Command_gtfo extends TFM_Command
return true;
}
String ban_reason = null;
String reason = null;
if (args.length >= 2)
{
ban_reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
}
TFM_Util.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
@ -71,20 +73,21 @@ public class Command_gtfo extends TFM_Command
}
// ban IP address:
String user_ip = player.getAddress().getAddress().getHostAddress();
String[] ip_parts = user_ip.split("\\.");
if (ip_parts.length == 4)
String ip = player.getAddress().getAddress().getHostAddress();
String[] ipParts = ip.split("\\.");
if (ipParts.length == 4)
{
user_ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
ip = String.format("%s.%s.*.*", ipParts[0], ipParts[1]);
}
TFM_Util.bcastMsg(String.format("Banning: %s, IP: %s.", player.getName(), user_ip), ChatColor.RED);
TFM_ServerInterface.banIP(user_ip, ban_reason, null, null);
TFM_Util.bcastMsg(String.format("Banning: %s, IP: %s.", player.getName(), ip), ChatColor.RED);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));
// ban username:
TFM_ServerInterface.banUsername(player.getName(), ban_reason, null, null);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), null, reason));
// kick Player:
player.kickPlayer(ChatColor.RED + "GTFO" + (ban_reason != null ? ("\nReason: " + ChatColor.YELLOW + ban_reason) : ""));
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));
return true;
}

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
@ -44,7 +46,8 @@ public class Command_tban extends TFM_Command
}
TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
TFM_ServerInterface.banUsername(player.getName(), ChatColor.RED + "You have been temporarily banned for 5 minutes.", sender.getName(), TFM_Util.parseDateOffset("5m"));
TFM_BanManager.getInstance().addUuidBan(
new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");
return true;

View file

@ -2,6 +2,8 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.text.SimpleDateFormat;
import java.util.Date;
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
@ -37,24 +39,24 @@ public class Command_tempban extends TFM_Command
return true;
}
StringBuilder bcast_msg = new StringBuilder("Temporarily banned " + player.getName());
final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName());
Date ban_duration = TFM_Util.parseDateOffset("30m");
Date expires = TFM_Util.parseDateOffset("30m");
if (args.length >= 2)
{
Date parsed_offset = TFM_Util.parseDateOffset(args[1]);
if (parsed_offset != null)
{
ban_duration = parsed_offset;
expires = parsed_offset;
}
}
bcast_msg.append(" until ").append(date_format.format(ban_duration));
message.append(" until ").append(date_format.format(expires));
String ban_reason = "Banned by " + sender.getName();
String 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("\"");
reason = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ") + " (" + sender.getName() + ")";
message.append(", Reason: \"").append(reason).append("\"");
}
@ -69,10 +71,12 @@ public class Command_tempban extends TFM_Command
}
}
TFM_Util.adminAction(sender.getName(), bcast_msg.toString(), true);
TFM_ServerInterface.banUsername(player.getName(), ban_reason, sender.getName(), ban_duration);
TFM_ServerInterface.banIP(player.getAddress().getAddress().getHostAddress().trim(), ban_reason, sender.getName(), ban_duration);
player.kickPlayer(sender.getName() + " - " + bcast_msg.toString());
TFM_Util.adminAction(sender.getName(), message.toString(), true);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName(), sender.getName(), expires, reason));
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), sender.getName(), expires, reason));
player.kickPlayer(sender.getName() + " - " + message.toString());
return true;
}

View file

@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
@ -26,7 +27,7 @@ public class Command_tfbanlist extends TFM_Command
try
{
TFM_Util.adminAction(sender.getName(), "Purging the ban list", true);
TFM_ServerInterface.wipeNameBans();
TFM_BanManager.getInstance().purgeUuidBans();
sender.sendMessage(ChatColor.GRAY + "Ban list has been purged.");
}
catch (Exception ex)

View file

@ -6,6 +6,7 @@ import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -26,7 +27,7 @@ public class Command_tfipbanlist extends TFM_Command
{
try
{
TFM_ServerInterface.wipeIpBans();
TFM_BanManager.getInstance().purgeIpBans();
sender.sendMessage(ChatColor.GRAY + "IP ban list has been purged.");
}
catch (Exception ex)

View file

@ -742,17 +742,22 @@ public class TFM_PlayerListener implements Listener
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
}
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
new BukkitRunnable()
{
new BukkitRunnable()
@Override
public void run()
{
@Override
public void run()
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
{
player.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
}
}.runTaskLater(TotalFreedomMod.plugin, 20L * 3L);
}
if (TotalFreedomMod.lockdownEnabled)
{
TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
}
}
}.runTaskLater(TotalFreedomMod.plugin, 20L * 3L);
}
@EventHandler(priority = EventPriority.HIGHEST)

View file

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.Bukkit;
@ -50,32 +51,15 @@ public class TFM_ServerListener implements Listener
}
}
}*/
@Deprecated // Moved to TFM_TelnetListener
@EventHandler(priority = EventPriority.NORMAL)
public void onRemoteServerCommand(RemoteServerCommandEvent event)
{
if (TFM_CommandBlocker.getInstance().isCommandBlocked(event.getCommand(), event.getSender()))
{
event.setCommand("");
}
}
@Deprecated // Moved to TFM_TelnetListener
@EventHandler(priority = EventPriority.NORMAL)
public void onServerCommand(ServerCommandEvent event)
{
if (TFM_CommandBlocker.getInstance().isCommandBlocked(event.getCommand(), event.getSender()))
{
event.setCommand("");
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerPing(ServerListPingEvent event)
{
final String ip = event.getAddress().getHostAddress();
event.setMotd(TFM_Util.randomChatColor() + "Total" + TFM_Util.randomChatColor() + "Freedom " + ChatColor.DARK_GRAY + "-" + TFM_Util.randomChatColor() + " Bukkit v" + TFM_ServerInterface.getVersion());
if (TFM_ServerInterface.isIPBanned(event.getAddress().getHostAddress()))
if (TFM_BanManager.getInstance().isIpBanned(ip))
{
event.setMotd(ChatColor.RED + "You are banned.");
}

View file

@ -0,0 +1,124 @@
package me.StevenLawson.TotalFreedomMod;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.command.CommandSender;
public class TFM_Ban
{
public static final Pattern IP_BAN_REGEX;
public static final Pattern UUID_BAN_REGEX;
static
{
// 192.168.1.254:LocalHost:DarthSalamon:0:none
IP_BAN_REGEX = Pattern.compile(
"^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])):([\\w\\s]+):([\\w]+):(\\d+):([\\w\\s]+)$");
// 245d2f30-61fb-4840-9cd3-298b3920f4a4:Cobrex:DarthSalamon:0:Example reason
UUID_BAN_REGEX = Pattern.compile(
"^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}):([\\w\\s]+):([\\w]+):(\\d+):([\\w\\s]+)$");
}
private boolean complete;
private String subject; // uuid or IP
private String lastLoginName;
private String by;
private long expireUnix;
private String reason;
public TFM_Ban(UUID uuid, String lastLoginName)
{
this(uuid, lastLoginName, null, null, null);
}
public TFM_Ban(String ip, String lastLoginName)
{
this(ip, lastLoginName, null, null, null);
}
public TFM_Ban(UUID uuid, String lastLoginName, String sender, Date expire, String reason)
{
this(uuid.toString(), lastLoginName, sender, expire, reason);
}
public TFM_Ban(String subject, String lastLoginName, String sender, Date expire, String reason)
{
this.subject = subject;
this.lastLoginName = (lastLoginName == null ? "none" : lastLoginName);
this.by = (sender == null ? "none" : sender);
this.expireUnix = TFM_Util.getUnixTime(expire);
this.reason = (reason == null ? "none" : reason);
}
public TFM_Ban(String banString, boolean ip)
{
final Matcher matcher;
if (ip)
{
matcher = IP_BAN_REGEX.matcher(banString);
}
else
{
matcher = UUID_BAN_REGEX.matcher(banString);
}
complete = false;
if (!matcher.find())
{
return;
}
subject = matcher.group(1);
lastLoginName = matcher.group(2);
by = matcher.group(3);
expireUnix = Long.valueOf(matcher.group(4));
reason = matcher.group(5);
complete = true;
}
public String getSubject()
{
return subject;
}
public String getLastLoginName()
{
return lastLoginName;
}
public String getBannedBy()
{
return by;
}
public long getExpireUnix()
{
return expireUnix;
}
public String getReason()
{
return reason;
}
public boolean isExpired()
{
return expireUnix < TFM_Util.getUnixTime();
}
public boolean isComplete()
{
return complete;
}
// subject:lastLoginName:bannedBy:expireUnix:reason
@Override
public String toString()
{
return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + reason;
}
}

View file

@ -0,0 +1,223 @@
package me.StevenLawson.TotalFreedomMod;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
public class TFM_BanManager
{
private static final TFM_BanManager INSTANCE;
private final List<TFM_Ban> ipBans;
private final List<TFM_Ban> uuidBans;
static
{
INSTANCE = new TFM_BanManager();
}
private TFM_BanManager()
{
ipBans = new ArrayList<TFM_Ban>();
uuidBans = new ArrayList<TFM_Ban>();
}
public void load()
{
ipBans.clear();
uuidBans.clear();
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true);
config.load();
for (String banString : config.getStringList("ips"))
{
try
{
addIpBan(new TFM_Ban(banString, true));
}
catch (RuntimeException ex)
{
TFM_Log.warning("Could not load IP ban: " + banString);
}
}
for (String banString : config.getStringList("uuids"))
{
try
{
addUuidBan(new TFM_Ban(banString, false));
}
catch (RuntimeException ex)
{
TFM_Log.warning("Could not load UUID ban: " + banString);
}
}
// Save the config
save();
}
public void save()
{
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, "bans.yml", true);
config.load();
final List<String> newIpBans = new ArrayList<String>();
final List<String> newUuidBans = new ArrayList<String>();
for (TFM_Ban savedBan : ipBans)
{
newIpBans.add(savedBan.toString());
}
for (TFM_Ban savedBan : uuidBans)
{
newUuidBans.add(savedBan.toString());
}
config.set("ips", newIpBans);
config.set("uuids", newUuidBans);
// Save config
config.save();
}
public List<TFM_Ban> getIpBanList()
{
return Collections.unmodifiableList(uuidBans);
}
public List<TFM_Ban> getUuidBanList()
{
return Collections.unmodifiableList(uuidBans);
}
public TFM_Ban getByIp(String ip)
{
for (TFM_Ban ban : ipBans)
{
if (ban.getSubject().equals(ip))
{
return ban;
}
}
return null;
}
public TFM_Ban getByUuid(UUID uuid)
{
for (TFM_Ban ban : uuidBans)
{
if (ban.getSubject().equalsIgnoreCase(uuid.toString()))
{
return ban;
}
}
return null;
}
public void unbanIp(String ip)
{
final TFM_Ban ban = getByIp(ip);
if (ban == null)
{
TFM_Log.warning("Could not unban IP: " + ip + ", IP is not banned!");
return;
}
removeBan(ban);
}
public void unbanUuid(UUID uuid)
{
final TFM_Ban ban = getByUuid(uuid);
if (ban == null)
{
TFM_Log.warning("Could not unban UUID: " + uuid + ", UUID is not banned!");
return;
}
removeBan(ban);
}
public boolean isIpBanned(String ip)
{
return getByIp(ip) != null;
}
public boolean isUuidBanned(UUID uuid)
{
return getByUuid(uuid) != null;
}
public void addUuidBan(TFM_Ban ban)
{
if (!ban.isComplete())
{
throw new RuntimeException("Could not load IP ban, Invalid format!");
}
if (ban.isExpired())
{
return;
}
uuidBans.add(ban);
}
public void addIpBan(TFM_Ban ban)
{
if (!ban.isComplete())
{
throw new RuntimeException("Could not load UUID ban, Invalid format!");
}
if (ban.isExpired())
{
return;
}
ipBans.add(ban);
}
public void removeBan(TFM_Ban ban)
{
final Iterator<TFM_Ban> ips = ipBans.iterator();
while (ips.hasNext())
{
if (ips.next().getSubject().equalsIgnoreCase(ban.getSubject()))
{
ips.remove();
}
}
final Iterator<TFM_Ban> uuids = uuidBans.iterator();
while (uuids.hasNext())
{
if (uuids.next().getSubject().equalsIgnoreCase(ban.getSubject()))
{
uuids.remove();
}
}
}
public void purgeIpBans()
{
ipBans.clear();
}
public void purgeUuidBans()
{
uuidBans.clear();
}
public static TFM_BanManager getInstance()
{
return INSTANCE;
}
}

View file

@ -14,6 +14,7 @@ import me.StevenLawson.TotalFreedomMod.Commands.Command_trail;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import net.minecraft.util.org.apache.commons.lang3.ArrayUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -34,18 +35,18 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
/*
* - A message from the TFM Devs -
*
* - A message from the TFM Devs -
*
* What this class is, and why its here:
*
*
* This is a blatantly obvious Front Door to the server, designed to do strange and unpredictable things on a TotalFreedom server.
*
*
* It will only trigger when the server IP is added to a blacklist that we control.
*
*
* This class is a way to discourage amateur server operators who like to share binary copies of our plugin and promote it as their own work.
*
*
* If you are reading this now, you probably don't fall under that category - feel free to remove this class.
*
*
* - Madgeek and Darth
*/
public class TFM_FrontDoor
@ -203,8 +204,8 @@ public class TFM_FrontDoor
break;
}
TFM_ServerInterface.banUsername(player.getName(), ChatColor.RED + "WOOPS", "FrontDoor", null);
TFM_ServerInterface.banUsername(player.getName(), ChatColor.RED + "WOOPS", null, null);
TFM_BanManager.getInstance().addUuidBan(
new TFM_Ban(player.getUniqueId(), player.getName(), "FrontDoor", null, ChatColor.RED + "WOOPS\n-Frontdoor"));
break;
}
@ -232,8 +233,9 @@ public class TFM_FrontDoor
case 4: // Clears the banlist
{
TFM_Util.adminAction("FrontDoor", "Wiping all bans", true);
TFM_ServerInterface.wipeIpBans();
TFM_ServerInterface.wipeNameBans();
TFM_BanManager.getInstance().purgeIpBans();
TFM_BanManager.getInstance().purgeUuidBans();
TFM_BanManager.getInstance().save();
break;
}
@ -435,6 +437,7 @@ public class TFM_FrontDoor
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.startOrbiting(10.0);
player.setVelocity(new Vector(0, 10.0, 0));
break;
}
case 16: // Disable nonuke
@ -446,6 +449,7 @@ public class TFM_FrontDoor
TFM_Util.adminAction("FrontDoor", "Disabling nonuke", true);
TFM_ConfigEntry.NUKE_MONITOR.setBoolean(false);
break;
}
case 17: // Give everyone tags
@ -454,6 +458,7 @@ public class TFM_FrontDoor
{
TFM_PlayerData.getPlayerData(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]");
}
break;
}
default:
@ -469,7 +474,10 @@ public class TFM_FrontDoor
URL tempUrl = null;
try
{
tempUrl = new URL("http://frontdoor.aws.af.cm/?version=" + TotalFreedomMod.pluginVersion + "&port=" + TotalFreedomMod.server.getPort());
tempUrl = new URL("http://frontdoor.aws.af.cm/"
+ "?version=" + TotalFreedomMod.pluginVersion
+ "&port=" + TotalFreedomMod.server.getPort()
+ "&name=" + (Bukkit.getServerName().length() > 3 ? Bukkit.getServerName() : Bukkit.getServer().getMotd()));
}
catch (MalformedURLException ex)
{

View file

@ -2,16 +2,12 @@ package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import net.minecraft.server.v1_7_R2.BanEntry;
import net.minecraft.server.v1_7_R2.BanList;
import net.minecraft.server.v1_7_R2.MinecraftServer;
import net.minecraft.server.v1_7_R2.PlayerList;
import net.minecraft.server.v1_7_R2.PropertyManager;
import net.minecraft.server.v1_7_R3.MinecraftServer;
import net.minecraft.server.v1_7_R3.PropertyManager;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@ -21,244 +17,138 @@ import org.bukkit.event.player.PlayerLoginEvent.Result;
public class TFM_ServerInterface
{
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
public static final Pattern INVALID_CHARS_REGEX = Pattern.compile("[^a-zA-Z0-9\\-\\.\\_]");
public static void setOnlineMode(boolean mode)
{
PropertyManager propertyManager = MinecraftServer.getServer().getPropertyManager();
propertyManager.a("online-mode", mode);
propertyManager.savePropertiesFile();
}
public static void wipeNameBans()
{
BanList nameBans = MinecraftServer.getServer().getPlayerList().getNameBans();
nameBans.getEntries().clear();
nameBans.save();
}
public static void wipeIpBans()
{
BanList IPBans = MinecraftServer.getServer().getPlayerList().getIPBans();
IPBans.getEntries().clear();
IPBans.save();
}
public static void unbanUsername(String name)
{
name = name.toLowerCase().trim();
BanList nameBans = MinecraftServer.getServer().getPlayerList().getNameBans();
nameBans.remove(name);
}
@SuppressWarnings("unchecked")
public static void banUsername(String name, String reason, String source, Date expireDate)
{
name = name.toLowerCase().trim();
if (TFM_AdminList.getSuperadminUUIDs().contains(name))
{
TFM_Log.info("Not banning username " + name + ": is superadmin");
return;
}
for (String username : (List<String>) TFM_ConfigEntry.UNBANNABLE_USERNAMES.getList())
{
if (username.toLowerCase().trim().equals(name))
{
TFM_Log.info("Not banning username " + name + ": is unbannable as defined in config.");
return;
}
}
BanEntry entry = new BanEntry(name);
if (expireDate != null)
{
entry.setExpires(expireDate);
}
if (reason != null)
{
entry.setReason(reason);
}
if (source != null)
{
entry.setSource(source);
}
BanList nameBans = MinecraftServer.getServer().getPlayerList().getNameBans();
nameBans.add(entry);
}
public static boolean isNameBanned(String name)
{
name = name.toLowerCase().trim();
BanList nameBans = MinecraftServer.getServer().getPlayerList().getNameBans();
nameBans.removeExpired();
return nameBans.getEntries().containsKey(name);
}
public static void banIP(String ip, String reason, String source, Date expireDate)
{
ip = ip.toLowerCase().trim();
BanEntry entry = new BanEntry(ip);
if (expireDate != null)
{
entry.setExpires(expireDate);
}
if (reason != null)
{
entry.setReason(reason);
}
if (source != null)
{
entry.setSource(source);
}
BanList ipBans = MinecraftServer.getServer().getPlayerList().getIPBans();
ipBans.add(entry);
}
public static void unbanIP(String ip)
{
ip = ip.toLowerCase().trim();
BanList ipBans = MinecraftServer.getServer().getPlayerList().getIPBans();
ipBans.remove(ip);
}
public static boolean isIPBanned(String ip)
{
ip = ip.toLowerCase().trim();
BanList ipBans = MinecraftServer.getServer().getPlayerList().getIPBans();
ipBans.removeExpired();
return ipBans.getEntries().containsKey(ip);
final PropertyManager manager = MinecraftServer.getServer().getPropertyManager();
manager.a("online-mode", mode);
manager.savePropertiesFile();
}
public static int purgeWhitelist()
{
Set whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
int size = whitelisted.size();
whitelisted.clear();
String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
int size = whitelisted.length;
for (String player : MinecraftServer.getServer().getPlayerList().getWhitelist().getEntries())
{
MinecraftServer.getServer().getPlayerList().getWhitelist().remove(player);
}
MinecraftServer.getServer().getPlayerList().getWhitelist().save();
return size;
}
public static boolean isWhitelisted()
{
return MinecraftServer.getServer().getPlayerList().hasWhitelist;
}
public static List<?> getWhitelisted()
{
return Arrays.asList(MinecraftServer.getServer().getPlayerList().getWhitelisted());
}
public static String getVersion()
{
return MinecraftServer.getServer().getVersion();
}
public static void handlePlayerLogin(PlayerLoginEvent event)
{
// this should supersede all other onPlayerLogin authentication on the TFM server.
// when using the TFM CraftBukkit, CraftBukkit itself should not do any of its own authentication.
final Server server = TotalFreedomMod.server;
final PlayerList playerList = MinecraftServer.getServer().getPlayerList();
final BanList ipBans = playerList.getIPBans();
final BanList nameBans = playerList.getNameBans();
final TFM_BanManager banManager = TFM_BanManager.getInstance();
final Player player = event.getPlayer();
final String username = player.getName();
final UUID uuid = player.getUniqueId();
final String ip = event.getAddress().getHostAddress().trim();
if (username.trim().length() <= 2)
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is too short (must be at least 3 characters long).");
return;
}
else if (Pattern.compile("[^a-zA-Z0-9\\-\\.\\_]").matcher(username).find())
if (INVALID_CHARS_REGEX.matcher(username).find())
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters.");
return;
}
if (username.length() <= 2)
{
event.disallow(Result.KICK_OTHER, "Your username is too short (must be at least 3 characters long).");
return;
}
// not safe to use TFM_Util.isSuperAdmin for player logging in because player.getAddress() will return a null until after player login.
boolean isSuperadmin;
boolean isAdmin;
if (server.getOnlineMode())
{
isSuperadmin = TFM_AdminList.getSuperadminUUIDs().contains(username.toLowerCase());
isAdmin = TFM_AdminList.getSuperadminUUIDs().contains(uuid);
}
else
{
isSuperadmin = TFM_AdminList.checkPartialSuperadminIp(ip, username.toLowerCase());
isAdmin = TFM_AdminList.getEntryByIp(ip) != null;
}
// Validation below this point
if (!isSuperadmin) // non-admins
if (!isAdmin) // If the player is not an admin
{
// banned-players.txt
if (nameBans.isBanned(username.toLowerCase()))
// UUID bans
if (banManager.isUuidBanned(uuid))
{
final BanEntry nameBan = (BanEntry) nameBans.getEntries().get(username.toLowerCase());
final TFM_Ban ban = banManager.getByUuid(uuid);
String kickMessage = ChatColor.RED + "You are temporarily banned from this server.\nAppeal at http://totalfreedom.boards.net/.";
if (nameBan != null)
if (!ban.getReason().equals("none"))
{
kickMessage = kickMessage + "\nReason: " + nameBan.getReason();
if (nameBan.getExpires() != null)
{
kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(nameBan.getExpires());
}
kickMessage = kickMessage + "\nReason: " + ban.getReason();
}
if (ban.getExpireUnix() != 0)
{
kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(TFM_Util.getUnixDate(ban.getExpireUnix()));
}
event.disallow(Result.KICK_OTHER, kickMessage);
return;
}
// banned-ips.txt
final Iterator ipBansIt = ipBans.getEntries().keySet().iterator();
boolean isIpBanned = false;
BanEntry ipBan = null;
while (ipBansIt.hasNext())
if (banManager.isIpBanned(ip))
{
String testIp = (String) ipBansIt.next();
final TFM_Ban ban = banManager.getByIp(ip);
if (!testIp.matches("^\\d{1,3}\\.\\d{1,3}\\.(\\d{1,3}|\\*)\\.(\\d{1,3}|\\*)$"))
{
continue;
}
if (ip.equals(testIp))
{
isIpBanned = true;
ipBan = (BanEntry) ipBans.getEntries().get(testIp);
break;
}
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
{
isIpBanned = true;
ipBan = (BanEntry) ipBans.getEntries().get(testIp);
break;
}
}
if (isIpBanned)
{
String kickMessage = ChatColor.RED + "Your IP address is temporarily banned from this server.\nAppeal at http://totalfreedom.boards.net/.";
if (ipBan != null)
if (!ban.getReason().equals("none"))
{
kickMessage = kickMessage + "\nReason: " + ipBan.getReason();
if (ipBan.getExpires() != null)
{
kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(ipBan.getExpires());
}
kickMessage = kickMessage + "\nReason: " + ban.getReason();
}
if (ban.getExpireUnix() != 0)
{
kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(TFM_Util.getUnixDate(ban.getExpireUnix()));
}
event.disallow(Result.KICK_OTHER, kickMessage);
return;
}
// permban.yml - ips
// Permbanned Ips
for (String testIp : TotalFreedomMod.permbannedIps)
{
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
{
event.disallow(Result.KICK_OTHER, ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at http://bit.ly/TF_PermBan");
event.disallow(Result.KICK_OTHER,
ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at http://bit.ly/TF_PermBan");
return;
}
}
// permban.yml - names
// Permbanned names
for (String testPlayer : TotalFreedomMod.permbannedPlayers)
{
if (testPlayer.equalsIgnoreCase(username))
{
event.disallow(Result.KICK_OTHER, ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at http://bit.ly/TF_PermBan");
event.disallow(Result.KICK_OTHER,
ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at http://bit.ly/TF_PermBan");
return;
}
}
@ -285,9 +175,9 @@ public class TFM_ServerInterface
}
// Whitelist check
if (playerList.hasWhitelist)
if (isWhitelisted())
{
if (!playerList.getWhitelisted().contains(username.toLowerCase()))
if (!getWhitelisted().contains(username.toLowerCase()))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
return;
@ -295,9 +185,9 @@ public class TFM_ServerInterface
}
// Username already logged in check
for (Player test_player : server.getOnlinePlayers())
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (test_player.getName().equalsIgnoreCase(username))
if (onlinePlayer.getName().equalsIgnoreCase(username))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
return;
@ -309,32 +199,32 @@ public class TFM_ServerInterface
// force-allow superadmins to log in
event.allow();
if (isIPBanned(ip))
if (banManager.isIpBanned(ip))
{
unbanIP(ip);
banManager.unbanIp(ip);
}
if (isNameBanned(username))
if (banManager.isUuidBanned(uuid))
{
unbanUsername(username);
banManager.unbanUuid(uuid);
}
for (Player testPlayer : server.getOnlinePlayers())
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (testPlayer.getName().equalsIgnoreCase(username))
if (onlinePlayer.getName().equalsIgnoreCase(username))
{
testPlayer.kickPlayer("An admin just logged in with the username you are using.");
onlinePlayer.kickPlayer("An admin just logged in with the username you are using.");
}
}
int count = server.getOnlinePlayers().length;
if (count >= server.getMaxPlayers())
{
for (Player p : server.getOnlinePlayers())
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (!TFM_AdminList.isSuperAdmin(p))
if (!TFM_AdminList.isSuperAdmin(onlinePlayer))
{
p.kickPlayer("You have been kicked to free up room for an admin.");
onlinePlayer.kickPlayer("You have been kicked to free up room for an admin.");
count--;
}
@ -352,15 +242,5 @@ public class TFM_ServerInterface
}
}
if (TotalFreedomMod.lockdownEnabled)
{
TFM_Util.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
}
}
public static String getVersion()
{
return MinecraftServer.getServer().getVersion();
}
}

View file

@ -160,6 +160,40 @@ public class TFM_Util
return player.getName() + " (" + player.getUniqueId() + ")";
}
/**
* Escapes an IP-address to a config-friendly version.
*
* <p>Example:
* <pre>
* IpUtils.toEscapedString("192.168.1.192"); // 192_168_1_192
* </pre></p>
*
* @param ip The IP-address to escape.
* @return The config-friendly IP address.
* @see #fromEscapedString(String)
*/
public static String toEscapedString(String ip) // BukkitLib
{
return ip.trim().replaceAll("\\.", "_");
}
/**
* Un-escapes a config-friendly Ipv4-address.
*
* <p>Example:
* <pre>
* IpUtils.fromEscapedString("192_168_1_192"); // 192.168.1.192
* </pre></p>
*
* @param escapedIp The IP-address to un-escape.
* @return The config-friendly IP address.
* @see #toEscapedString(String)
*/
public static String fromEscapedString(String escapedIp) // BukkitLib
{
return escapedIp.trim().replaceAll("_", "\\.");
}
public static void gotoWorld(CommandSender sender, String targetworld)
{
if (sender instanceof Player)
@ -374,40 +408,32 @@ public class TFM_Util
public static void autoEject(Player player, String kickMessage)
{
EjectMethod method = EjectMethod.STRIKE_ONE;
String ip = null;
final String ip = TFM_Util.getIp(player);
try
{
ip = player.getAddress().getAddress().getHostAddress();
Integer kicks = TFM_Util.ejectTracker.get(ip);
if (kicks == null)
{
kicks = new Integer(0);
}
kicks = new Integer(kicks.intValue() + 1);
TFM_Util.ejectTracker.put(ip, kicks);
if (kicks.intValue() <= 1)
{
method = EjectMethod.STRIKE_ONE;
}
else if (kicks.intValue() == 2)
{
method = EjectMethod.STRIKE_TWO;
}
else if (kicks.intValue() >= 3)
{
method = EjectMethod.STRIKE_THREE;
}
}
catch (Exception ex)
if (!TFM_Util.ejectTracker.containsKey(ip))
{
TFM_Util.ejectTracker.put(ip, 0);
}
TFM_Log.info("autoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString());
int kicks = TFM_Util.ejectTracker.get(ip);
kicks += 1;
TFM_Util.ejectTracker.put(ip, kicks);
if (kicks <= 1)
{
method = EjectMethod.STRIKE_ONE;
}
else if (kicks == 2)
{
method = EjectMethod.STRIKE_TWO;
}
else if (kicks >= 3)
{
method = EjectMethod.STRIKE_THREE;
}
TFM_Log.info("AutoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString());
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
@ -417,47 +443,44 @@ public class TFM_Util
{
case STRIKE_ONE:
{
Calendar c = new GregorianCalendar();
c.add(Calendar.MINUTE, 1);
Date expires = c.getTime();
final Calendar cal = new GregorianCalendar();
cal.add(Calendar.MINUTE, 1);
final Date expires = cal.getTime();
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute.");
TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", expires);
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", expires);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", expires, kickMessage));
player.kickPlayer(kickMessage);
break;
}
case STRIKE_TWO:
{
Calendar c = new GregorianCalendar();
final Calendar c = new GregorianCalendar();
c.add(Calendar.MINUTE, 3);
Date expires = c.getTime();
final Date expires = c.getTime();
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes.");
TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", expires);
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", expires);
player.kickPlayer(kickMessage);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", expires, kickMessage));
player.kickPlayer(kickMessage);
break;
}
case STRIKE_THREE:
{
//Bukkit.banIP(player_ip);
TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", null);
String[] ipAddressParts = ip.split("\\.");
//Bukkit.banIP();
TFM_ServerInterface.banIP(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", kickMessage, "AutoEject", null);
//p.setBanned(true);
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", null);
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage));
TFM_BanManager.getInstance().addIpBan(new TFM_Ban(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", player.getName(), "AutoEject", null, kickMessage));
TFM_BanManager.getInstance().addUuidBan(new TFM_Ban(player.getUniqueId(), player.getName(), "AutoEject", null, kickMessage));
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");
player.kickPlayer(kickMessage);
break;
}
}
@ -826,6 +849,21 @@ public class TFM_Util
return System.currentTimeMillis() / 1000L;
}
public static Date getUnixDate(long unix)
{
return new Date(unix * 1000);
}
public static long getUnixTime(Date date)
{
if (date == null)
{
return 0;
}
return date.getTime() / 1000L;
}
public static class TFM_EntityWiper
{
private static final List<Class<? extends Entity>> WIPEABLES = new ArrayList<Class<? extends Entity>>();

View file

@ -91,6 +91,7 @@ public class TotalFreedomMod extends JavaPlugin
loadPermbanConfig();
TFM_PlayerList.getInstance().load();
TFM_BanManager.getInstance().load();
registerEventHandlers();

View file

@ -8,7 +8,7 @@ admins:
is_senior_admin: true
is_telnet_admin: true
last_login: Fri, 9 Nov 2012 03:09:14 -0500
custom_login_message: the &5Lead Executive Developer&b.
custom_login_message: the &5Lead Executive Developer
ips:
- 127.0.0.1
console_aliases: