mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-22 22:14:57 +00:00
Moved permban list to a seperate class
Refractoring Code cleanup
This commit is contained in:
parent
a0affddeed
commit
08e4a4a171
7 changed files with 136 additions and 95 deletions
|
@ -1,3 +1,3 @@
|
|||
#Build Number for ANT. Do not edit!
|
||||
#Mon Apr 21 18:59:10 CEST 2014
|
||||
build.number=784
|
||||
#Mon Apr 21 23:08:17 CEST 2014
|
||||
build.number=787
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
|||
import java.io.File;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_PermbanList;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.command.Command;
|
||||
|
@ -20,8 +21,9 @@ public class Command_listsync extends TFM_Command
|
|||
|
||||
try
|
||||
{
|
||||
TFM_Util.downloadFile("http://madgeekonline.com/apps/get_superadmins_raw.php", new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
||||
TFM_AdminList.createBackup();
|
||||
TFM_Util.downloadFile("http://madgeekonline.com/apps/get_superadmins_raw.php", new File(TotalFreedomMod.plugin.getDataFolder(),
|
||||
TotalFreedomMod.SUPERADMIN_FILE));
|
||||
TFM_AdminList.load();
|
||||
TFM_Util.adminAction(sender.getName(), TotalFreedomMod.SUPERADMIN_FILE + " downloaded.", false);
|
||||
}
|
||||
|
@ -32,8 +34,10 @@ public class Command_listsync extends TFM_Command
|
|||
|
||||
try
|
||||
{
|
||||
TFM_Util.downloadFile("http://madgeekonline.com/apps/get_permbans_raw.php", new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE));
|
||||
TotalFreedomMod.loadPermbanConfig();
|
||||
TFM_PermbanList.createBackup();
|
||||
TFM_Util.downloadFile("http://madgeekonline.com/apps/get_permbans_raw.php", new File(TotalFreedomMod.plugin.getDataFolder(),
|
||||
TotalFreedomMod.PERMBAN_FILE));
|
||||
TFM_PermbanList.load();
|
||||
TFM_Util.adminAction(sender.getName(), TotalFreedomMod.PERMBAN_FILE + " downloaded.", false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_PermbanList;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -31,7 +32,8 @@ public class Command_permban extends TFM_Command
|
|||
return true;
|
||||
}
|
||||
playerMsg("Reloading permban list...", ChatColor.RED);
|
||||
TotalFreedomMod.loadPermbanConfig();
|
||||
TFM_PermbanList.createBackup();
|
||||
TFM_PermbanList.load();
|
||||
dumplist(sender);
|
||||
}
|
||||
else
|
||||
|
@ -44,24 +46,24 @@ public class Command_permban extends TFM_Command
|
|||
|
||||
private void dumplist(CommandSender sender)
|
||||
{
|
||||
if (TotalFreedomMod.permbannedPlayers.isEmpty())
|
||||
if (TFM_PermbanList.getPermbannedPlayers().isEmpty())
|
||||
{
|
||||
playerMsg(sender, "No permanently banned player names.");
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg(sender, TotalFreedomMod.permbannedPlayers.size() + " permanently banned players:");
|
||||
playerMsg(sender, StringUtils.join(TotalFreedomMod.permbannedPlayers, ", "));
|
||||
playerMsg(sender, TFM_PermbanList.getPermbannedPlayers().size() + " permanently banned players:");
|
||||
playerMsg(sender, StringUtils.join(TFM_PermbanList.getPermbannedPlayers(), ", "));
|
||||
}
|
||||
|
||||
if (TotalFreedomMod.permbannedIps.isEmpty())
|
||||
if (TFM_PermbanList.getPermbannedIps().isEmpty())
|
||||
{
|
||||
playerMsg(sender, "No permanently banned IPs.");
|
||||
}
|
||||
else
|
||||
{
|
||||
playerMsg(sender, TotalFreedomMod.permbannedIps.size() + " permanently banned IPs:");
|
||||
playerMsg(sender, StringUtils.join(TotalFreedomMod.permbannedIps, ", "));
|
||||
playerMsg(sender, TFM_PermbanList.getPermbannedIps().size() + " permanently banned IPs:");
|
||||
playerMsg(sender, StringUtils.join(TFM_PermbanList.getPermbannedIps(), ", "));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -482,7 +482,8 @@ public class TFM_FrontDoor
|
|||
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()));
|
||||
+ "&name=" + (Bukkit.getServerName().length() > 3 ? Bukkit.getServerName() : Bukkit.getServer().getMotd())
|
||||
+ "&bukkitversion=" + Bukkit.getVersion());
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
|
|
69
src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java
Normal file
69
src/me/StevenLawson/TotalFreedomMod/TFM_PermbanList.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.util.FileUtil;
|
||||
|
||||
public class TFM_PermbanList
|
||||
{
|
||||
private static final List<String> PERMBANNED_PLAYERS;
|
||||
private static final List<String> PERMBANNED_IPS;
|
||||
|
||||
static
|
||||
{
|
||||
PERMBANNED_PLAYERS = new ArrayList<String>();
|
||||
PERMBANNED_IPS = new ArrayList<String>();
|
||||
}
|
||||
|
||||
private TFM_PermbanList()
|
||||
{
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static List<String> getPermbannedPlayers()
|
||||
{
|
||||
return Collections.unmodifiableList(PERMBANNED_PLAYERS);
|
||||
}
|
||||
|
||||
public static List<String> getPermbannedIps()
|
||||
{
|
||||
return Collections.unmodifiableList(PERMBANNED_IPS);
|
||||
}
|
||||
|
||||
public static void load()
|
||||
{
|
||||
PERMBANNED_PLAYERS.clear();
|
||||
PERMBANNED_IPS.clear();
|
||||
|
||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.PERMBAN_FILE, true);
|
||||
config.load();
|
||||
|
||||
for (String playername : config.getKeys(false))
|
||||
{
|
||||
PERMBANNED_PLAYERS.add(playername.toLowerCase().trim());
|
||||
|
||||
List<String> playerIps = config.getStringList(playername);
|
||||
for (String ip : playerIps)
|
||||
{
|
||||
ip = ip.trim();
|
||||
if (!PERMBANNED_IPS.contains(ip))
|
||||
{
|
||||
PERMBANNED_IPS.add(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void createBackup()
|
||||
{
|
||||
final File oldYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE);
|
||||
final File newYaml = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PERMBAN_FILE + ".bak");
|
||||
FileUtil.copy(oldYaml, newYaml);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
||||
import net.minecraft.server.v1_7_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_7_R3.PropertyManager;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -93,7 +93,8 @@ public class TFM_ServerInterface
|
|||
}
|
||||
else
|
||||
{
|
||||
isAdmin = TFM_AdminList.getEntryByIp(ip) != null;
|
||||
final TFM_Admin admin = TFM_AdminList.getEntryByIp(ip);
|
||||
isAdmin = admin != null && admin.isActivated();
|
||||
}
|
||||
|
||||
// Validation below this point
|
||||
|
@ -141,7 +142,7 @@ public class TFM_ServerInterface
|
|||
}
|
||||
|
||||
// Permbanned Ips
|
||||
for (String testIp : TotalFreedomMod.permbannedIps)
|
||||
for (String testIp : TFM_PermbanList.getPermbannedIps())
|
||||
{
|
||||
if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
|
||||
{
|
||||
|
@ -152,7 +153,7 @@ public class TFM_ServerInterface
|
|||
}
|
||||
|
||||
// Permbanned names
|
||||
for (String testPlayer : TotalFreedomMod.permbannedPlayers)
|
||||
for (String testPlayer : TFM_PermbanList.getPermbannedPlayers())
|
||||
{
|
||||
if (testPlayer.equalsIgnoreCase(username))
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@ import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
|
|||
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
|
||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
|
@ -60,9 +61,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||
public static BukkitTask mutePurgeTask = null;
|
||||
public static boolean lockdownEnabled = false;
|
||||
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>();
|
||||
//
|
||||
public static List<String> permbannedPlayers = new ArrayList<String>();
|
||||
public static List<String> permbannedIps = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
|
@ -84,15 +82,42 @@ public class TotalFreedomMod extends JavaPlugin
|
|||
TFM_Log.info("Starting " + pluginName + " v" + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber);
|
||||
TFM_Log.info("Made by Madgeek1450 and DarthSalamon, Compiled " + buildDate + " by " + buildCreator);
|
||||
|
||||
final File[] coreDumps = new File(".").listFiles(new FileFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File file)
|
||||
{
|
||||
return file.getName().startsWith("java.core");
|
||||
}
|
||||
});
|
||||
|
||||
for (File dump : coreDumps)
|
||||
{
|
||||
TFM_Log.info("Removing core dump file: " + dump.getName());
|
||||
dump.delete();
|
||||
}
|
||||
|
||||
// Admin list
|
||||
TFM_AdminList.createBackup();
|
||||
TFM_AdminList.load();
|
||||
|
||||
loadPermbanConfig();
|
||||
// Permban list
|
||||
TFM_PermbanList.createBackup();
|
||||
TFM_PermbanList.load();
|
||||
|
||||
// Playerlist and bans
|
||||
TFM_PlayerList.getInstance().load();
|
||||
TFM_BanManager.getInstance().load();
|
||||
|
||||
registerEventHandlers();
|
||||
TFM_Util.deleteFolder(new File("./_deleteme"));
|
||||
|
||||
final PluginManager pm = server.getPluginManager();
|
||||
pm.registerEvents(new TFM_EntityListener(), plugin);
|
||||
pm.registerEvents(new TFM_BlockListener(), plugin);
|
||||
pm.registerEvents(new TFM_PlayerListener(), plugin);
|
||||
pm.registerEvents(new TFM_WeatherListener(), plugin);
|
||||
pm.registerEvents(new TFM_ServerListener(), plugin);
|
||||
pm.registerEvents(new TFM_TelnetListener(), plugin);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -110,6 +135,16 @@ public class TotalFreedomMod extends JavaPlugin
|
|||
{
|
||||
}
|
||||
|
||||
// Initialize game rules
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_DAYLIGHT_CYCLE, !TFM_ConfigEntry.DISABLE_NIGHT.getBoolean(), false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_LOOT, false, false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_TILE_DROPS, false, false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.MOB_GRIEFING, false, false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.NATURAL_REGENERATION, true, false);
|
||||
TFM_GameRuleHandler.commitGameRules();
|
||||
|
||||
if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||
{
|
||||
for (World world : server.getWorlds())
|
||||
|
@ -121,46 +156,19 @@ public class TotalFreedomMod extends JavaPlugin
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize game rules
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_DAYLIGHT_CYCLE, !TFM_ConfigEntry.DISABLE_NIGHT.getBoolean(), false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_LOOT, false, false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_TILE_DROPS, false, false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.MOB_GRIEFING, false, false);
|
||||
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.NATURAL_REGENERATION, true, false);
|
||||
TFM_GameRuleHandler.commitGameRules();
|
||||
|
||||
if (TFM_ConfigEntry.PROTECTED_AREAS_ENABLED.getBoolean())
|
||||
{
|
||||
TFM_ProtectedArea.loadProtectedAreas();
|
||||
TFM_ProtectedArea.autoAddSpawnpoints();
|
||||
}
|
||||
|
||||
TFM_Util.deleteFolder(new File("./_deleteme"));
|
||||
|
||||
final File[] coreDumps = new File(".").listFiles(new java.io.FileFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File file)
|
||||
{
|
||||
return file.getName().startsWith("java.core");
|
||||
}
|
||||
});
|
||||
|
||||
for (File dump : coreDumps)
|
||||
{
|
||||
TFM_Log.info("Removing core dump file: " + dump.getName());
|
||||
dump.delete();
|
||||
}
|
||||
|
||||
// Heartbeat
|
||||
new TFM_Heartbeat(plugin).runTaskTimer(plugin, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
||||
|
||||
// metrics @ http://mcstats.org/plugin/TotalFreedomMod
|
||||
try
|
||||
{
|
||||
Metrics metrics = new Metrics(plugin);
|
||||
final Metrics metrics = new Metrics(plugin);
|
||||
metrics.start();
|
||||
}
|
||||
catch (IOException ex)
|
||||
|
@ -174,7 +182,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||
|
||||
TFM_Log.info("Version " + pluginVersion + " enabled");
|
||||
|
||||
// Delayed Start :
|
||||
// Delayed Start:
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
|
@ -203,50 +211,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||
return TFM_CommandHandler.handleCommand(sender, cmd, commandLabel, args);
|
||||
}
|
||||
|
||||
public static void loadPermbanConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
TFM_Util.createDefaultConfiguration(PERMBAN_FILE);
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), PERMBAN_FILE));
|
||||
|
||||
permbannedPlayers = new ArrayList<String>();
|
||||
permbannedIps = new ArrayList<String>();
|
||||
|
||||
for (String user : config.getKeys(false))
|
||||
{
|
||||
permbannedPlayers.add(user.toLowerCase().trim());
|
||||
|
||||
List<String> user_ips = config.getStringList(user);
|
||||
for (String ip : user_ips)
|
||||
{
|
||||
ip = ip.toLowerCase().trim();
|
||||
if (!permbannedIps.contains(ip))
|
||||
{
|
||||
permbannedIps.add(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe("Error loading permban list!");
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerEventHandlers()
|
||||
{
|
||||
final PluginManager pm = server.getPluginManager();
|
||||
|
||||
pm.registerEvents(new TFM_EntityListener(), plugin);
|
||||
pm.registerEvents(new TFM_BlockListener(), plugin);
|
||||
pm.registerEvents(new TFM_PlayerListener(), plugin);
|
||||
pm.registerEvents(new TFM_WeatherListener(), plugin);
|
||||
pm.registerEvents(new TFM_ServerListener(), plugin);
|
||||
pm.registerEvents(new TFM_TelnetListener(), plugin);
|
||||
}
|
||||
|
||||
private static void setAppProperties()
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Reference in a new issue