Added my own set of ban/unban commands that go directly to the server banlist and support temp banning and ban reasons.

This commit is contained in:
Steven Lawson 2012-09-15 21:19:55 -04:00
parent 0af25d921f
commit 0de47783b9
9 changed files with 177 additions and 37 deletions

View File

@ -45,7 +45,8 @@ public class Command_gadmin extends TFM_Command
}
else if (mode.equals("nameban"))
{
server.getOfflinePlayer(p.getName()).setBanned(true);
//server.getOfflinePlayer(p.getName()).setBanned(true);
TFM_Util.banUsername(p.getName(), null, null, null);
TFM_Util.bcastMsg(String.format("Banning Name: %s.", p.getName()), ChatColor.RED);
p.kickPlayer("Username banned by Administrator.");
}
@ -58,7 +59,8 @@ public class Command_gadmin extends TFM_Command
user_ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
TFM_Util.bcastMsg(String.format("Banning IP: %s.", p.getName(), user_ip), ChatColor.RED);
server.banIP(user_ip);
//server.banIP(user_ip);
TFM_Util.banIP(user_ip, null, null, null);
p.kickPlayer("IP address banned by Administrator.");
}
else if (mode.equals("ban"))
@ -70,8 +72,10 @@ public class Command_gadmin extends TFM_Command
user_ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
TFM_Util.bcastMsg(String.format("Banning Name: %s, IP: %s.", p.getName(), user_ip), ChatColor.RED);
server.banIP(user_ip);
server.getOfflinePlayer(p.getName()).setBanned(true);
//server.banIP(user_ip);
//server.getOfflinePlayer(p.getName()).setBanned(true);
TFM_Util.banIP(user_ip, null, null, null);
TFM_Util.banUsername(p.getName(), null, null, null);
p.kickPlayer("IP and username banned by Administrator.");
}
else if (mode.equals("op"))

View File

@ -6,7 +6,6 @@ import me.StevenLawson.TotalFreedomMod.TFM_UserList;
import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry;
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;
@ -72,32 +71,39 @@ public class Command_glist extends TFM_Command
Player p = server.getPlayerExact(username);
if (p != null)
{
p.setBanned(true);
//p.setBanned(true);
TFM_Util.banUsername(p.getName(), null, null, null);
p.kickPlayer("IP and username banned by Administrator.");
}
else
{
server.getOfflinePlayer(username).setBanned(true);
//server.getOfflinePlayer(username).setBanned(true);
TFM_Util.banUsername(username, null, null, null);
}
for (String ip_address : ip_addresses)
{
server.banIP(ip_address);
//server.banIP(ip_address);
TFM_Util.banIP(ip_address, null, null, null);
String[] ip_address_parts = ip_address.split("\\.");
server.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
//server.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
TFM_Util.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", null, null, null);
}
}
else if (mode.equalsIgnoreCase("unban"))
{
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + TFM_Util.implodeStringList(",", ip_addresses), true);
server.getOfflinePlayer(username).setBanned(false);
//server.getOfflinePlayer(username).setBanned(false);
TFM_Util.unbanUsername(username);
for (String ip_address : ip_addresses)
{
server.unbanIP(ip_address);
//server.unbanIP(ip_address);
TFM_Util.unbanIP(ip_address);
String[] ip_address_parts = ip_address.split("\\.");
server.unbanIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
//server.unbanIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
TFM_Util.unbanIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
}
}
}

View File

@ -71,10 +71,12 @@ public class Command_gtfo extends TFM_Command
user_ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
TFM_Util.bcastMsg(String.format("Banning: %s, IP: %s.", p.getName(), user_ip), ChatColor.RED);
server.banIP(user_ip);
//server.banIP(user_ip);
TFM_Util.banIP(user_ip, null, null, null);
//Ban Username:
server.getOfflinePlayer(p.getName()).setBanned(true);
//server.getOfflinePlayer(p.getName()).setBanned(true);
TFM_Util.banUsername(p.getName(), null, null, null);
//Kick Player:
p.kickPlayer("GTFO");

View File

@ -26,7 +26,7 @@ public class Command_ops extends TFM_Command
int offlineOPs = 0;
int totalOPs = 0;
for (OfflinePlayer p : Bukkit.getOperators())
for (OfflinePlayer p : server.getOperators())
{
if (p.isOnline())
{
@ -53,7 +53,7 @@ public class Command_ops extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Removing all operators", true);
for (OfflinePlayer p : Bukkit.getOperators())
for (OfflinePlayer p : server.getOperators())
{
p.setOp(false);

View File

@ -32,7 +32,7 @@ public class Command_stfu extends TFM_Command
TFM_Util.playerMsg(sender, "Muted players:");
TFM_UserInfo info;
int count = 0;
for (Player mp : Bukkit.getOnlinePlayers())
for (Player mp : server.getOnlinePlayers())
{
info = TFM_UserInfo.getPlayerData(mp);
if (info.isMuted())
@ -53,7 +53,7 @@ public class Command_stfu extends TFM_Command
TFM_Util.bcastMsg(ChatColor.RED + sender.getName() + " - Unmuting all players.");
TFM_UserInfo info;
int count = 0;
for (Player mp : Bukkit.getOnlinePlayers())
for (Player mp : server.getOnlinePlayers())
{
info = TFM_UserInfo.getPlayerData(mp);
if (info.isMuted())

View File

@ -1,6 +1,9 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.server.BanList;
import net.minecraft.server.MinecraftServer;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@ -18,12 +21,18 @@ public class Command_tfbanlist extends TFM_Command
{
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender))
{
for (OfflinePlayer p : server.getBannedPlayers())
try
{
p.setBanned(false);
}
BanList nameBans = MinecraftServer.getServer().getServerConfigurationManager().getNameBans();
nameBans.getEntries().clear();
nameBans.save();
sender.sendMessage(ChatColor.GRAY + "Ban list has been purged.");
sender.sendMessage(ChatColor.GRAY + "Ban list has been purged.");
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
return true;
}

View File

@ -3,7 +3,10 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.server.BanList;
import net.minecraft.server.MinecraftServer;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -20,12 +23,18 @@ public class Command_tfipbanlist extends TFM_Command
{
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender))
{
for (String ip : server.getIPBans())
try
{
server.unbanIP(ip);
}
BanList IPBans = MinecraftServer.getServer().getServerConfigurationManager().getIPBans();
IPBans.getEntries().clear();
IPBans.save();
sender.sendMessage(ChatColor.GRAY + "IP Ban list has been purged.");
sender.sendMessage(ChatColor.GRAY + "IP ban list has been purged.");
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
return true;
}

View File

@ -2,7 +2,6 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -24,9 +23,9 @@ public class Command_uall extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Undisguising all players", true);
try
{
for (Player p : Bukkit.getOnlinePlayers())
for (Player p : server.getOnlinePlayers())
{
Bukkit.dispatchCommand(p, "u");
server.dispatchCommand(p, "u");
}
}
catch (Throwable e)

View File

@ -8,6 +8,9 @@ import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import net.minecraft.server.BanEntry;
import net.minecraft.server.BanList;
import net.minecraft.server.MinecraftServer;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
@ -619,23 +622,52 @@ 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);
TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned for 1 minute.");
p.kickPlayer(kickMessage);
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("tempban %s 1m", p.getName()));
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);
TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned for 3 minutes.");
p.kickPlayer(kickMessage);
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("tempban %s 3m", p.getName()));
break;
}
case STRIKE_THREE:
{
Bukkit.banIP(player_ip);
//Bukkit.banIP(player_ip);
TFM_Util.banIP(player_ip, null, null, null);
String[] ip_address_parts = player_ip.split("\\.");
Bukkit.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
//Bukkit.banIP();
TFM_Util.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", null, null, null);
p.setBanned(true);
//p.setBanned(true);
TFM_Util.banUsername(p.getName(), null, null, null);
TFM_Util.bcastMsg(ChatColor.RED + p.getName() + " has been banned permanently.");
p.kickPlayer(kickMessage);
@ -691,11 +723,11 @@ public class TFM_Util
if (sender.getName().equalsIgnoreCase("madgeek1450"))
{
return "the " + ChatColor.DARK_PURPLE + "chief-developer" + ChatColor.AQUA + ".";
return "the " + ChatColor.DARK_PURPLE + "server chief-developer" + ChatColor.AQUA + ".";
}
if (sender.getName().equalsIgnoreCase("darthsalamon"))
{
return "a " + ChatColor.DARK_PURPLE + "developer" + ChatColor.AQUA + "!";
return "a " + ChatColor.DARK_PURPLE + "server developer" + ChatColor.AQUA + "!";
}
if (TFM_Util.isUserSuperadmin(sender))
@ -711,6 +743,85 @@ public class TFM_Util
return "a " + ChatColor.GREEN + "standard player" + ChatColor.AQUA + ".";
}
public static void banUsername(String name, String reason, String source, Date expire_date)
{
name = name.toLowerCase().trim();
BanEntry ban_entry = new BanEntry(name);
if (expire_date != null)
{
ban_entry.setExpires(expire_date);
}
if (reason != null)
{
ban_entry.setReason(reason);
}
if (source != null)
{
ban_entry.setSource(source);
}
BanList nameBans = MinecraftServer.getServer().getServerConfigurationManager().getNameBans();
nameBans.add(ban_entry);
}
public static void unbanUsername(String name)
{
name = name.toLowerCase().trim();
BanList nameBans = MinecraftServer.getServer().getServerConfigurationManager().getNameBans();
nameBans.remove(name);
}
public static boolean isNameBanned(String name)
{
name = name.toLowerCase().trim();
BanList nameBans = MinecraftServer.getServer().getServerConfigurationManager().getNameBans();
nameBans.removeExpired();
return nameBans.getEntries().containsKey(name);
}
public static void banIP(String ip, String reason, String source, Date expire_date)
{
ip = ip.toLowerCase().trim();
BanEntry ban_entry = new BanEntry(ip);
if (expire_date != null)
{
ban_entry.setExpires(expire_date);
}
if (reason != null)
{
ban_entry.setReason(reason);
}
if (source != null)
{
ban_entry.setSource(source);
}
BanList ipBans = MinecraftServer.getServer().getServerConfigurationManager().getIPBans();
ipBans.add(ban_entry);
}
public static void unbanIP(String ip)
{
ip = ip.toLowerCase().trim();
BanList ipBans = MinecraftServer.getServer().getServerConfigurationManager().getIPBans();
ipBans.remove(ip);
}
public static boolean isIPBanned(String ip)
{
ip = ip.toLowerCase().trim();
BanList ipBans = MinecraftServer.getServer().getServerConfigurationManager().getIPBans();
ipBans.removeExpired();
return ipBans.getEntries().containsKey(ip);
}
// 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;