mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
Config migration, stage 3
This commit is contained in:
parent
f53b67abf1
commit
4494a4c039
@ -2,7 +2,6 @@ package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -23,7 +22,7 @@ public class Command_explosives extends TFM_Command
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -35,7 +34,7 @@ public class Command_explosives extends TFM_Command
|
||||
if (args[0].equalsIgnoreCase("on"))
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -9,6 +9,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||
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)
|
||||
{
|
||||
if (TotalFreedomMod.logsRegisterURL == null || TotalFreedomMod.logsRegisterPassword == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
final String logsRegisterURL = TFM_ConfigEntry.LOGS_REGISTER_URL.getString();
|
||||
final String logsRegisterPassword = TFM_ConfigEntry.LOGS_REGISTER_PASSWORD.getString();
|
||||
|
||||
if (TotalFreedomMod.logsRegisterPassword.isEmpty() || TotalFreedomMod.logsRegisterURL.isEmpty())
|
||||
if (logsRegisterURL == null || logsRegisterPassword == null || logsRegisterURL.isEmpty() || logsRegisterPassword.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -68,9 +67,9 @@ public class Command_logs extends TFM_Command
|
||||
sender.sendMessage(ChatColor.YELLOW + "Connecting...");
|
||||
}
|
||||
|
||||
URL url = new URLBuilder(TotalFreedomMod.logsRegisterURL)
|
||||
URL url = new URLBuilder(logsRegisterURL)
|
||||
.addQueryParameter("mode", mode.toString())
|
||||
.addQueryParameter("password", TotalFreedomMod.logsRegisterPassword)
|
||||
.addQueryParameter("password", logsRegisterPassword)
|
||||
.addQueryParameter("name", targetName)
|
||||
.addQueryParameter("ip", targetIP)
|
||||
.getURL();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||
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_SuperadminList.removeSuperadmin(targetName);
|
||||
|
||||
if (!TotalFreedomMod.twitterbotEnabled)
|
||||
if (!TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Twitterbot
|
||||
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance(plugin);
|
||||
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance();
|
||||
String reply = twitterbot.delTwitter(targetName);
|
||||
if ("ok".equals(reply))
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -19,7 +19,7 @@ public class Command_tossmob extends TFM_Command
|
||||
@Override
|
||||
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.");
|
||||
return true;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
@ -15,7 +16,7 @@ public class Command_twitter extends TFM_Command
|
||||
@Override
|
||||
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);
|
||||
return true;
|
||||
@ -26,7 +27,7 @@ public class Command_twitter extends TFM_Command
|
||||
return false;
|
||||
}
|
||||
|
||||
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance(plugin);
|
||||
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance();
|
||||
|
||||
if ("set".equals(args[0]))
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Listener;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -31,7 +30,7 @@ public class TFM_EntityListener implements Listener
|
||||
return;
|
||||
}
|
||||
|
||||
event.setRadius((float) TotalFreedomMod.explosiveRadius);
|
||||
event.setRadius((float) TFM_ConfigEntry.EXPLOSIVE_RADIUS.getDouble().doubleValue());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
|
@ -19,7 +19,7 @@ public class TFM_AdminWorld
|
||||
{
|
||||
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 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 final Map<Player, Long> teleportCooldown = new HashMap<Player, Long>();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -20,6 +21,7 @@ public class TFM_CommandBlockerNew
|
||||
parseBlockingRules();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final void parseBlockingRules()
|
||||
{
|
||||
blockedCommands.clear();
|
||||
@ -31,7 +33,8 @@ public class TFM_CommandBlockerNew
|
||||
return;
|
||||
}
|
||||
|
||||
for (String rawEntry : TotalFreedomMod.blockedCommands)
|
||||
List<String> _blockedCommands = (List<String>) TFM_ConfigEntry.BLOCKED_COMMANDS.getList();
|
||||
for (String rawEntry : _blockedCommands)
|
||||
{
|
||||
String[] parts = rawEntry.split(":");
|
||||
if (parts.length < 3 || parts.length > 4)
|
||||
|
@ -114,7 +114,7 @@ public enum TFM_ConfigEntry
|
||||
return value;
|
||||
}
|
||||
|
||||
public List getList(TFM_ConfigEntry entry)
|
||||
public List getList()
|
||||
{
|
||||
return TFM_Config.getInstance().getList(this);
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public class TFM_ProtectedArea implements Serializable
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,9 +40,16 @@ public class TFM_ServiceChecker
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final String serviceCheckerURL = TFM_ConfigEntry.SERVICE_CHECKER_URL.getString();
|
||||
|
||||
if (serviceCheckerURL == null || serviceCheckerURL.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
URL mojang_status = new URL(TotalFreedomMod.serviceCheckerURL);
|
||||
URL mojang_status = new URL(serviceCheckerURL);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream()));
|
||||
JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine());
|
||||
in.close();
|
||||
@ -90,7 +97,7 @@ public class TFM_ServiceChecker
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -8,11 +8,8 @@ import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
|
||||
public class TFM_TwitterHandler
|
||||
{
|
||||
private TotalFreedomMod plugin;
|
||||
|
||||
private TFM_TwitterHandler(TotalFreedomMod plugin)
|
||||
private TFM_TwitterHandler()
|
||||
{
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public String getTwitter(String player)
|
||||
@ -47,9 +44,15 @@ public class TFM_TwitterHandler
|
||||
private String request(String queryString)
|
||||
{
|
||||
String line = "failed";
|
||||
|
||||
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())
|
||||
{
|
||||
try
|
||||
{
|
||||
URL getUrl = new URL(TotalFreedomMod.twitterbotURL + "?auth=" + TotalFreedomMod.twitterbotSecret + "&" + queryString);
|
||||
URL getUrl = new URL(twitterbotURL + "?auth=" + twitterbotSecret + "&" + queryString);
|
||||
URLConnection urlConnection = getUrl.openConnection();
|
||||
// Read the response
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
@ -60,11 +63,13 @@ public class TFM_TwitterHandler
|
||||
{
|
||||
TFM_Log.severe(ExceptionUtils.getFullStackTrace(ex));
|
||||
}
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
public static TFM_TwitterHandler getInstance(TotalFreedomMod plugin)
|
||||
public static TFM_TwitterHandler getInstance()
|
||||
{
|
||||
return new TFM_TwitterHandler(plugin);
|
||||
return new TFM_TwitterHandler();
|
||||
}
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ public class TFM_Util
|
||||
|
||||
public static void generateFlatlands()
|
||||
{
|
||||
generateFlatlands(TotalFreedomMod.flatlandsGenerationParams);
|
||||
generateFlatlands(TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString());
|
||||
}
|
||||
|
||||
public static void generateFlatlands(String genParams)
|
||||
@ -791,9 +791,10 @@ public class TFM_Util
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
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)
|
||||
|
@ -79,7 +79,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
if (TFM_ConfigEntry.GENERATE_FLATLANDS.getBoolean())
|
||||
{
|
||||
TFM_Util.wipeFlatlandsIfFlagged();
|
||||
TFM_Util.generateFlatlands(flatlandsGenerationParams);
|
||||
TFM_Util.generateFlatlands(TFM_ConfigEntry.FLATLANDS_GENERATION_PARAMS.getString());
|
||||
}
|
||||
|
||||
TFM_AdminWorld.getInstance().getAdminWorld();
|
||||
@ -228,33 +228,6 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
|
||||
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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user