Config migration, stage 3

This commit is contained in:
Steven Lawson 2013-08-18 15:52:32 -04:00
parent f53b67abf1
commit 4494a4c039
16 changed files with 61 additions and 237 deletions

View File

@ -2,7 +2,6 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -23,7 +22,7 @@ public class Command_explosives extends TFM_Command
{ {
try try
{ {
TotalFreedomMod.explosiveRadius = Math.max(1.0, Math.min(30.0, Double.parseDouble(args[1]))); TFM_ConfigEntry.EXPLOSIVE_RADIUS.setDouble(Math.max(1.0, Math.min(30.0, Double.parseDouble(args[1]))));
} }
catch (NumberFormatException nfex) catch (NumberFormatException nfex)
{ {
@ -35,7 +34,7 @@ public class Command_explosives extends TFM_Command
if (args[0].equalsIgnoreCase("on")) if (args[0].equalsIgnoreCase("on"))
{ {
TFM_ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true); TFM_ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true);
playerMsg("Explosives are now enabled, radius set to " + TotalFreedomMod.explosiveRadius + " blocks."); playerMsg("Explosives are now enabled, radius set to " + TFM_ConfigEntry.EXPLOSIVE_RADIUS.getDouble() + " blocks.");
} }
else else
{ {

View File

@ -9,6 +9,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin; import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
@ -46,12 +47,10 @@ public class Command_logs extends TFM_Command
public static void updateLogsRegistration(final CommandSender sender, final String targetName, final String targetIP, final LogsRegistrationMode mode) public static void updateLogsRegistration(final CommandSender sender, final String targetName, final String targetIP, final LogsRegistrationMode mode)
{ {
if (TotalFreedomMod.logsRegisterURL == null || TotalFreedomMod.logsRegisterPassword == null) final String logsRegisterURL = TFM_ConfigEntry.LOGS_REGISTER_URL.getString();
{ final String logsRegisterPassword = TFM_ConfigEntry.LOGS_REGISTER_PASSWORD.getString();
return;
}
if (TotalFreedomMod.logsRegisterPassword.isEmpty() || TotalFreedomMod.logsRegisterURL.isEmpty()) if (logsRegisterURL == null || logsRegisterPassword == null || logsRegisterURL.isEmpty() || logsRegisterPassword.isEmpty())
{ {
return; return;
} }
@ -68,9 +67,9 @@ public class Command_logs extends TFM_Command
sender.sendMessage(ChatColor.YELLOW + "Connecting..."); sender.sendMessage(ChatColor.YELLOW + "Connecting...");
} }
URL url = new URLBuilder(TotalFreedomMod.logsRegisterURL) URL url = new URLBuilder(logsRegisterURL)
.addQueryParameter("mode", mode.toString()) .addQueryParameter("mode", mode.toString())
.addQueryParameter("password", TotalFreedomMod.logsRegisterPassword) .addQueryParameter("password", logsRegisterPassword)
.addQueryParameter("name", targetName) .addQueryParameter("name", targetName)
.addQueryParameter("ip", targetIP) .addQueryParameter("ip", targetIP)
.getURL(); .getURL();

View File

@ -33,7 +33,7 @@ public class Command_premium extends TFM_Command
{ {
name = args[0]; name = args[0];
} }
final String playername = name; final String playername = name;
new BukkitRunnable() new BukkitRunnable()
{ {
@ -66,7 +66,7 @@ public class Command_premium extends TFM_Command
} }
} }
}.runTaskAsynchronously(plugin); }.runTaskAsynchronously(plugin);
return true; return true;
} }
} }

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin; import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler; import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
@ -150,13 +151,13 @@ public class Command_saconfig extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true); TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
TFM_SuperadminList.removeSuperadmin(targetName); TFM_SuperadminList.removeSuperadmin(targetName);
if (!TotalFreedomMod.twitterbotEnabled) if (!TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
{ {
return true; return true;
} }
// Twitterbot // Twitterbot
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance(plugin); TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance();
String reply = twitterbot.delTwitter(targetName); String reply = twitterbot.delTwitter(targetName);
if ("ok".equals(reply)) if ("ok".equals(reply))
{ {

View File

@ -1,8 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -19,7 +19,7 @@ public class Command_tossmob extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (!TotalFreedomMod.tossmobEnabled) if (!TFM_ConfigEntry.TOSSMOB_ENABLED.getBoolean())
{ {
playerMsg("Tossmob is currently disabled."); playerMsg("Tossmob is currently disabled.");
return true; return true;

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler; import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
@ -15,7 +16,7 @@ public class Command_twitter extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (!TotalFreedomMod.twitterbotEnabled) if (!TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
{ {
TFM_Util.playerMsg(sender, "TwitterBot has been disabled in config.", ChatColor.RED); TFM_Util.playerMsg(sender, "TwitterBot has been disabled in config.", ChatColor.RED);
return true; return true;
@ -26,7 +27,7 @@ public class Command_twitter extends TFM_Command
return false; return false;
} }
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance(plugin); TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance();
if ("set".equals(args[0])) if ("set".equals(args[0]))
{ {

View File

@ -1,7 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Listener; package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -31,7 +30,7 @@ public class TFM_EntityListener implements Listener
return; return;
} }
event.setRadius((float) TotalFreedomMod.explosiveRadius); event.setRadius((float) TFM_ConfigEntry.EXPLOSIVE_RADIUS.getDouble().doubleValue());
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)

View File

@ -19,7 +19,7 @@ public class TFM_AdminWorld
{ {
private static final long CACHE_CLEAR_FREQUENCY = 30L * 1000L; //30 seconds, milliseconds private static final long CACHE_CLEAR_FREQUENCY = 30L * 1000L; //30 seconds, milliseconds
private static final long TP_COOLDOWN_TIME = 500L; //0.5 seconds, milliseconds private static final long TP_COOLDOWN_TIME = 500L; //0.5 seconds, milliseconds
private static final String GENERATION_PARAMETERS = "16,stone,32,dirt,1,grass"; private static final String GENERATION_PARAMETERS = TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString();
private static final String ADMINWORLD_NAME = "adminworld"; private static final String ADMINWORLD_NAME = "adminworld";
// //
private final Map<Player, Long> teleportCooldown = new HashMap<Player, Long>(); private final Map<Player, Long> teleportCooldown = new HashMap<Player, Long>();

View File

@ -1,164 +0,0 @@
package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class TFM_CommandBlocker
{
public static boolean isCommandBlocked(String usedcommand, CommandSender sender)
{
String name = sender.getName();
usedcommand = usedcommand.toLowerCase().trim();
for (String blocked_command : TotalFreedomMod.blockedCommands)
{
String[] parts = blocked_command.split(":");
if (parts.length < 3 || parts.length > 4)
{
continue;
}
if (!(usedcommand + " ").startsWith(parts[2] + " "))
{
CommandMap commandMap = TFM_CommandLoader.getInstance().getCommandMap();
if (commandMap == null)
{
continue;
}
Command command = commandMap.getCommand(parts[2].replaceAll("/", ""));
if (command == null)
{
continue;
}
boolean block = false;
for (String alias : command.getAliases())
{
if (usedcommand.replaceAll("/", "").startsWith(alias))
{
block = true;
break;
}
}
if (!block)
{
continue;
}
}
if (SenderRank.hasPermissions(sender, parts[0]))
{
continue;
}
// Past this line indicates that the command is blocked.
// Optional: Send a message
if (parts.length == 4)
{
if ("_".equals(parts[3]))
{
sender.sendMessage(ChatColor.GRAY + "That command is blocked.");
}
else
{
sender.sendMessage(ChatColor.GRAY + TFM_Util.colorise(parts[3]));
}
}
// Action
if ("b".equals(parts[1]))
{
return true;
}
else if ("a".equals(parts[1]))
{
if (SenderRank.getSenderRank(sender).rank < 2) // Only auto-eject Ops and non-ops
{
TFM_Util.autoEject((Player) sender, "You used a prohibited command: " + usedcommand);
TFM_Util.bcastMsg(name + " was automatically kicked for using harmful commands.", ChatColor.RED);
}
return true;
}
else if ("u".equals(parts[1]))
{
sender.sendMessage("Unknown command. Type \"help\" for help.");
return true;
}
return false;
}
return false;
}
public enum SenderRank
{
ANYONE("a", 0),
OP("o", 1),
SUPER("s", 2),
TELNET("t", 3),
SENIOR("c", 4),
NOBODY("n", 5);
private String letter = "n";
private int rank = 5;
SenderRank(String letter, int rank)
{
this.letter = letter;
this.rank = rank;
}
public static boolean hasPermissions(CommandSender sender, String letter)
{
return (getSenderRank(sender).rank >= getSenderRankByLetter(letter).rank);
}
public static SenderRank getSenderRank(CommandSender sender)
{
if (!(sender instanceof Player))
{
if (TFM_SuperadminList.isSeniorAdmin(sender))
{
return SenderRank.SENIOR;
}
else
{
return SenderRank.TELNET;
}
}
if (TFM_SuperadminList.isUserSuperadmin(sender))
{
return SenderRank.SUPER;
}
if (sender.isOp())
{
return SenderRank.OP;
}
return SenderRank.ANYONE;
}
public static SenderRank getSenderRankByLetter(String letter)
{
for (SenderRank rank : SenderRank.values())
{
if (letter.equals(rank.letter))
{
return rank;
}
}
return SenderRank.NOBODY;
}
}
}

View File

@ -1,6 +1,7 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -20,6 +21,7 @@ public class TFM_CommandBlockerNew
parseBlockingRules(); parseBlockingRules();
} }
@SuppressWarnings("unchecked")
public final void parseBlockingRules() public final void parseBlockingRules()
{ {
blockedCommands.clear(); blockedCommands.clear();
@ -31,7 +33,8 @@ public class TFM_CommandBlockerNew
return; return;
} }
for (String rawEntry : TotalFreedomMod.blockedCommands) List<String> _blockedCommands = (List<String>) TFM_ConfigEntry.BLOCKED_COMMANDS.getList();
for (String rawEntry : _blockedCommands)
{ {
String[] parts = rawEntry.split(":"); String[] parts = rawEntry.split(":");
if (parts.length < 3 || parts.length > 4) if (parts.length < 3 || parts.length > 4)

View File

@ -114,7 +114,7 @@ public enum TFM_ConfigEntry
return value; return value;
} }
public List getList(TFM_ConfigEntry entry) public List getList()
{ {
return TFM_Config.getInstance().getList(this); return TFM_Config.getInstance().getList(this);
} }

View File

@ -119,7 +119,7 @@ public class TFM_ProtectedArea implements Serializable
{ {
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())
{ {
TFM_ProtectedArea.addProtectedArea("spawn_" + world.getName(), world.getSpawnLocation(), TotalFreedomMod.autoProtectRadius); TFM_ProtectedArea.addProtectedArea("spawn_" + world.getName(), world.getSpawnLocation(), TFM_ConfigEntry.AUTO_PROTECT_RADIUS.getDouble());
} }
} }
} }

View File

@ -40,9 +40,16 @@ public class TFM_ServiceChecker
@Override @Override
public void run() public void run()
{ {
final String serviceCheckerURL = TFM_ConfigEntry.SERVICE_CHECKER_URL.getString();
if (serviceCheckerURL == null || serviceCheckerURL.isEmpty())
{
return;
}
try try
{ {
URL mojang_status = new URL(TotalFreedomMod.serviceCheckerURL); URL mojang_status = new URL(serviceCheckerURL);
BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream())); BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream()));
JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine()); JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine());
in.close(); in.close();
@ -90,7 +97,7 @@ public class TFM_ServiceChecker
} }
catch (Exception ex) catch (Exception ex)
{ {
TFM_Log.severe("Error updating mojang services from " + TotalFreedomMod.serviceCheckerURL); TFM_Log.severe("Error updating mojang services from " + serviceCheckerURL);
TFM_Log.severe(ex); TFM_Log.severe(ex);
} }
} }

View File

@ -8,11 +8,8 @@ import org.apache.commons.lang.exception.ExceptionUtils;
public class TFM_TwitterHandler public class TFM_TwitterHandler
{ {
private TotalFreedomMod plugin; private TFM_TwitterHandler()
private TFM_TwitterHandler(TotalFreedomMod plugin)
{ {
this.plugin = plugin;
} }
public String getTwitter(String player) public String getTwitter(String player)
@ -47,24 +44,32 @@ public class TFM_TwitterHandler
private String request(String queryString) private String request(String queryString)
{ {
String line = "failed"; String line = "failed";
try
final String twitterbotURL = TFM_ConfigEntry.TWITTERBOT_URL.getString();
final String twitterbotSecret = TFM_ConfigEntry.TWITTERBOT_SECRET.getString();
if (twitterbotURL != null && twitterbotSecret != null && !twitterbotURL.isEmpty() && !twitterbotSecret.isEmpty())
{ {
URL getUrl = new URL(TotalFreedomMod.twitterbotURL + "?auth=" + TotalFreedomMod.twitterbotSecret + "&" + queryString); try
URLConnection urlConnection = getUrl.openConnection(); {
// Read the response URL getUrl = new URL(twitterbotURL + "?auth=" + twitterbotSecret + "&" + queryString);
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); URLConnection urlConnection = getUrl.openConnection();
line = in.readLine(); // Read the response
in.close(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
} line = in.readLine();
catch (Exception ex) in.close();
{ }
TFM_Log.severe(ExceptionUtils.getFullStackTrace(ex)); catch (Exception ex)
{
TFM_Log.severe(ExceptionUtils.getFullStackTrace(ex));
}
} }
return line; return line;
} }
public static TFM_TwitterHandler getInstance(TotalFreedomMod plugin) public static TFM_TwitterHandler getInstance()
{ {
return new TFM_TwitterHandler(plugin); return new TFM_TwitterHandler();
} }
} }

View File

@ -496,7 +496,7 @@ public class TFM_Util
public static void generateFlatlands() public static void generateFlatlands()
{ {
generateFlatlands(TotalFreedomMod.flatlandsGenerationParams); generateFlatlands(TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString());
} }
public static void generateFlatlands(String genParams) public static void generateFlatlands(String genParams)
@ -791,9 +791,10 @@ public class TFM_Util
} }
} }
@SuppressWarnings("unchecked")
public static boolean isFromHostConsole(String sender_name) public static boolean isFromHostConsole(String sender_name)
{ {
return TotalFreedomMod.host_sender_names.contains(sender_name.toLowerCase()); return ((List<String>) TFM_ConfigEntry.HOST_SENDER_NAMES.getList()).contains(sender_name.toLowerCase());
} }
public static List<String> removeDuplicates(List<String> old_list) public static List<String> removeDuplicates(List<String> old_list)

View File

@ -79,7 +79,7 @@ public class TotalFreedomMod extends JavaPlugin
if (TFM_ConfigEntry.GENERATE_FLATLANDS.getBoolean()) if (TFM_ConfigEntry.GENERATE_FLATLANDS.getBoolean())
{ {
TFM_Util.wipeFlatlandsIfFlagged(); TFM_Util.wipeFlatlandsIfFlagged();
TFM_Util.generateFlatlands(flatlandsGenerationParams); TFM_Util.generateFlatlands(TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString());
} }
TFM_AdminWorld.getInstance().getAdminWorld(); TFM_AdminWorld.getInstance().getAdminWorld();
@ -228,33 +228,6 @@ public class TotalFreedomMod extends JavaPlugin
return true; return true;
} }
//
@Deprecated
public static boolean protectedAreasEnabled = true;
@Deprecated
public static boolean tossmobEnabled = false;
@Deprecated
public static boolean twitterbotEnabled = false;
@Deprecated
public static double autoProtectRadius = 25.0D;
@Deprecated
public static double explosiveRadius = 4.0D;
@Deprecated
public static List<String> blockedCommands = new ArrayList<String>();
@Deprecated
public static List<String> host_sender_names = Arrays.asList("rcon", "remotebukkit");
@Deprecated
public static String flatlandsGenerationParams = "16,stone,32,dirt,1,grass";
@Deprecated
public static String logsRegisterPassword = "";
@Deprecated
public static String logsRegisterURL = "";
@Deprecated
public static String serviceCheckerURL = "http://status.mojang.com/check";
@Deprecated
public static String twitterbotSecret = "";
@Deprecated
public static String twitterbotURL = "";
public static void loadSuperadminConfig() public static void loadSuperadminConfig()
{ {