Consolidate any calls to net.minecraft.server classes to new TFM_ServerInterface class.

Fix use of deprecated async calls.
This commit is contained in:
Steven Lawson 2012-12-08 22:42:29 -05:00
parent c3b03f8e7c
commit 9ae4677307
18 changed files with 516 additions and 367 deletions

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
@ -49,10 +50,10 @@ public class Command_doom extends TFM_Command
p.setOp(false);
// ban IP
TFM_Util.banIP(IP, null, null, null);
TFM_ServerInterface.banIP(IP, null, null, null);
// ban name
TFM_Util.banUsername(p.getName(), null, null, null);
TFM_ServerInterface.banUsername(p.getName(), null, null, null);
// set gamemode to survival
p.setGameMode(GameMode.SURVIVAL);
@ -67,7 +68,7 @@ public class Command_doom extends TFM_Command
// generate explosion
p.getWorld().createExplosion(p.getLocation(), 4F);
server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
server.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable()
{
@Override
public void run()
@ -80,7 +81,7 @@ public class Command_doom extends TFM_Command
}
}, 40L); // 2 seconds
server.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
server.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable()
{
@Override
public void run()

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
@ -45,7 +46,7 @@ public class Command_gadmin extends TFM_Command
}
else if (mode.equals("nameban"))
{
TFM_Util.banUsername(p.getName(), null, null, null);
TFM_ServerInterface.banUsername(p.getName(), null, null, null);
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", p.getName()), true);
p.kickPlayer("Username banned by Administrator.");
}
@ -58,7 +59,7 @@ public class Command_gadmin extends TFM_Command
user_ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", p.getName(), user_ip), true);
TFM_Util.banIP(user_ip, null, null, null);
TFM_ServerInterface.banIP(user_ip, null, null, null);
p.kickPlayer("IP address banned by Administrator.");
}
else if (mode.equals("ban"))
@ -70,8 +71,8 @@ public class Command_gadmin extends TFM_Command
user_ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", p.getName(), user_ip), true);
TFM_Util.banIP(user_ip, null, null, null);
TFM_Util.banUsername(p.getName(), null, null, null);
TFM_ServerInterface.banIP(user_ip, null, null, null);
TFM_ServerInterface.banUsername(p.getName(), null, null, null);
p.kickPlayer("IP and username banned by Administrator.");
}
else if (mode.equals("op"))

View File

@ -2,6 +2,8 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
@ -26,7 +28,14 @@ public class Command_glist extends TFM_Command
if (args[0].equalsIgnoreCase("purge"))
{
//Purge does not clear the banlist! This is not for clearing bans! This is for clearing the yaml file that stores the player/IP database!
TFM_UserList.getInstance(plugin).purge();
if (TFM_SuperadminList.isSeniorAdmin(sender))
{
TFM_UserList.getInstance(plugin).purge();
}
else
{
TFM_Util.playerMsg(sender, "Only Senior Admins may purge the userlist.");
}
return true;
}
else
@ -34,79 +43,78 @@ public class Command_glist extends TFM_Command
return false;
}
}
else if (args.length != 2)
else if (args.length == 2)
{
return false;
}
String username;
List<String> ip_addresses = new ArrayList<String>();
String username;
List<String> ip_addresses = new ArrayList<String>();
try
{
Player p = getPlayer(args[1]);
username = p.getName();
ip_addresses.add(p.getAddress().getAddress().getHostAddress());
}
catch (CantFindPlayerException ex)
{
TFM_UserListEntry entry = TFM_UserList.getInstance(plugin).getEntry(args[1]);
if (entry == null)
try
{
sender.sendMessage("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
return true;
Player p = getPlayer(args[1]);
username = p.getName();
ip_addresses.add(p.getAddress().getAddress().getHostAddress());
}
catch (CantFindPlayerException ex)
{
TFM_UserListEntry entry = TFM_UserList.getInstance(plugin).getEntry(args[1]);
if (entry == null)
{
TFM_Util.playerMsg(sender, "Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
return true;
}
username = entry.getUsername();
ip_addresses = entry.getIpAddresses();
}
username = entry.getUsername();
ip_addresses = entry.getIpAddresses();
}
String mode = args[0].toLowerCase();
if (mode.equalsIgnoreCase("ban"))
{
TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ip_addresses, ","), true);
Player p = server.getPlayerExact(username);
if (p != null)
String mode = args[0].toLowerCase();
if (mode.equalsIgnoreCase("ban"))
{
//p.setBanned(true);
TFM_Util.banUsername(p.getName(), null, null, null);
p.kickPlayer("IP and username banned by Administrator.");
TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ip_addresses, ","), true);
Player p = server.getPlayerExact(username);
if (p != null)
{
TFM_ServerInterface.banUsername(p.getName(), null, null, null);
p.kickPlayer("IP and username banned by Administrator.");
}
else
{
TFM_ServerInterface.banUsername(username, null, null, null);
}
for (String ip_address : ip_addresses)
{
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);
}
}
else if (mode.equalsIgnoreCase("unban") || mode.equalsIgnoreCase("pardon"))
{
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ip_addresses, ","), true);
TFM_ServerInterface.unbanUsername(username);
for (String ip_address : ip_addresses)
{
TFM_ServerInterface.unbanIP(ip_address);
String[] ip_address_parts = ip_address.split("\\.");
TFM_ServerInterface.unbanIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
}
}
else
{
//server.getOfflinePlayer(username).setBanned(true);
TFM_Util.banUsername(username, null, null, null);
return false;
}
for (String ip_address : ip_addresses)
{
//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] + ".*.*");
TFM_Util.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", null, null, null);
}
return true;
}
else if (mode.equalsIgnoreCase("unban"))
else
{
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ip_addresses, ","), true);
//server.getOfflinePlayer(username).setBanned(false);
TFM_Util.unbanUsername(username);
for (String ip_address : ip_addresses)
{
//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] + ".*.*");
TFM_Util.unbanIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
}
return false;
}
return true;
}
}

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -69,12 +70,10 @@ 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);
TFM_Util.banIP(user_ip, null, null, null);
TFM_ServerInterface.banIP(user_ip, null, null, null);
// ban username:
// server.getOfflinePlayer(p.getName()).setBanned(true);
TFM_Util.banUsername(p.getName(), null, null, null);
TFM_ServerInterface.banUsername(p.getName(), null, null, null);
// kick Player:
p.kickPlayer("GTFO");

View File

@ -7,7 +7,7 @@ import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
@CommandPermissions(level = ADMIN_LEVEL.SENIOR, source = SOURCE_TYPE_ALLOWED.ONLY_CONSOLE, block_host_console = true, ignore_permissions = false)
public class Command_lockup extends TFM_Command
@ -92,12 +92,11 @@ public class Command_lockup extends TFM_Command
private void cancelLockup(TFM_UserInfo playerdata)
{
BukkitScheduler scheduler = server.getScheduler();
int lockupScheduleID = playerdata.getLockupScheduleID();
if (lockupScheduleID != -1)
BukkitTask lockupScheduleID = playerdata.getLockupScheduleID();
if (lockupScheduleID != null)
{
scheduler.cancelTask(lockupScheduleID);
playerdata.setLockupScheduleID(-1);
lockupScheduleID.cancel();
playerdata.setLockupScheduleID(null);
}
}
@ -112,7 +111,7 @@ public class Command_lockup extends TFM_Command
cancelLockup(playerdata);
playerdata.setLockupScheduleID(server.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable()
playerdata.setLockupScheduleID(server.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable()
{
private Random random = new Random();

View File

@ -1,9 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PropertyManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -38,9 +37,7 @@ public class Command_onlinemode extends TFM_Command
try
{
PropertyManager prop_man = MinecraftServer.getServer().getPropertyManager();
prop_man.a("online-mode", online_mode);
prop_man.savePropertiesFile();
TFM_ServerInterface.setOnlineMode(online_mode);
if (online_mode)
{

View File

@ -26,7 +26,7 @@ public class Command_permban extends TFM_Command
else if (args[0].equalsIgnoreCase("reload"))
{
TFM_Util.playerMsg(sender, "Reloading permban list...", ChatColor.RED);
plugin.loadPermbanConfig();
TotalFreedomMod.loadPermbanConfig();
dumplist(sender);
}
else

View File

@ -1,29 +1,110 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
@CommandPermissions(level = ADMIN_LEVEL.ALL, source = SOURCE_TYPE_ALLOWED.BOTH, ignore_permissions = true)
public class Command_status extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
sender.sendMessage(ChatColor.GOLD + "Total Freedom Mod v" + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + ", built " + TotalFreedomMod.buildDate);
sender.sendMessage(ChatColor.GOLD + "By: Madgeek1450 and DarthSalamon");
sender.sendMessage(ChatColor.YELLOW + "Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.");
sender.sendMessage(ChatColor.GOLD + "Loaded worlds:");
public static final Map<String, String> SERVICE_MAP = new HashMap<String, String>();
static
{
SERVICE_MAP.put("minecraft.net", "Minecraft.net");
SERVICE_MAP.put("login.minecraft.net", "Minecraft Logins");
SERVICE_MAP.put("session.minecraft.net", "Minecraft Multiplayer Sessions");
SERVICE_MAP.put("account.mojang.com", "Mojang Accounts Website");
SERVICE_MAP.put("auth.mojang.com", "Mojang Accounts Login");
SERVICE_MAP.put("skins.minecraft.net", "Minecraft Skins");
}
@Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
TFM_Util.playerMsg(sender, String.format("Total Freedom Mod v%s.%s, built %s.", TotalFreedomMod.pluginVersion, TotalFreedomMod.buildNumber, TotalFreedomMod.buildDate), ChatColor.GOLD);
TFM_Util.playerMsg(sender, "TotalFreedomMod was created by Madgeek1450 and DarthSalamon.", ChatColor.GOLD);
TFM_Util.playerMsg(sender, "Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.YELLOW);
TFM_Util.playerMsg(sender, "Loaded worlds:", ChatColor.BLUE);
int i = 0;
for (World world : server.getWorlds())
{
sender.sendMessage(ChatColor.GOLD + "World " + Integer.toString(i++) + ": " + world.getName() + " - " + Integer.toString(world.getPlayers().size()) + " players.");
TFM_Util.playerMsg(sender, String.format("World %d: %s - %d players.", i++, world.getName(), world.getPlayers().size()), ChatColor.BLUE);
}
server.getScheduler().runTaskAsynchronously(plugin, new Runnable()
{
@SuppressWarnings("unchecked")
@Override
public void run()
{
try
{
URL mojang_status = new URL("http://status.mojang.com/check");
BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream()));
JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine());
in.close();
Map<String, Boolean> service_status = new HashMap<String, Boolean>();
Iterator status_it = status_json.iterator();
while (status_it.hasNext())
{
JSONObject service = (JSONObject) status_it.next();
Iterator service_it = service.entrySet().iterator();
while (service_it.hasNext())
{
Entry<String, String> pair = (Entry<String, String>) service_it.next();
service_status.put(pair.getKey(), (pair.getValue().equals("green") ? Boolean.TRUE : Boolean.FALSE));
}
}
List<String> status_output = new ArrayList<String>();
Iterator<Entry<String, Boolean>> output_it = service_status.entrySet().iterator();
while (output_it.hasNext())
{
Entry<String, Boolean> pair = output_it.next();
String service_name = pair.getKey();
boolean service_online = pair.getValue().booleanValue();
if (SERVICE_MAP.containsKey(service_name))
{
service_name = SERVICE_MAP.get(service_name);
}
status_output.add(String.format("%s is %s", service_name, (service_online ? ChatColor.GREEN + "ONLINE" + ChatColor.GRAY : ChatColor.RED + "OFFLINE" + ChatColor.GRAY)));
}
TFM_Util.playerMsg(sender, String.format("Mojang Service Status: %s.", StringUtils.join(status_output, ", ")), ChatColor.GRAY);
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
});
return true;
}
}

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.text.SimpleDateFormat;
import java.util.Date;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
@ -54,8 +55,8 @@ public class Command_tempban extends TFM_Command
}
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);
TFM_ServerInterface.banUsername(p.getName(), ban_reason, sender.getName(), ban_duration);
TFM_ServerInterface.banIP(p.getAddress().getAddress().getHostAddress().trim(), ban_reason, sender.getName(), ban_duration);
p.kickPlayer(sender.getName() + " - " + bcast_msg.toString());
return true;

View File

@ -29,7 +29,7 @@ public class Command_terminal extends TFM_Command
}
sender.sendMessage("Running system command: " + command);
server.getScheduler().scheduleAsyncDelayedTask(plugin, new TFM_RunSystemCommand(command, plugin));
server.getScheduler().runTaskAsynchronously(plugin, new TFM_RunSystemCommand(command, plugin));
return true;
}

View File

@ -1,9 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import net.minecraft.server.BanList;
import net.minecraft.server.MinecraftServer;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@ -24,10 +23,7 @@ public class Command_tfbanlist extends TFM_Command
{
try
{
BanList nameBans = MinecraftServer.getServer().getServerConfigurationManager().getNameBans();
nameBans.getEntries().clear();
nameBans.save();
TFM_ServerInterface.wipeNameBans();
sender.sendMessage(ChatColor.GRAY + "Ban list has been purged.");
}
catch (Exception ex)

View File

@ -4,9 +4,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import net.minecraft.server.BanList;
import net.minecraft.server.MinecraftServer;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -26,10 +25,7 @@ public class Command_tfipbanlist extends TFM_Command
{
try
{
BanList IPBans = MinecraftServer.getServer().getServerConfigurationManager().getIPBans();
IPBans.getEntries().clear();
IPBans.save();
TFM_ServerInterface.wipeIpBans();
sender.sendMessage(ChatColor.GRAY + "IP ban list has been purged.");
}
catch (Exception ex)

View File

@ -1,10 +1,9 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.Set;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.server.MinecraftServer;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@ -166,11 +165,8 @@ public class Command_whitelist extends TFM_Command
//purge
if (args[0].equalsIgnoreCase("purge"))
{
@SuppressWarnings("rawtypes")
Set whitelisted = MinecraftServer.getServer().getServerConfigurationManager().getWhitelisted();
TFM_Util.adminAction(sender.getName(), "Removing all players from the whitelist.", false);
TFM_Util.playerMsg(sender, "Removed " + whitelisted.size() + " players from the whitelist.");
whitelisted.clear();
TFM_Util.playerMsg(sender, "Removed " + TFM_ServerInterface.purgeWhitelist() + " players from the whitelist.");
return true;
}

View File

@ -7,16 +7,11 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.*;
import net.minecraft.server.BanEntry;
import net.minecraft.server.BanList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerConfigurationManagerAbstract;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -32,7 +27,6 @@ import org.bukkit.util.Vector;
public class TFM_PlayerListener implements Listener
{
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
private static final List<String> BLOCKED_MUTED_CMDS = Arrays.asList(StringUtils.split("say,me,msg,m,tell,r,reply", ","));
@EventHandler(priority = EventPriority.HIGH)
@ -608,7 +602,7 @@ public class TFM_PlayerListener implements Listener
if (TotalFreedomMod.adminOnlyMode)
{
TotalFreedomMod.plugin.getServer().getScheduler().scheduleAsyncDelayedTask(TotalFreedomMod.plugin, new Runnable()
TotalFreedomMod.plugin.getServer().getScheduler().runTaskLaterAsynchronously(TotalFreedomMod.plugin, new Runnable()
{
@Override
public void run()
@ -626,180 +620,6 @@ public class TFM_PlayerListener implements Listener
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(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.plugin.getServer();
final ServerConfigurationManagerAbstract scm = MinecraftServer.getServer().getServerConfigurationManager();
final BanList banByIP = scm.getIPBans();
final BanList banByName = scm.getNameBans();
final Player p = event.getPlayer();
final String player_name = p.getName();
final String player_ip = event.getAddress().getHostAddress().trim().toLowerCase();
if (player_name.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(player_name).find())
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters.");
return;
}
// not safe to use TFM_Util.isUserSuperadmin for player logging in because p.getAddress() will return a null until after player login.
boolean is_superadmin;
if (server.getOnlineMode())
{
is_superadmin = TFM_SuperadminList.getSuperadminNames().contains(player_name.toLowerCase());
}
else
{
is_superadmin = TFM_SuperadminList.checkPartialSuperadminIP(player_ip);
}
if (!is_superadmin)
{
BanEntry ban_entry = null;
if (banByName.isBanned(player_name.toLowerCase()))
{
ban_entry = (BanEntry) banByName.getEntries().get(player_name.toLowerCase());
String kick_message = "You are banned from this server.";
if (ban_entry != null)
{
kick_message = kick_message + "\nReason: " + ban_entry.getReason();
if (ban_entry.getExpires() != null)
{
kick_message = kick_message + "\nYour ban will be removed on " + date_format.format(ban_entry.getExpires());
}
}
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kick_message);
return;
}
boolean is_ip_banned = false;
@SuppressWarnings("rawtypes")
Iterator ip_bans = banByIP.getEntries().keySet().iterator();
while (ip_bans.hasNext())
{
String test_ip = (String) ip_bans.next();
if (!test_ip.matches("^\\d{1,3}\\.\\d{1,3}\\.(\\d{1,3}|\\*)\\.(\\d{1,3}|\\*)$"))
{
continue;
}
if (player_ip.equals(test_ip))
{
ban_entry = (BanEntry) banByIP.getEntries().get(test_ip);
is_ip_banned = true;
break;
}
if (TFM_Util.fuzzyIpMatch(test_ip, player_ip, 4))
{
ban_entry = (BanEntry) banByIP.getEntries().get(test_ip);
is_ip_banned = true;
break;
}
}
if (is_ip_banned)
{
String kick_message = "Your IP address is banned from this server.";
if (ban_entry != null)
{
kick_message = kick_message + "\nReason: " + ban_entry.getReason();
if (ban_entry.getExpires() != null)
{
kick_message = kick_message + "\nYour ban will be removed on " + date_format.format(ban_entry.getExpires());
}
}
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kick_message);
return;
}
for (String test_player : TotalFreedomMod.permbanned_players)
{
if (test_player.equalsIgnoreCase(player_name))
{
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.");
return;
}
}
for (String test_ip : TotalFreedomMod.permbanned_ips)
{
if (TFM_Util.fuzzyIpMatch(test_ip, player_ip, 4))
{
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP address is permanently banned from this server.");
return;
}
}
if (server.getOnlinePlayers().length >= server.getMaxPlayers())
{
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full.");
return;
}
if (TotalFreedomMod.adminOnlyMode)
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is temporarily open to admins only.");
return;
}
if (scm.hasWhitelist)
{
if (!scm.getWhitelisted().contains(player_name.toLowerCase()))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
return;
}
}
for (Player test_player : server.getOnlinePlayers())
{
if (test_player.getName().equalsIgnoreCase(player_name))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
return;
}
}
}
else
{
for (Player test_player : server.getOnlinePlayers())
{
if (test_player.getName().equalsIgnoreCase(player_name))
{
test_player.kickPlayer("An admin just logged in with the username you are using.");
}
}
boolean can_kick = true; // if the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop.
while (server.getOnlinePlayers().length >= server.getMaxPlayers() && can_kick)
{
can_kick = false;
for (Player test_player : server.getOnlinePlayers())
{
if (!TFM_SuperadminList.isUserSuperadmin(test_player))
{
can_kick = true;
test_player.kickPlayer("You have been kicked to free up room for an admin.");
break;
}
}
}
}
TFM_ServerInterface.handlePlayerLogin(event);
}
}

View File

@ -0,0 +1,300 @@
package me.StevenLawson.TotalFreedomMod;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import java.util.regex.Pattern;
import net.minecraft.server.v1_4_5.BanEntry;
import net.minecraft.server.v1_4_5.BanList;
import net.minecraft.server.v1_4_5.MinecraftServer;
import net.minecraft.server.v1_4_5.PropertyManager;
import net.minecraft.server.v1_4_5.ServerConfigurationManagerAbstract;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerLoginEvent;
public class TFM_ServerInterface
{
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
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().getServerConfigurationManager().getNameBans();
nameBans.getEntries().clear();
nameBans.save();
}
public static void wipeIpBans()
{
BanList IPBans = MinecraftServer.getServer().getServerConfigurationManager().getIPBans();
IPBans.getEntries().clear();
IPBans.save();
}
public static void unbanUsername(String name)
{
name = name.toLowerCase().trim();
BanList nameBans = MinecraftServer.getServer().getServerConfigurationManager().getNameBans();
nameBans.remove(name);
}
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 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);
}
@SuppressWarnings("rawtypes")
public static int purgeWhitelist()
{
Set whitelisted = MinecraftServer.getServer().getServerConfigurationManager().getWhitelisted();
int size = whitelisted.size();
whitelisted.clear();
return size;
}
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.plugin.getServer();
final ServerConfigurationManagerAbstract scm = MinecraftServer.getServer().getServerConfigurationManager();
final BanList banByIP = scm.getIPBans();
final BanList banByName = scm.getNameBans();
final Player p = event.getPlayer();
final String player_name = p.getName();
final String player_ip = event.getAddress().getHostAddress().trim().toLowerCase();
if (player_name.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(player_name).find())
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters.");
return;
}
// not safe to use TFM_Util.isUserSuperadmin for player logging in because p.getAddress() will return a null until after player login.
boolean is_superadmin;
if (server.getOnlineMode())
{
is_superadmin = TFM_SuperadminList.getSuperadminNames().contains(player_name.toLowerCase());
}
else
{
is_superadmin = TFM_SuperadminList.checkPartialSuperadminIP(player_ip);
}
if (!is_superadmin)
{
BanEntry ban_entry = null;
if (banByName.isBanned(player_name.toLowerCase()))
{
ban_entry = (BanEntry) banByName.getEntries().get(player_name.toLowerCase());
String kick_message = "You are banned from this server.";
if (ban_entry != null)
{
kick_message = kick_message + "\nReason: " + ban_entry.getReason();
if (ban_entry.getExpires() != null)
{
kick_message = kick_message + "\nYour ban will be removed on " + date_format.format(ban_entry.getExpires());
}
}
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kick_message);
return;
}
boolean is_ip_banned = false;
@SuppressWarnings("rawtypes")
Iterator ip_bans = banByIP.getEntries().keySet().iterator();
while (ip_bans.hasNext())
{
String test_ip = (String) ip_bans.next();
if (!test_ip.matches("^\\d{1,3}\\.\\d{1,3}\\.(\\d{1,3}|\\*)\\.(\\d{1,3}|\\*)$"))
{
continue;
}
if (player_ip.equals(test_ip))
{
ban_entry = (BanEntry) banByIP.getEntries().get(test_ip);
is_ip_banned = true;
break;
}
if (TFM_Util.fuzzyIpMatch(test_ip, player_ip, 4))
{
ban_entry = (BanEntry) banByIP.getEntries().get(test_ip);
is_ip_banned = true;
break;
}
}
if (is_ip_banned)
{
String kick_message = "Your IP address is banned from this server.";
if (ban_entry != null)
{
kick_message = kick_message + "\nReason: " + ban_entry.getReason();
if (ban_entry.getExpires() != null)
{
kick_message = kick_message + "\nYour ban will be removed on " + date_format.format(ban_entry.getExpires());
}
}
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kick_message);
return;
}
for (String test_player : TotalFreedomMod.permbanned_players)
{
if (test_player.equalsIgnoreCase(player_name))
{
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.");
return;
}
}
for (String test_ip : TotalFreedomMod.permbanned_ips)
{
if (TFM_Util.fuzzyIpMatch(test_ip, player_ip, 4))
{
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP address is permanently banned from this server.");
return;
}
}
if (server.getOnlinePlayers().length >= server.getMaxPlayers())
{
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "Sorry, but this server is full.");
return;
}
if (TotalFreedomMod.adminOnlyMode)
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is temporarily open to admins only.");
return;
}
if (scm.hasWhitelist)
{
if (!scm.getWhitelisted().contains(player_name.toLowerCase()))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
return;
}
}
for (Player test_player : server.getOnlinePlayers())
{
if (test_player.getName().equalsIgnoreCase(player_name))
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
return;
}
}
}
else
{
for (Player test_player : server.getOnlinePlayers())
{
if (test_player.getName().equalsIgnoreCase(player_name))
{
test_player.kickPlayer("An admin just logged in with the username you are using.");
}
}
boolean can_kick = true; // if the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop.
while (server.getOnlinePlayers().length >= server.getMaxPlayers() && can_kick)
{
can_kick = false;
for (Player test_player : server.getOnlinePlayers())
{
if (!TFM_SuperadminList.isUserSuperadmin(test_player))
{
can_kick = true;
test_player.kickPlayer("You have been kicked to free up room for an admin.");
break;
}
}
}
}
}
}

View File

@ -13,6 +13,7 @@ import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
public class TFM_UserInfo
{
@ -39,10 +40,10 @@ public class TFM_UserInfo
private EntityType mob_thrower_creature = EntityType.PIG;
private double mob_thrower_speed = 4.0;
private List<LivingEntity> mob_thrower_queue = new ArrayList<LivingEntity>();
private int mp44_schedule_id = -1;
private BukkitTask mp44_schedule_id = null;
private boolean mp44_armed = false;
private boolean mp44_firing = false;
private int lockup_schedule_id = -1;
private BukkitTask lockup_schedule_id = null;
private String last_message = "";
private boolean in_adminchat = false;
private boolean all_commands_blocked = false;
@ -324,16 +325,16 @@ public class TFM_UserInfo
public void startArrowShooter(TotalFreedomMod plugin)
{
this.stopArrowShooter();
this.mp44_schedule_id = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new ArrowShooter(this.player), 1L, 1L);
this.mp44_schedule_id = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new ArrowShooter(this.player), 1L, 1L);
mp44_firing = true;
}
public void stopArrowShooter()
{
if (this.mp44_schedule_id != -1)
if (this.mp44_schedule_id != null)
{
Bukkit.getServer().getScheduler().cancelTask(this.mp44_schedule_id);
this.mp44_schedule_id = -1;
this.mp44_schedule_id.cancel();
this.mp44_schedule_id = null;
}
mp44_firing = false;
}
@ -398,12 +399,12 @@ public class TFM_UserInfo
this.is_halted = is_halted;
}
public int getLockupScheduleID()
public BukkitTask getLockupScheduleID()
{
return lockup_schedule_id;
}
public void setLockupScheduleID(int lockup_schedule_id)
public void setLockupScheduleID(BukkitTask lockup_schedule_id)
{
this.lockup_schedule_id = lockup_schedule_id;
}

View File

@ -14,9 +14,6 @@ import java.util.regex.Pattern;
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.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.*;
@ -28,7 +25,7 @@ public class TFM_Util
{
private static final Map<String, Integer> eject_tracker = new HashMap<String, Integer>();
public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>();
public static final List<String> stop_commands = Arrays.asList("stop", "off", "end", "halt", "die");
public static final List<String> STOP_COMMANDS = Arrays.asList("stop", "off", "end", "halt", "die");
static
{
@ -423,7 +420,7 @@ public class TFM_Util
public static boolean isStopCommand(String command)
{
return stop_commands.contains(command.toLowerCase());
return STOP_COMMANDS.contains(command.toLowerCase());
}
enum EjectMethod
@ -586,84 +583,40 @@ public class TFM_Util
return "a " + ChatColor.GREEN + "non-OP" + ChatColor.AQUA + ".";
}
@Deprecated
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);
TFM_ServerInterface.banUsername(name, reason, source, expire_date);
}
@Deprecated
public static void unbanUsername(String name)
{
name = name.toLowerCase().trim();
BanList nameBans = MinecraftServer.getServer().getServerConfigurationManager().getNameBans();
nameBans.remove(name);
TFM_ServerInterface.unbanUsername(name);
}
@Deprecated
public static boolean isNameBanned(String name)
{
name = name.toLowerCase().trim();
BanList nameBans = MinecraftServer.getServer().getServerConfigurationManager().getNameBans();
nameBans.removeExpired();
return nameBans.getEntries().containsKey(name);
return TFM_ServerInterface.isNameBanned(name);
}
@Deprecated
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);
TFM_ServerInterface.banIP(ip, reason, source, expire_date);
}
@Deprecated
public static void unbanIP(String ip)
{
ip = ip.toLowerCase().trim();
BanList ipBans = MinecraftServer.getServer().getServerConfigurationManager().getIPBans();
ipBans.remove(ip);
TFM_ServerInterface.unbanIP(ip);
}
@Deprecated
public static boolean isIPBanned(String ip)
{
ip = ip.toLowerCase().trim();
BanList ipBans = MinecraftServer.getServer().getServerConfigurationManager().getIPBans();
ipBans.removeExpired();
return ipBans.getEntries().containsKey(ip);
return TFM_ServerInterface.isIPBanned(ip);
}
public static Date parseDateOffset(String time)

View File

@ -99,7 +99,7 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Util.deleteFolder(new File("./_deleteme"));
server.getScheduler().scheduleAsyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
server.getScheduler().runTaskTimerAsynchronously(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
// metrics @ http://mcstats.org/plugin/TotalFreedomMod
try