Config build change to new ConfigBuilder

This commit is contained in:
JaTiTV 2024-07-03 03:32:03 +02:00
parent c89430b219
commit 35ac13b695
17 changed files with 526 additions and 418 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2C-OPSecurity</artifactId> <artifactId>T2C-OPSecurity</artifactId>
<version>3.2</version> <version>3.3_DEV-1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
@ -83,7 +83,8 @@
<dependency> <dependency>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId> <artifactId>T2CodeLib</artifactId>
<version>16.4</version> <version>16.7</version>
<classifier>dev-3</classifier>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

View File

@ -15,18 +15,18 @@ import java.util.Map;
public class T2COpSecAPI { public class T2COpSecAPI {
public static boolean checkOPWhiteList(Player player) { public static boolean checkOPWhiteList(Player player) {
if (!OPWhitelist.enable.valueBoolean) return true; if (!(boolean) OPWhitelist.VALUES.enable.getValue()) return true;
String debug = T2Cdebug.debugCode(); String debug = T2Cdebug.debugCode();
return OpCheck.opWhitelist(player,debug); return OpCheck.opWhitelist(player, debug);
} }
public static boolean checkPermissionWhiteList(Player player, String debug) { public static boolean checkPermissionWhiteList(Player player, String debug) {
if (!PermissionWhitelist.enable.valueBoolean) return true; if (!(boolean) PermissionWhitelist.VALUES.enable.getValue()) return true;
return PermissionCheck.permWhitelist(player, debug); return PermissionCheck.permWhitelist(player, debug);
} }
public static T2COpSecAPIPlayerStatus detailCheckOPWhiteList(Player player) { public static T2COpSecAPIPlayerStatus detailCheckOPWhiteList(Player player) {
if (!OPWhitelist.enable.valueBoolean) return T2COpSecAPIPlayerStatus.playerOnOpWhitelist; if (!(boolean) OPWhitelist.VALUES.enable.getValue()) return T2COpSecAPIPlayerStatus.playerOnOpWhitelist;
List<String> nameList = new ArrayList<>(); List<String> nameList = new ArrayList<>();
List<String> uuidList = new ArrayList<>(); List<String> uuidList = new ArrayList<>();
for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getOpHashMap().entrySet()) { for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getOpHashMap().entrySet()) {
@ -41,8 +41,9 @@ public class T2COpSecAPI {
} }
return T2COpSecAPIPlayerStatus.playerOnOpWhitelist; return T2COpSecAPIPlayerStatus.playerOnOpWhitelist;
} }
public static T2COpSecAPIPlayerStatus detailCheckPermissionWhiteList(Player player) { public static T2COpSecAPIPlayerStatus detailCheckPermissionWhiteList(Player player) {
if (!PermissionWhitelist.enable.valueBoolean) return T2COpSecAPIPlayerStatus.playerOnPermissionWhitelist; if (!(boolean)PermissionWhitelist.VALUES.enable.getValue()) return T2COpSecAPIPlayerStatus.playerOnPermissionWhitelist;
List<String> nameList = new ArrayList<>(); List<String> nameList = new ArrayList<>();
List<String> uuidList = new ArrayList<>(); List<String> uuidList = new ArrayList<>();
for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getPermissionHashMap().entrySet()) { for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getPermissionHashMap().entrySet()) {

View File

@ -8,7 +8,7 @@ public class Util {
private static String infoText = ""; private static String infoText = "";
@Getter @Getter
private static String requiredT2CodeLibVersion = "15.0"; private static String requiredT2CodeLibVersion = "16.7";
@Getter @Getter
private static String prefix = "§8[§4T2C§8-§2OP§4Security§8]"; private static String prefix = "§8[§4T2C§8-§2OP§4Security§8]";
@ -27,8 +27,23 @@ public class Util {
@Getter @Getter
private static String discord = "http://dc.t2code.net"; private static String discord = "http://dc.t2code.net";
@Getter @Getter
private static Integer configVersion = 2; private static final String[] configLogo = new String[]{
"####################################################################################################################",
"## ##",
"## /$$$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$ ##",
"## |__ $$__//$$__ $$ /$$__ $$ | $$ | $$ ##",
"## | $$ |__/ \\ $$| $$ \\__/ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ ##",
"## | $$ /$$$$$$/| $$ /$$__ $$ /$$__ $$ /$$__ $$ | $$__ $$ /$$__ $$|_ $$_/ ##",
"## | $$ /$$____/ | $$ | $$ \\ $$| $$ | $$| $$$$$$$$ | $$ \\ $$| $$$$$$$$ | $$ ##",
"## | $$ | $$ | $$ $$| $$ | $$| $$ | $$| $$_____/ | $$ | $$| $$_____/ | $$ /$$ ##",
"## | $$ | $$$$$$$$| $$$$$$/| $$$$$$/| $$$$$$$| $$$$$$$ /$$| $$ | $$| $$$$$$$ | $$$$/ ##",
"## |__/ |________/ \\______/ \\______/ \\_______/ \\_______/|__/|__/ |__/ \\_______/ \\___/ ##",
"## ##",
"## T2CodeLib from JaTiTV / T2Code.net. In case of problems please contact the Discord: https://dc.t2code.net ##",
"## ##",
"####################################################################################################################"};
} }

View File

@ -1,5 +1,6 @@
package net.t2code.opsecurity.check; package net.t2code.opsecurity.check;
import com.sun.org.apache.xerces.internal.xs.StringList;
import net.t2code.opsecurity.config.config.Config; import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.language.Language; import net.t2code.opsecurity.config.language.Language;
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist; import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
@ -12,13 +13,15 @@ import net.t2code.t2codelib.SPIGOT.api.commands.T2Ccmd;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug; import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
import java.util.Map; import java.util.Map;
public class OpCheck { public class OpCheck {
public static Boolean onCheck(Player player, Boolean join, String debug) { public static Boolean onCheck(Player player, Boolean join, String debug) {
if (!OPWhitelist.enable.valueBoolean) return false; if (!(boolean) OPWhitelist.VALUES.enable.getValue()) return false;
if (!player.isOp()) return false; if (!player.isOp()) return false;
if (opWhitelist(player, debug)) return false; if (opWhitelist(player, debug)) return false;
if (join) T2Csend.console(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); if (join) T2Csend.console(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
@ -32,26 +35,26 @@ public class OpCheck {
} }
private static void execute(Player player, Boolean join, String debug) { private static void execute(Player player, Boolean join, String debug) {
if (Config.notifyJoinWarning.valueBoolean && join) { if ((boolean)Config.VALUES.notifyJoinWarning.getValue() && join) {
if (Config.notifyBungee.valueBoolean) { if ((boolean)Config.VALUES.notifyBungee.getValue()) {
BungeeSenderReceiver.sendToBungee(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); BungeeSenderReceiver.sendToBungee(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} else } else
Events.notifyPlayer(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); Events.notifyPlayer(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} }
if (OPWhitelist.noOpPlayerSetGameModeEnable.valueBoolean) { if ((boolean)OPWhitelist.VALUES.noOpPlayerSetGameModeEnable.getValue()) {
player.setGameMode(OPWhitelist.noOpPlayerSetGameModeValue.valueGameMode); player.setGameMode(GameMode.valueOf( OPWhitelist.VALUES.noOpPlayerSetGameModeValue.getValue().toString()));
} }
if (OPWhitelist.noOpPlayerDeopEnable.valueBoolean) { if ((boolean)OPWhitelist.VALUES.noOpPlayerDeopEnable.getValue()) {
player.setOp(false); player.setOp(false);
if (OPWhitelist.noOpPlayerKickEnable.valueBoolean) { if ((boolean)OPWhitelist.VALUES.noOpPlayerKickEnable.getValue()) {
if (!OPWhitelist.customCommandsEnable.valueBoolean) { if (!(boolean)OPWhitelist.VALUES.customCommandsEnable.getValue()) {
if (Config.kickCustomCommand.valueBoolean) { if ((boolean) Config.VALUES.kickCustomCommand.getValue()) {
T2Ccmd.console( Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]", T2Ccmd.console( Config.VALUES.kickCommand.getValue().toString().replace("[player]", player.getName()).replace("[reason]",
OPWhitelist.noOpPlayerKickEnable.valueBoolean && OPWhitelist.noOpPlayerDeopEnable.valueBoolean && OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean (boolean)OPWhitelist.VALUES.noOpPlayerKickEnable.getValue() && (boolean)OPWhitelist.VALUES.noOpPlayerDeopEnable.getValue() && (boolean)OPWhitelist.VALUES.noOpPlayerDeopPlayerSendMessage.getValue()
? Language.opWhitelistKick.value + "<br> <br>" + Language.opWhitelistDeop.value : Language.opWhitelistKick.value)); ? Language.opWhitelistKick.value + "<br> <br>" + Language.opWhitelistDeop.value : Language.opWhitelistKick.value));
} else player.kickPlayer(OPWhitelist.noOpPlayerDeopEnable.valueBoolean && OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean } else player.kickPlayer((boolean)OPWhitelist.VALUES.noOpPlayerDeopEnable.getValue() && (boolean)OPWhitelist.VALUES.noOpPlayerDeopPlayerSendMessage.getValue()
? Language.opWhitelistKick.value + "\n \n" + Language.opWhitelistDeop.value : Language.opWhitelistKick.value); ? Language.opWhitelistKick.value + "\n \n" + Language.opWhitelistDeop.value : Language.opWhitelistKick.value);
} }
T2Csend.console("["+debug+ "]" +Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName().replace("[uuid]", String.valueOf(player.getUniqueId()))) + "<br>" T2Csend.console("["+debug+ "]" +Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName().replace("[uuid]", String.valueOf(player.getUniqueId()))) + "<br>"
@ -62,7 +65,7 @@ public class OpCheck {
T2Csend.console("["+debug+ "]" +Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); T2Csend.console("["+debug+ "]" +Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
Events.notifyPlayer(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); Events.notifyPlayer(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
if (OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean) { if ((boolean)OPWhitelist.VALUES.noOpPlayerDeopPlayerSendMessage.getValue()) {
Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
@ -72,19 +75,19 @@ public class OpCheck {
} }
} }
} }
if (OPWhitelist.noOpPlayerKickEnable.valueBoolean) { if ((boolean)OPWhitelist.VALUES.noOpPlayerKickEnable.getValue()) {
if (!OPWhitelist.noOpPlayerDeopEnable.valueBoolean) { if (!(boolean)OPWhitelist.VALUES.noOpPlayerDeopEnable.getValue()) {
if (!OPWhitelist.customCommandsEnable.valueBoolean) { if (!(boolean)OPWhitelist.VALUES.customCommandsEnable.getValue()) {
if (Config.kickCustomCommand.valueBoolean) { if ((boolean)Config.VALUES.kickCustomCommand.getValue()) {
T2Ccmd.console(Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]", Language.opWhitelistKick.value)); T2Ccmd.console(Config.VALUES.kickCommand.getValue().toString().replace("[player]", player.getName()).replace("[reason]", Language.opWhitelistKick.value));
} else player.kickPlayer(Language.opWhitelistKick.value); } else player.kickPlayer(Language.opWhitelistKick.value);
} }
T2Csend.console("["+debug+ "]" +Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); T2Csend.console("["+debug+ "]" +Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
Events.notifyPlayer(Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); Events.notifyPlayer(Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} }
} }
if (OPWhitelist.customCommandsEnable.valueBoolean) { if ((boolean)OPWhitelist.VALUES.customCommandsEnable.getValue()) {
for (String cmd : OPWhitelist.customCommandsCommands.valueStringList) { for (String cmd : (StringList)OPWhitelist.VALUES.customCommandsCommands.getValue()) {
T2Ccmd.console(cmd.replace("[player]", player.getName())); T2Ccmd.console(cmd.replace("[player]", player.getName()));
} }
} }

View File

@ -1,5 +1,6 @@
package net.t2code.opsecurity.check; package net.t2code.opsecurity.check;
import com.sun.org.apache.xerces.internal.xs.StringList;
import net.t2code.opsecurity.config.config.Config; import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.language.Language; import net.t2code.opsecurity.config.language.Language;
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist; import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist;
@ -18,8 +19,8 @@ import java.util.Map;
public class PermissionCheck { public class PermissionCheck {
public static Boolean onCheck(Player player, Boolean join, String debug) { public static Boolean onCheck(Player player, Boolean join, String debug) {
if (!PermissionWhitelist.enable.valueBoolean) return false; if (!(boolean) PermissionWhitelist.VALUES.enable.getValue()) return false;
for (String perm : PermissionWhitelist.permissions.valueStringList) { for (String perm : (StringList) PermissionWhitelist.VALUES.permissions.getValue()) {
if (!player.hasPermission(perm)) return false; if (!player.hasPermission(perm)) return false;
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] check Permission: " + perm); T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] check Permission: " + perm);
if (permWhitelist(player, debug)) return false; if (permWhitelist(player, debug)) return false;
@ -37,22 +38,22 @@ public class PermissionCheck {
private static void execute(Player player, Boolean join, String perm, String debug) { private static void execute(Player player, Boolean join, String perm, String debug) {
if (join) if (join)
T2Csend.console("[" + debug + "]" + Language.permissionWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); T2Csend.console("[" + debug + "]" + Language.permissionWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
if (Config.notifyJoinWarning.valueBoolean && join) { if ((boolean) Config.VALUES.notifyJoinWarning.getValue() && join) {
if (Config.notifyBungee.valueBoolean) { if ((boolean) Config.VALUES.notifyBungee.getValue()) {
BungeeSenderReceiver.sendToBungee(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); BungeeSenderReceiver.sendToBungee(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} else } else
Events.notifyPlayer(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); Events.notifyPlayer(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} }
if (PermissionWhitelist.playerWithPermissionKick.valueBoolean) { if ((boolean)PermissionWhitelist.VALUES.playerWithPermissionKick.getValue()) {
if (Config.kickCustomCommand.valueBoolean) { if ((boolean) Config.VALUES.kickCustomCommand.getValue()) {
T2Ccmd.console(Config.kickCommand.valueString.replace("[perm]", perm).replace("[player]", player.getName()).replace("[reason]", Language.permissionWhitelistKick.value)); T2Ccmd.console(Config.VALUES.kickCommand.getValue().toString().replace("[perm]", perm).replace("[player]", player.getName()).replace("[reason]", Language.permissionWhitelistKick.value));
} else player.kickPlayer(Language.permissionWhitelistKick.value); } else player.kickPlayer(Language.permissionWhitelistKick.value);
T2Csend.console("[" + debug + "]" + Language.permissionWhitelistNotifyKick.value.replace("[player]", T2Csend.console("[" + debug + "]" + Language.permissionWhitelistNotifyKick.value.replace("[player]",
player.getName()).replace("[perm]", perm).replace("[uuid]", String.valueOf(player.getUniqueId()))); player.getName()).replace("[perm]", perm).replace("[uuid]", String.valueOf(player.getUniqueId())));
} }
if (PermissionWhitelist.customCommandsEnable.valueBoolean) { if ((boolean)PermissionWhitelist.VALUES.customCommandsEnable.getValue()) {
for (String cmd : PermissionWhitelist.customCommandsCommands.valueStringList) { for (String cmd : (StringList)PermissionWhitelist.VALUES.customCommandsCommands.getValue()) {
T2Ccmd.console(cmd.replace("[player]", player.getName()).replace("[perm]", perm)); T2Ccmd.console(cmd.replace("[player]", player.getName()).replace("[perm]", perm));
} }
} }

View File

@ -13,8 +13,8 @@ import org.bukkit.entity.Player;
public class Timer { public class Timer {
public static void refreshTimer() { public static void refreshTimer() {
if (!(OPWhitelist.enable.valueBoolean && PermissionWhitelist.enable.valueBoolean)) return; if (!((boolean)OPWhitelist.VALUES.enable.getValue() && (boolean)PermissionWhitelist.VALUES.enable.getValue())) return;
if (!Config.checkTimerEnable.valueBoolean) return; if (!(boolean) Config.VALUES.checkTimerEnable.getValue()) return;
Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getPlugin(), new Runnable() {
@Override @Override
@ -25,6 +25,6 @@ public class Timer {
PermissionCheck.onCheck(player, false, debug); PermissionCheck.onCheck(player, false, debug);
} }
} }
}, 0, 20L * Config.checkTimerRefreshInSec.valueInt); }, 0, 20L * (int) Config.VALUES.checkTimerRefreshInSec.getValue());
} }
} }

View File

@ -22,7 +22,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
if (args.length == 0) { if (args.length == 0) {
Commands.mainCommand(sender); Commands.mainCommand(sender);
} else { } else {
if (Config.onlyOPcanUseThePlugin.valueBoolean) { if ((boolean)Config.VALUES.onlyOPcanUseThePlugin.getValue()) {
if (!sender.isOp()) { if (!sender.isOp()) {
sender.sendMessage(Util.getPrefix() + "§cOnly OPs can use OPSecurity!"); sender.sendMessage(Util.getPrefix() + "§cOnly OPs can use OPSecurity!");
return false; return false;

View File

@ -5,6 +5,8 @@ import net.t2code.opsecurity.check.OpCheck;
import net.t2code.opsecurity.config.FileSelect; import net.t2code.opsecurity.config.FileSelect;
import net.t2code.opsecurity.config.config.Config; import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.language.Language; import net.t2code.opsecurity.config.language.Language;
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist;
import net.t2code.opsecurity.system.Main; import net.t2code.opsecurity.system.Main;
import net.t2code.opsecurity.system.Permissions; import net.t2code.opsecurity.system.Permissions;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug; import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
@ -33,7 +35,7 @@ public class Commands {
} }
public static void mainCommand(CommandSender sender) { public static void mainCommand(CommandSender sender) {
if (Config.onlyOPcanUseThePlugin.valueBoolean) { if ((boolean) Config.VALUES.onlyOPcanUseThePlugin.getValue()) {
if (!sender.isOp()) { if (!sender.isOp()) {
sender.sendMessage(Util.getPrefix() + "§cOnly OPs can use OPSecurity!"); sender.sendMessage(Util.getPrefix() + "§cOnly OPs can use OPSecurity!");
return; return;
@ -53,7 +55,7 @@ public class Commands {
} }
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; Player player = (Player) sender;
if (Config.onlyOPcanUseThePlugin.valueBoolean) { if ((boolean) Config.VALUES.onlyOPcanUseThePlugin.getValue()) {
String debug = T2Cdebug.debugCode(); String debug = T2Cdebug.debugCode();
if (!OpCheck.opWhitelist(player, debug)) { if (!OpCheck.opWhitelist(player, debug)) {
sender.sendMessage(Util.getPrefix() + " §4You are not on the Whitelist!"); // todo sender.sendMessage(Util.getPrefix() + " §4You are not on the Whitelist!"); // todo
@ -67,10 +69,10 @@ public class Commands {
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §6Plugin reload..."); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §6Plugin reload...");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------");
// Load.onLoad(Main.getPlugin(),Main.getAutor(),Main.getVersion()); // Load.onLoad(Main.getPlugin(),Main.getAutor(),Main.getVersion());
FileSelect.selectConfig(); Config.set();
FileSelect.selectLanguage(); FileSelect.selectLanguage();
FileSelect.selectOpWhitelist(); OPWhitelist.set();
FileSelect.selectPermissionWhitelist(); PermissionWhitelist.set();
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §2Plugin successfully reloaded."); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §2Plugin successfully reloaded.");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------");

View File

@ -2,20 +2,12 @@ package net.t2code.opsecurity.config;
import net.t2code.opsecurity.Util; import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.config.config.Config; import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.config.Converter;
import net.t2code.opsecurity.config.language.Language; import net.t2code.opsecurity.config.language.Language;
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist;
import net.t2code.opsecurity.objects.PlayerCache;
import net.t2code.opsecurity.objects.PlayerObject;
import net.t2code.opsecurity.system.Main; import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug; import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace; import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2Cconfig; import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
@ -23,69 +15,6 @@ import java.io.IOException;
import java.util.*; import java.util.*;
public class FileSelect { public class FileSelect {
public static void selectConfig() {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
if (!config.exists()) T2Cconfig.set("configVersion", Util.getConfigVersion(), yamlConfiguration);
if (yamlConfiguration.getInt("configVersion") < Util.getConfigVersion() && new File(Main.getPath(), "config.yml").exists()) {
if (yamlConfiguration.getInt("configVersion") < 2) {
Converter.convertCheck();
T2Csend.console(Util.getPrefix() + " §4----------------------");
T2Csend.console(Util.getPrefix() + " ");
T2Csend.console(Util.getPrefix() + " §6New features have been added to T2C-OPSecurity. The Config is adapted!");
T2Csend.console(Util.getPrefix() + " ");
T2Csend.console(Util.getPrefix() + " §4----------------------");
}
config = new File(Main.getPath(), "config.yml");
yamlConfiguration = YamlConfiguration.loadConfiguration(config);
}
for (Config value : Config.values()) {
switch (value.configParam) {
case STRING:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueString);
}
value.valueString = T2Creplace.replace(Util.getPrefix(), Objects.requireNonNull(yamlConfiguration.getString(value.path)));
break;
case STRINGLIST:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueStringList);
}
value.valueStringList = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getStringList(value.path));
break;
case SOUND:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.sound.toString());
}
try {
value.sound = Sound.valueOf(yamlConfiguration.getString(value.path));
} catch (Exception ex) {
T2Csend.console("§4\n§4\n§4\n" + SelectLibMsg.soundNotFound.replace("[prefix]", Util.getPrefix())
.replace("[sound]", "§8" + value.path + ": §6" + yamlConfiguration.getString(value.path)) + "§4\n§4\n§4\n");
}
break;
case BOOLEAN:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueBoolean);
}
value.valueBoolean = yamlConfiguration.getBoolean(value.path);
break;
case INTEGER:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueInt);
}
value.valueInt = yamlConfiguration.getInt(value.path);
break;
}
}
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
private static ArrayList<String> defaultLanguages = new ArrayList<>(Arrays.asList("german", "english")); private static ArrayList<String> defaultLanguages = new ArrayList<>(Arrays.asList("german", "english"));
@ -116,119 +45,24 @@ public class FileSelect {
} }
String selectMSG; String selectMSG;
File config = new File(Main.getPath(), "languages/" + Config.language.valueString + ".yml"); File config = new File(Main.getPath(), "languages/" + Config.VALUES.language.getValue() + ".yml");
T2Cdebug.debug(Main.getPlugin(), config.getAbsolutePath()); T2Cdebug.debug(Main.getPlugin(), config.getAbsolutePath());
if (!config.isFile()) { if (!config.isFile()) {
T2Csend.console(Util.getPrefix()); T2Csend.console(Util.getPrefix());
T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
T2Csend.console(Util.getPrefix() + " §4The selected §c" + Config.language.valueString + " §4language file was not found."); T2Csend.console(Util.getPrefix() + " §4The selected §c" + Config.VALUES.language.getValue() + " §4language file was not found.");
T2Csend.console(Util.getPrefix() + " §6The default language §eEnglish §6is used!"); T2Csend.console(Util.getPrefix() + " §6The default language §eEnglish §6is used!");
T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
T2Csend.console(Util.getPrefix()); T2Csend.console(Util.getPrefix());
config = new File(Main.getPath(), "languages/" + "english.yml"); config = new File(Main.getPath(), "languages/" + "english.yml");
selectMSG = "english"; selectMSG = "english";
} else selectMSG = Config.language.valueString; } else selectMSG = Config.VALUES.language.getValue().toString();
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (Language value : Language.values()) { for (Language value : Language.values()) {
T2Cdebug.debug(Main.getPlugin(), "Select: File: " + config.getName() + " Path: " + value.path); T2Cdebug.debug(Main.getPlugin(), "Select: File: " + config.getName() + " Path: " + value.path);
value.value = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getString(value.path)); value.value = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getString(value.path));
} }
T2Csend.console(Util.getPrefix() + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_) + "ms"); T2Ctemplate.onStartMsg(Util.getPrefix(),"§2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
}
public static void selectOpWhitelist() {
PlayerCache.getOpHashMap().clear();
File config = new File(Main.getPath(), "opWhitelist.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (OPWhitelist value : OPWhitelist.values()) {
switch (value.cEnum) {
case BOOLEAN:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueBoolean);
}
value.valueBoolean = yamlConfiguration.getBoolean(value.path);
break;
case STRINGLIST:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueStringList);
}
value.valueStringList = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getStringList(value.path));
break;
case PLAYERLIST:
if (!yamlConfiguration.contains(value.pathPlayerListPath)) {
yamlConfiguration.set(value.pathPlayerName.replace("KEY", "player1"), value.valuePlayerName);
yamlConfiguration.set(value.pathPlayerUuid.replace("KEY", "player1"), value.valuePlayerUuid);
yamlConfiguration.set(value.pathPlayerName.replace("KEY", "player2"), value.valuePlayerName);
yamlConfiguration.set(value.pathPlayerUuid.replace("KEY", "player2"), value.valuePlayerUuid);
}
for (String key : yamlConfiguration.getConfigurationSection(value.pathPlayerListPath).getKeys(false)) {
String name = yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key));
PlayerObject playerObject = new PlayerObject(
name,
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key)).replace("-", ""));
PlayerCache.getOpHashMap().put(name, playerObject);
}
break;
case GAMEMODE:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueGameMode.toString());
}
try {
value.valueGameMode = GameMode.valueOf(yamlConfiguration.getString(value.path).toUpperCase());
} catch (Exception ex) {
ex.printStackTrace();
value.valueGameMode = GameMode.SURVIVAL;
}
break;
}
}
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void selectPermissionWhitelist() {
PlayerCache.getPermissionHashMap().clear();
File config = new File(Main.getPath(), "permissionWhitelist.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (PermissionWhitelist value : PermissionWhitelist.values()) {
switch (value.cEnum) {
case BOOLEAN:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueBoolean);
}
value.valueBoolean = yamlConfiguration.getBoolean(value.path);
break;
case STRINGLIST:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueStringList);
}
value.valueStringList = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getStringList(value.path));
break;
case PLAYERLIST:
if (!yamlConfiguration.contains(value.pathPlayerListPath)) {
yamlConfiguration.set(value.pathPlayerName.replace("KEY", "player1"), value.valuePlayerName);
yamlConfiguration.set(value.pathPlayerUuid.replace("KEY", "player1"), value.valuePlayerUuid);
yamlConfiguration.set(value.pathPlayerName.replace("KEY", "player2"), value.valuePlayerName);
yamlConfiguration.set(value.pathPlayerUuid.replace("KEY", "player2"), value.valuePlayerUuid);
}
for (String key : yamlConfiguration.getConfigurationSection(value.pathPlayerListPath).getKeys(false)) {
String name = yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key));
PlayerObject playerObject = new PlayerObject(
name,
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key)).replace("-", ""));
PlayerCache.getPermissionHashMap().put(name, playerObject);
}
break;
}
}
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
} }
} }

View File

@ -1,73 +1,95 @@
// This class was created by JaTiTV.
package net.t2code.opsecurity.config.config; package net.t2code.opsecurity.config.config;
import net.t2code.opsecurity.enums.ConfigParam; import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigWriter;
import net.t2code.t2codelib.T2CconfigItem;
import net.t2code.opsecurity.Util;
import org.bukkit.Sound; import org.bukkit.Sound;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public enum Config { public class Config {
language("plugin.language", "english", ConfigParam.STRING), public enum VALUES implements T2CconfigItem {
onlyOPcanUseThePlugin("plugin.onlyOPcanUseThePlugin", true, ConfigParam.BOOLEAN),
updateCheckOnJoin("plugin.updateCheck.onJoin",true,ConfigParam.BOOLEAN), language("plugin.language", "english", true,"Here you can set the language of the plugin."),
updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates",true,ConfigParam.BOOLEAN), onlyOPcanUseThePlugin("plugin.onlyOPcanUseThePlugin", true, true, "Here you can specify that only players with OP can use the commands of the plugin."),
updateCheckTimeInterval("plugin.updateCheck.timeInterval",60,ConfigParam.INTEGER),
checkOnJoin("check.onJoin.enable", true, ConfigParam.BOOLEAN), updateCheckOnJoin("plugin.updateCheck.onJoin",true,true, "In this option you can set if players with the permission 't2c.opsecurity.updatemsg' will get an update message on join when an update for the plugin is available."),
checkOnInteract("check.onInteract.enable", true, ConfigParam.BOOLEAN), updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates",true,true,"In this option you can set whether you want to receive and display beta and snapshot versions in the update check."),
checkOnCommand("check.onCommand.enable", true, ConfigParam.BOOLEAN), updateCheckTimeInterval("plugin.updateCheck.timeInterval",60,true,"In this option you can set the time interval in minutes in which updates should be checked."),
checkOnCommandWhitelist("check.onCommand.whitelist", Arrays.asList("command 1","command 2"), ConfigParam.STRINGLIST),
checkOnChat("check.onChat.enable", true, ConfigParam.BOOLEAN),
checkTimerEnable("check.timer.enable", true, ConfigParam.BOOLEAN),
checkTimerRefreshInSec("check.timer.refreshInSec", 60, ConfigParam.INTEGER),
kickCustomCommand("kick.customCommand.enable", false, ConfigParam.BOOLEAN),
kickCommand("kick.customCommand.command", "minecraft:kick [player] [reason]", ConfigParam.STRING),
notifyJoinWarning("notify.joinWarn.enable", true, ConfigParam.BOOLEAN),
notifyBungee("notify.allBungeePlayer.enable", false, ConfigParam.BOOLEAN),
notifySoundEnable("notify.soundEnable", true, ConfigParam.BOOLEAN),
notifySoundValue("notify.sound", sound(), ConfigParam.SOUND);
public String path; checkOnJoin("check.onJoin.enable", true, true, "Activate the checks whether the player is authorised when joining the player."),
public String valueString; checkOnInteract("check.onInteract.enable", true, true,"Activate the checks whether the player is authorised for player interactions."),
public List<String> valueStringList; checkOnCommand("check.onCommand.enable", true, true,"Activate the checks whether the player is authorised when the player executes a command."),
public Integer valueInt; checkOnCommandWhitelist("check.onCommand.whitelist", Arrays.asList("command 1","command 2"), true, "Here you can specify commands for which the check is not carried out."),
public Boolean valueBoolean; checkOnChat("check.onChat.enable", true, true,"Activate the checks whether the player is authorised when the player writes a chat message." ),
public Sound sound; checkTimerEnable("check.timer.enable", true, true, "Activate the check of all players in a time interval."),
public ConfigParam configParam; checkTimerRefreshInSec("check.timer.refreshInSec", 60, true,"Here you set the seconds with which the check is carried out in a time interval."),
kickCustomCommand("kick.customCommand.enable", false,true, "Should a separate kick command be used for the kick? For example, if you use your own ban system."),
kickCommand("kick.customCommand.command", "minecraft:kick [player] [reason]", true, "This is where you set the user-defined kick command."),
notifyJoinWarning("notify.warn.enable", true, true, "Should players with the permission 't2c.opsecurity.notify' be warned if a player is detected who is not authorised to be on the server with OP / a permission."),
notifyBungee("notify.allBungeePlayer.enable", false, true, "Should the warnings be sent on the entire network (true) or only on the individual server (false)."),
notifySoundEnable("notify.soundEnable", true, true, "Should a sound be played during the warnings?"),
notifySoundValue("notify.sound", sound(), true, "Which sound should be played during the warnings?"),
;
Config(String path, String value, ConfigParam cEnum) { private final String path;
private Object value;
private final boolean forceSet;
private final List<String> comments;
VALUES(String path, Object value,boolean forceSet, String... comments) {
this.path = path; this.path = path;
this.valueString = value; this.value = value;
this.configParam = cEnum; this.forceSet = forceSet;
this.comments = new ArrayList<>(Arrays.asList(comments));
} }
Config(String path, Sound value, ConfigParam cEnum) { @Override
this.path = path; public String getPath() {
this.sound = value; return path;
this.configParam = cEnum;
} }
Config(String path, Integer value, ConfigParam cEnum) { @Override
this.path = path; public Object getValue() {
this.valueInt = value; return value;
this.configParam = cEnum;
} }
Config(String path, Boolean value, ConfigParam cEnum) { @Override
this.path = path; public boolean getForceSet() {
this.valueBoolean = value; return forceSet;
this.configParam = cEnum;
}
Config(String path, List<String> value, ConfigParam cEnum) {
this.path = path;
this.valueStringList = value;
this.configParam = cEnum;
} }
public static Sound sound() { @Override
public List<String> getComments() {
return comments;
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
}
public static void set() {
long long_ = System.currentTimeMillis();
T2CconfigWriter.createConfig(new File(Main.getPath(), "config.yml"), VALUES.values(), Util.getConfigLogo());
T2Ctemplate.onStartMsg(Util.getPrefix(), "§2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
}
private static Sound sound() {
if (T2CmcVersion.isMc1_8()) { if (T2CmcVersion.isMc1_8()) {
return Sound.valueOf("NOTE_PIANO"); return Sound.valueOf("NOTE_PIANO");
} else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) { } else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {

View File

@ -1,10 +1,13 @@
package net.t2code.opsecurity.config.config; package net.t2code.opsecurity.config.config;
import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist; import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist; import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist;
import net.t2code.opsecurity.objects.PlayerObject; import net.t2code.opsecurity.objects.PlayerObject;
import net.t2code.opsecurity.system.Main; import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigWriter;
import net.t2code.t2codelib.T2CconfigItem;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
@ -13,8 +16,14 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Converter { public class Converter {
private static YamlConfiguration yamlConfigurationOld;
private static YamlConfiguration opYml;
private static YamlConfiguration permYml;
public static void convert() { public static void convert() {
Path pathOld = Paths.get("plugins/OPSecurity/config.yml"); Path pathOld = Paths.get("plugins/OPSecurity/config.yml");
Path pathNew = Paths.get(Main.getPath() + "/config.yml"); Path pathNew = Paths.get(Main.getPath() + "/config.yml");
@ -24,52 +33,61 @@ public class Converter {
if (Files.exists(pathOld) && !Files.isDirectory(pathOld)) { if (Files.exists(pathOld) && !Files.isDirectory(pathOld)) {
File configOld = new File("plugins/OPSecurity/config.yml"); File configOld = new File("plugins/OPSecurity/config.yml");
YamlConfiguration yamlConfigurationOld = YamlConfiguration.loadConfiguration(configOld); yamlConfigurationOld = YamlConfiguration.loadConfiguration(configOld);
File opConfig = new File(Main.getPath(), "opWhitelist.yml"); File opConfig = new File(Main.getPath(), "opWhitelist.yml");
YamlConfiguration opYml = YamlConfiguration.loadConfiguration(opConfig); opYml = YamlConfiguration.loadConfiguration(opConfig);
File permConfig = new File(Main.getPath(), "permissionWhitelist.yml"); File permConfig = new File(Main.getPath(), "permissionWhitelist.yml");
YamlConfiguration permYml = YamlConfiguration.loadConfiguration(permConfig); permYml = YamlConfiguration.loadConfiguration(permConfig);
Config.language.valueString = yamlConfigurationOld.getString("Plugin.language");
Config.onlyOPcanUseThePlugin.valueBoolean = yamlConfigurationOld.getBoolean("Plugin.OnlyOPcanUseThePlugin");
Config.checkOnJoin.valueBoolean = yamlConfigurationOld.getBoolean("Check.OnJoin");
Config.checkOnInteract.valueBoolean = yamlConfigurationOld.getBoolean("Check.OnInteract");
Config.checkOnCommand.valueBoolean = yamlConfigurationOld.getBoolean("Check.OnCommand");
Config.checkOnChat.valueBoolean = yamlConfigurationOld.getBoolean("Check.OnChat");
Config.checkTimerEnable.valueBoolean = yamlConfigurationOld.getBoolean("Check.Timer.Enable");
Config.checkTimerRefreshInSec.valueInt = yamlConfigurationOld.getInt("Check.Timer.RefreshTime_inSec");
Config.kickCommand.valueString = yamlConfigurationOld.getString("Kick.Command"); setConfig("Plugin.language", Config.VALUES.language);
Config.notifyJoinWarning.valueBoolean = yamlConfigurationOld.getBoolean("Notify.JoinWarn.Enable"); setConfig("Plugin.OnlyOPcanUseThePlugin", Config.VALUES.onlyOPcanUseThePlugin);
Config.notifySoundEnable.valueBoolean = yamlConfigurationOld.getBoolean("Notify.Sound.Enable"); setConfig("Check.OnJoin", Config.VALUES.checkOnJoin);
Config.notifySoundValue.valueString = yamlConfigurationOld.getString("Notify.Sound.Sound"); setConfig("Check.OnInteract", Config.VALUES.checkOnInteract);
setConfig("Check.OnCommand", Config.VALUES.checkOnCommand);
setConfig("Check.OnChat", Config.VALUES.checkOnChat);
setConfig("Check.Timer.Enable", Config.VALUES.checkTimerEnable);
setConfig("Check.Timer.RefreshTime_inSec", Config.VALUES.checkTimerRefreshInSec);
setConfig("Kick.Command", Config.VALUES.kickCommand);
setConfig("Notify.JoinWarn.Enable", Config.VALUES.notifyJoinWarning);
setConfig("Notify.Sound.Enable", Config.VALUES.notifySoundEnable);
setConfig("Notify.Sound.Sound", Config.VALUES.notifySoundValue);
OPWhitelist.enable.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.Enable"); setOPWhitelist("OP_Whitelist.Enable", OPWhitelist.VALUES.enable);
OPWhitelist.playerMustBeOnlineToOp.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.PlayerMustBeOnlineToOp"); setOPWhitelist("OP_Whitelist.PlayerMustBeOnlineToOp", OPWhitelist.VALUES.playerMustBeOnlineToOp);
setOPWhitelist("OP_Whitelist.noOpPlayerDeop.Enable", OPWhitelist.VALUES.noOpPlayerDeopEnable);
setOPWhitelist("OP_Whitelist.noOpPlayerDeop.PlayerSendMessage", OPWhitelist.VALUES.noOpPlayerDeopPlayerSendMessage);
setOPWhitelist("OP_Whitelist.noOpPlayerKick.Enable", OPWhitelist.VALUES.noOpPlayerKickEnable);
setOPWhitelist("OP_Whitelist.customCommands.Enable", OPWhitelist.VALUES.customCommandsEnable);
setOPWhitelist("OP_Whitelist.customCommands.Commands", OPWhitelist.VALUES.customCommandsCommands);
OPWhitelist.noOpPlayerDeopEnable.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.noOpPlayerDeop.Enable");
OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.noOpPlayerDeop.PlayerSendMessage");
OPWhitelist.noOpPlayerKickEnable.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.noOpPlayerKick.Enable");
OPWhitelist.customCommandsEnable.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.customCommands.Enable");
OPWhitelist.customCommandsCommands.valueStringList = yamlConfigurationOld.getStringList("OP_Whitelist.customCommands.Commands");
if (yamlConfigurationOld.contains("OP_Whitelist.Whitelist")){
ArrayList<PlayerObject> opWhitelist = new ArrayList<>(); ArrayList<PlayerObject> opWhitelist = new ArrayList<>();
for (String key : yamlConfigurationOld.getConfigurationSection("OP_Whitelist.Whitelist").getKeys(false)) { for (String key : yamlConfigurationOld.getConfigurationSection("OP_Whitelist.Whitelist").getKeys(false)) {
PlayerObject player = new PlayerObject(key, PlayerObject player = new PlayerObject(key,
yamlConfigurationOld.getString("OP_Whitelist.Whitelist." + key + ".UUID").replace("-", "")); yamlConfigurationOld.getString("OP_Whitelist.Whitelist." + key + ".UUID").replace("-", ""));
opWhitelist.add(player); opWhitelist.add(player);
} }
for (PlayerObject playerObject : opWhitelist) { for (PlayerObject playerObject : opWhitelist) {
opYml.set("opWhitelist.whitelist.KEY.name".replace("KEY", playerObject.playerName), playerObject.playerName); PLAYERENUM.name.path = "opWhitelist.whitelist.KEY.name".replace("KEY", playerObject.playerName);
opYml.set("opWhitelist.whitelist.KEY.uuid".replace("KEY", playerObject.playerName), playerObject.uuid); PLAYERENUM.name.value = playerObject.playerName;
PLAYERENUM.uuid.path = "opWhitelist.whitelist.KEY.uuid".replace("KEY", playerObject.playerName);
PLAYERENUM.uuid.value=playerObject.uuid;
T2CconfigWriter.createConfig(new File(Main.getPath(), "opWhitelist.yml"), PLAYERENUM.values(), Util.getConfigLogo());
}
} }
PermissionWhitelist.enable.valueBoolean = yamlConfigurationOld.getBoolean("Permission_Whitelist.Enable");
PermissionWhitelist.permissions.valueStringList = yamlConfigurationOld.getStringList("Permission_Whitelist.Permissions");
PermissionWhitelist.playerWithPermissionKick.valueBoolean = yamlConfigurationOld.getBoolean("Permission_Whitelist.PlayerWhithPermission_kick"); setPermissionWhitelist("Permission_Whitelist.Enable", PermissionWhitelist.VALUES.enable);
PermissionWhitelist.customCommandsEnable.valueBoolean = yamlConfigurationOld.getBoolean("Permission_Whitelist.customCommands.Enable"); setPermissionWhitelist("Permission_Whitelist.Permissions", PermissionWhitelist.VALUES.permissions);
PermissionWhitelist.customCommandsCommands.valueStringList = yamlConfigurationOld.getStringList("Permission_Whitelist.customCommands.Commands"); setPermissionWhitelist("Permission_Whitelist.PlayerWhithPermission_kick", PermissionWhitelist.VALUES.playerWithPermissionKick);
setPermissionWhitelist("Permission_Whitelist.customCommands.Enable", PermissionWhitelist.VALUES.customCommandsEnable);
setPermissionWhitelist("Permission_Whitelist.customCommands.Commands", PermissionWhitelist.VALUES.customCommandsCommands);
ArrayList<PlayerObject> permWhitelist = new ArrayList<>(); ArrayList<PlayerObject> permWhitelist = new ArrayList<>();
for (String key : yamlConfigurationOld.getConfigurationSection("Permission_Whitelist.Whitelist").getKeys(false)) { for (String key : yamlConfigurationOld.getConfigurationSection("Permission_Whitelist.Whitelist").getKeys(false)) {
@ -102,22 +120,22 @@ public class Converter {
if (!yamlConfiguration.contains("check.onJoin.enable")) { if (!yamlConfiguration.contains("check.onJoin.enable")) {
Boolean onJoin = yamlConfiguration.getBoolean("check.onJoin"); Boolean onJoin = yamlConfiguration.getBoolean("check.onJoin");
T2Csend.debugmsg(Main.getPlugin(),"onJoin = " + onJoin); T2Csend.debugmsg(Main.getPlugin(), "onJoin = " + onJoin);
yamlConfiguration.set("check.onJoin.enable", onJoin); yamlConfiguration.set("check.onJoin.enable", onJoin);
} }
if (!yamlConfiguration.contains("check.onInteract.enable")) { if (!yamlConfiguration.contains("check.onInteract.enable")) {
Boolean onInteract = yamlConfiguration.getBoolean("check.onInteract"); Boolean onInteract = yamlConfiguration.getBoolean("check.onInteract");
T2Csend.debugmsg(Main.getPlugin(),"onInteract = " + onInteract); T2Csend.debugmsg(Main.getPlugin(), "onInteract = " + onInteract);
yamlConfiguration.set("check.onInteract.enable", onInteract); yamlConfiguration.set("check.onInteract.enable", onInteract);
} }
if (!yamlConfiguration.contains("check.onCommand.enable")) { if (!yamlConfiguration.contains("check.onCommand.enable")) {
Boolean onCommand = yamlConfiguration.getBoolean("check.onCommand"); Boolean onCommand = yamlConfiguration.getBoolean("check.onCommand");
T2Csend.debugmsg(Main.getPlugin(),"onCommand = " + onCommand); T2Csend.debugmsg(Main.getPlugin(), "onCommand = " + onCommand);
yamlConfiguration.set("check.onCommand.enable", onCommand); yamlConfiguration.set("check.onCommand.enable", onCommand);
} }
if (!yamlConfiguration.contains("check.onChat.enable")) { if (!yamlConfiguration.contains("check.onChat.enable")) {
Boolean onChat = yamlConfiguration.getBoolean("check.onChat"); Boolean onChat = yamlConfiguration.getBoolean("check.onChat");
T2Csend.debugmsg(Main.getPlugin(),"onChat = " + onChat); T2Csend.debugmsg(Main.getPlugin(), "onChat = " + onChat);
yamlConfiguration.set("check.onChat.enable", onChat); yamlConfiguration.set("check.onChat.enable", onChat);
} }
@ -127,4 +145,69 @@ public class Converter {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private static void setConfig(String path, T2CconfigItem item) {
if (yamlConfigurationOld.contains(path)) {
item.setValue(yamlConfigurationOld.get(path));
}
}
private static void setOPWhitelist(String path, T2CconfigItem item) {
if (yamlConfigurationOld.contains(path)) {
item.setValue(opYml.get(path));
}
}
private static void setPermissionWhitelist(String path, T2CconfigItem item) {
if (yamlConfigurationOld.contains(path)) {
item.setValue(permYml.get(path));
}
}
private enum PLAYERENUM implements T2CconfigItem {
name("", "", true),
uuid("", "", true),
;
protected String path;
protected Object value;
private boolean forceSet;
private final List<String> comments;
PLAYERENUM(String path, Object value,boolean forceSet, String... comments) {
this.path = path;
this.value = value;
this.forceSet = forceSet;
this.comments = new ArrayList<>(Arrays.asList(comments));
}
@Override
public String getPath() {
return path;
}
@Override
public Object getValue() {
return value;
}
@Override
public boolean getForceSet() {
return forceSet;
}
@Override
public List<String> getComments() {
return comments;
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
}
} }

View File

@ -0,0 +1,65 @@
// This class was created by JaTiTV.
package net.t2code.opsecurity.config.language.news;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigWriter;
import net.t2code.t2codelib.T2CconfigItem;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Languages {
public enum VALUES implements T2CconfigItem {
VALUE1("path", VALUE, true, "DESCRIPTION"),
VALUE2("path", VALUE, true, "DESCRIPTION"),
;
private final String path;
private Object value;
private final boolean forceSet;
private final List<String> comments;
VALUES(String path, Object value,boolean forceSet, String... comments) {
this.path = path;
this.value = value;
this.forceSet=forceSet;
this.comments = new ArrayList<>(Arrays.asList(comments));
}
@Override
public String getPath() {
return path;
}
@Override
public Object getValue() {
return value;
}
@Override
public boolean getForceSet() {
return forceSet;
}
@Override
public List<String> getComments() {
return comments;
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
}
public static void set(){
T2CconfigWriter.createConfig(new File(getPlugin().getDataFolder(), "config.yml"), VALUES.values(), FILEHEADER);
}
}
}

View File

@ -1,60 +1,99 @@
// This class was created by JaTiTV.
package net.t2code.opsecurity.config.opWhitelist; package net.t2code.opsecurity.config.opWhitelist;
import net.t2code.opsecurity.enums.ConfigParam; import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.objects.PlayerCache;
import net.t2code.opsecurity.objects.PlayerObject;
import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigWriter;
import net.t2code.t2codelib.T2CconfigItem;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.configuration.ConfigurationSection;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public enum OPWhitelist { public class OPWhitelist {
enable("opWhitelist.enable", false, ConfigParam.BOOLEAN),
playerMustBeOnlineToOp("opWhitelist.playerMustBeOnlineToOp", true, ConfigParam.BOOLEAN),
noOpPlayerDeopEnable("opWhitelist.noOpPlayerDeop.enable", true, ConfigParam.BOOLEAN),
noOpPlayerDeopPlayerSendMessage("opWhitelist.noOpPlayerDeop.playerSendMessage", true, ConfigParam.BOOLEAN),
noOpPlayerKickEnable("opWhitelist.noOpPlayerKick.enable", true, ConfigParam.BOOLEAN),
noOpPlayerSetGameModeEnable("opWhitelist.noOpPlayerSetGameMode.enable", true, ConfigParam.BOOLEAN),
noOpPlayerSetGameModeValue("opWhitelist.noOpPlayerSetGameMode.gameMode", GameMode.SURVIVAL, ConfigParam.GAMEMODE),
customCommandsEnable("opWhitelist.customCommands.enable", false, ConfigParam.BOOLEAN),
customCommandsCommands("opWhitelist.customCommands.commands", Arrays.asList("kick [player] &4You have op but are not authorized to do so, that's why you were kicked!")
, ConfigParam.STRINGLIST),
player("opWhitelist.whitelist","opWhitelist.whitelist.KEY.name", "opWhitelist.whitelist.KEY.uuid", "PlayerName", "00000000000000000000000000000000", ConfigParam.PLAYERLIST);
public String path; public enum VALUES implements T2CconfigItem {
public String pathPlayerListPath;
public String pathPlayerName;
public String pathPlayerUuid;
public String valuePlayerName;
public String valuePlayerUuid;
public List<String> valueStringList;
public Boolean valueBoolean; enable("opWhitelist.enable", false, true),
public GameMode valueGameMode; playerMustBeOnlineToOp("opWhitelist.playerMustBeOnlineToOp", true, true),
public ConfigParam cEnum; noOpPlayerDeopEnable("opWhitelist.noOpPlayerDeop.enable", true, true),
noOpPlayerDeopPlayerSendMessage("opWhitelist.noOpPlayerDeop.playerSendMessage", true, true),
noOpPlayerKickEnable("opWhitelist.noOpPlayerKick.enable", true, true),
noOpPlayerSetGameModeEnable("opWhitelist.noOpPlayerSetGameMode.enable", true, true),
noOpPlayerSetGameModeValue("opWhitelist.noOpPlayerSetGameMode.gameMode", GameMode.SURVIVAL, true),
customCommandsEnable("opWhitelist.customCommands.enable", false, true),
customCommandsCommands("opWhitelist.customCommands.commands", Arrays.asList("kick [player] &4You have op but are not authorized to do so, that's why you were kicked!"), true),
OPWhitelist(String path, GameMode value, ConfigParam cEnum) { playerSection("opWhitelist.whitelist", null, true),
player1name("opWhitelist.whitelist.player1.name", "player1", false),
player1uuid("opWhitelist.whitelist.player1.uuid", "00000000000000000000000000000000", false),
player2name("opWhitelist.whitelist.player2.name", "player2", false),
player2uuid("opWhitelist.whitelist.player2.uuid", "00000000000000000000000000000000", false),
;
private final String path;
private Object value;
private final boolean forceSet;
private final List<String> comments;
VALUES(String path, Object value, boolean forceSet, String... comments) {
this.path = path; this.path = path;
this.valueGameMode = value; this.value = value;
this.cEnum = cEnum; this.forceSet = forceSet;
this.comments = new ArrayList<>(Arrays.asList(comments));
} }
OPWhitelist(String listPath,String pathPlayerName, String pathUuid, String playerName, String uuid, ConfigParam cEnum) { @Override
this.pathPlayerListPath = listPath; public String getPath() {
this.pathPlayerName = pathPlayerName; return path;
this.pathPlayerUuid = pathUuid;
this.valuePlayerName = playerName;
this.valuePlayerUuid = uuid;
this.cEnum = cEnum;
} }
OPWhitelist(String path, List<String> value, ConfigParam cEnum) { @Override
this.path = path; public Object getValue() {
this.valueStringList = value; return value;
this.cEnum = cEnum;
} }
OPWhitelist(String path, Boolean value, ConfigParam cEnum) { @Override
this.path = path; public boolean getForceSet() {
this.valueBoolean = value; return forceSet;
this.cEnum = cEnum; }
@Override
public List<String> getComments() {
return comments;
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
}
public static void set() {
long long_ = System.currentTimeMillis();
T2CconfigWriter.createConfig(new File(Main.getPath(), "opWhitelist.yml"), VALUES.values(), Util.getConfigLogo());
player();
T2Ctemplate.onStartMsg(Util.getPrefix(), "§2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
}
private static void player() {
ConfigurationSection section = (ConfigurationSection) VALUES.playerSection.getValue();
for (String key : section.getConfigurationSection("").getKeys(false)) {
String name = section.getString(key + ".name");
PlayerObject playerObject = new PlayerObject(
name,
section.getString(key + ".uuid").replace("-", ""));
PlayerCache.getOpHashMap().put(name, playerObject);
}
} }
} }

View File

@ -1,47 +1,94 @@
// This class was created by JaTiTV.
package net.t2code.opsecurity.config.permissionWhitelist; package net.t2code.opsecurity.config.permissionWhitelist;
import net.t2code.opsecurity.enums.ConfigParam; import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.objects.PlayerCache;
import net.t2code.opsecurity.objects.PlayerObject;
import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.api.yaml.T2CconfigWriter;
import net.t2code.t2codelib.T2CconfigItem;
import org.bukkit.configuration.ConfigurationSection;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public enum PermissionWhitelist { public class PermissionWhitelist {
enable("permissionWhitelist.enable", false, ConfigParam.BOOLEAN),
playerWithPermissionKick("permissionWhitelist.playerWithPermissionKick", true, ConfigParam.BOOLEAN),
permissions("permissionWhitelist.permissions", Arrays.asList("*", "t2c.opsecurity.admin"), ConfigParam.STRINGLIST),
customCommandsEnable("permissionWhitelist.customCommands.enable", false, ConfigParam.BOOLEAN),
customCommandsCommands("permissionWhitelist.customCommands.commands", Arrays.asList("lp user [player] permission unset *", "lp user [player] permission unset t2c.opsecurity.admin")
, ConfigParam.STRINGLIST),
player("permissionWhitelist.whitelist", "permissionWhitelist.whitelist.KEY.name", "permissionWhitelist.whitelist.KEY.uuid", "PlayerName", "00000000000000000000000000000000", ConfigParam.PLAYERLIST);
public String path; public enum VALUES implements T2CconfigItem {
public String pathPlayerListPath;
public String pathPlayerName;
public String pathPlayerUuid;
public String valuePlayerName;
public String valuePlayerUuid;
public List<String> valueStringList;
public Boolean valueBoolean;
public ConfigParam cEnum;
PermissionWhitelist(String listPath, String pathPlayerName, String pathUuid, String playerName, String uuid, ConfigParam cEnum) { enable("permissionWhitelist.enable", false, true),
this.pathPlayerListPath = listPath; playerWithPermissionKick("permissionWhitelist.playerWithPermissionKick", true, true),
this.pathPlayerName = pathPlayerName; permissions("permissionWhitelist.permissions", Arrays.asList("*", "t2c.opsecurity.admin"), true),
this.pathPlayerUuid = pathUuid; customCommandsEnable("permissionWhitelist.customCommands.enable", false, true),
this.valuePlayerName = playerName; customCommandsCommands("permissionWhitelist.customCommands.commands", Arrays.asList("lp user [player] permission unset *", "lp user [player] permission unset t2c.opsecurity.admin"), true),
this.valuePlayerUuid = uuid;
this.cEnum = cEnum; playerSection("permissionWhitelist.whitelist", null, true),
player1name("permissionWhitelist.whitelist.player1.name", "player1", false),
player1uuid("permissionWhitelist.whitelist.player1.uuid", "00000000000000000000000000000000", false),
player2name("permissionWhitelist.whitelist.player2.name", "player2", false),
player2uuid("permissionWhitelist.whitelist.player2.uuid", "00000000000000000000000000000000", false),
;
private final String path;
private Object value;
private final boolean forceSet;
private final List<String> comments;
VALUES(String path, Object value, boolean forceSet, String... comments) {
this.path = path;
this.value = value;
this.forceSet = forceSet;
this.comments = new ArrayList<>(Arrays.asList(comments));
} }
PermissionWhitelist(String path, List<String> value, ConfigParam cEnum) { @Override
this.path = path; public String getPath() {
this.valueStringList = value; return path;
this.cEnum = cEnum;
} }
PermissionWhitelist(String path, Boolean value, ConfigParam cEnum) { @Override
this.path = path; public Object getValue() {
this.valueBoolean = value; return value;
this.cEnum = cEnum; }
@Override
public boolean getForceSet() {
return forceSet;
}
@Override
public List<String> getComments() {
return comments;
}
@Override
public void setValue(Object newValue) {
value = newValue;
}
}
public static void set() {
long long_ = System.currentTimeMillis();
T2CconfigWriter.createConfig(new File(Main.getPath(), "permissionWhitelist.yml"), VALUES.values(), Util.getConfigLogo());
player();
T2Ctemplate.onStartMsg(Util.getPrefix(), "§2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
}
private static void player() {
ConfigurationSection section = (ConfigurationSection) VALUES.playerSection.getValue();
for (String key : section.getConfigurationSection("").getKeys(false)) {
String name = section.getString(key + ".name");
PlayerObject playerObject = new PlayerObject(
name,
section.getString(key + ".uuid").replace("-", ""));
PlayerCache.getOpHashMap().put(name, playerObject);
}
} }
} }

View File

@ -1,38 +1,42 @@
package net.t2code.opsecurity.events; package net.t2code.opsecurity.events;
import com.sun.org.apache.xerces.internal.xs.StringList;
import net.t2code.opsecurity.Util; import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.check.OpCheck; import net.t2code.opsecurity.check.OpCheck;
import net.t2code.opsecurity.check.PermissionCheck; import net.t2code.opsecurity.check.PermissionCheck;
import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.system.Main; import net.t2code.opsecurity.system.Main;
import net.t2code.opsecurity.system.Permissions; import net.t2code.opsecurity.system.Permissions;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug; import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
import java.util.List;
public class Events implements Listener { public class Events implements Listener {
public static void notifyPlayer(String msg) { public static void notifyPlayer(String msg) {
if (!Config.notifyJoinWarning.valueBoolean) return; if (!(boolean) Config.VALUES.notifyJoinWarning.getValue()) return;
for (Player notifyPlayer : Bukkit.getOnlinePlayers()) { for (Player notifyPlayer : Bukkit.getOnlinePlayers()) {
if (!notifyPlayer.hasPermission(Permissions.notify)) continue; if (!notifyPlayer.hasPermission(Permissions.notify)) continue;
T2Csend.player(notifyPlayer, msg); T2Csend.player(notifyPlayer, msg);
if (Config.notifySoundEnable.valueBoolean) notifyPlayer.playSound(notifyPlayer.getLocation(), Config.notifySoundValue.sound, 3, 1); if ((boolean) Config.VALUES.notifySoundEnable.getValue()) notifyPlayer.playSound(notifyPlayer.getLocation(), Sound.valueOf(Config.VALUES.notifySoundValue.getValue().toString()), 3, 1);
} }
} }
@EventHandler @EventHandler
public void CommandSendEvent(PlayerCommandPreprocessEvent event) { public void CommandSendEvent(PlayerCommandPreprocessEvent event) {
if (!Config.checkOnCommand.valueBoolean) return; if (!(boolean) Config.VALUES.checkOnCommand.getValue()) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
String debug = T2Cdebug.debugCode(); String debug = T2Cdebug.debugCode();
for (String s : Config.checkOnCommandWhitelist.valueStringList){ for (String s : (StringList) Config.VALUES.checkOnCommandWhitelist.getValue()) {
if (event.getMessage().startsWith("/"+s)) { if (event.getMessage().startsWith("/" + s)) {
return; return;
} }
} }
@ -51,7 +55,7 @@ public class Events implements Listener {
@EventHandler @EventHandler
public void PlayerChatEvent(PlayerChatEvent event) { public void PlayerChatEvent(PlayerChatEvent event) {
if (!Config.checkOnChat.valueBoolean) return; if (!(boolean) Config.VALUES.checkOnChat.getValue()) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
String debug = T2Cdebug.debugCode(); String debug = T2Cdebug.debugCode();
if (OpCheck.onCheck(player, false, debug)) { if (OpCheck.onCheck(player, false, debug)) {
@ -67,7 +71,7 @@ public class Events implements Listener {
@EventHandler @EventHandler
public void onInteract(PlayerInteractEvent event) { public void onInteract(PlayerInteractEvent event) {
if (!Config.checkOnInteract.valueBoolean) return; if (!(boolean) Config.VALUES.checkOnInteract.getValue()) return;
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
@ -86,7 +90,7 @@ public class Events implements Listener {
@EventHandler @EventHandler
public void onJoinCheck(PlayerJoinEvent event) { public void onJoinCheck(PlayerJoinEvent event) {
if (!Config.checkOnJoin.valueBoolean) return; if (!(boolean) Config.VALUES.checkOnJoin.getValue()) return;
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -22,7 +22,7 @@ import java.util.Map;
public class OpCommand implements Listener { public class OpCommand implements Listener {
@EventHandler @EventHandler
public void onOPServer(ServerCommandEvent event) { public void onOPServer(ServerCommandEvent event) {
if (!OPWhitelist.enable.valueBoolean) return; if (!(boolean) OPWhitelist.VALUES.enable.getValue()) return;
if ((event.getCommand().toLowerCase().startsWith("op ") || event.getCommand().toLowerCase().startsWith("minecraft:op "))) { if ((event.getCommand().toLowerCase().startsWith("op ") || event.getCommand().toLowerCase().startsWith("minecraft:op "))) {
switch (isNotOPWTL(event.getCommand())) { switch (isNotOPWTL(event.getCommand())) {
case mustOnline: case mustOnline:
@ -39,7 +39,7 @@ public class OpCommand implements Listener {
@EventHandler @EventHandler
public void onOpPlayer(PlayerCommandPreprocessEvent event) { public void onOpPlayer(PlayerCommandPreprocessEvent event) {
if (!OPWhitelist.enable.valueBoolean) return; if (!(boolean) OPWhitelist.VALUES.enable.getValue()) return;
if ((event.getMessage().toLowerCase().startsWith("/op ") || event.getMessage().toLowerCase().startsWith("/minecraft:op "))) { if ((event.getMessage().toLowerCase().startsWith("/op ") || event.getMessage().toLowerCase().startsWith("/minecraft:op "))) {
switch (isNotOPWTL(event.getMessage())) { switch (isNotOPWTL(event.getMessage())) {
case mustOnline: case mustOnline:
@ -59,7 +59,7 @@ public class OpCommand implements Listener {
String arg = command.replace("op ", ""); String arg = command.replace("op ", "");
Player target = Bukkit.getPlayer(arg); Player target = Bukkit.getPlayer(arg);
if (OPWhitelist.playerMustBeOnlineToOp.valueBoolean) { if ((boolean)OPWhitelist.VALUES.playerMustBeOnlineToOp.getValue()) {
if (target == null) return OpCommandRequest.mustOnline; if (target == null) return OpCommandRequest.mustOnline;
if (!opWhitelist(target.getName(), target.getUniqueId().toString())) return OpCommandRequest.notWhitelisted; if (!opWhitelist(target.getName(), target.getUniqueId().toString())) return OpCommandRequest.notWhitelisted;
} }

View File

@ -5,6 +5,8 @@ import net.t2code.opsecurity.command.CmdExecuter;
import net.t2code.opsecurity.config.FileSelect; import net.t2code.opsecurity.config.FileSelect;
import net.t2code.opsecurity.config.config.Config; import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.config.Converter; import net.t2code.opsecurity.config.config.Converter;
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist;
import net.t2code.opsecurity.events.Events; import net.t2code.opsecurity.events.Events;
import net.t2code.opsecurity.events.OpCommand; import net.t2code.opsecurity.events.OpCommand;
import net.t2code.opsecurity.events.PlugManCommand; import net.t2code.opsecurity.events.PlugManCommand;
@ -13,10 +15,10 @@ import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate; import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.api.register.T2Cregister; import net.t2code.t2codelib.SPIGOT.api.register.T2Cregister;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
import net.t2code.t2codelib.SPIGOT.system.config.config.T2CLibConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.checkerframework.checker.units.qual.C;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -34,37 +36,26 @@ public class Load {
ex.printStackTrace(); ex.printStackTrace();
} }
FileSelect.selectConfig(); Config.set();
FileSelect.selectLanguage();
FileSelect.selectOpWhitelist();
FileSelect.selectPermissionWhitelist();
setConfigVersion(); FileSelect.selectLanguage();
OPWhitelist.set();
PermissionWhitelist.set();
plugin.getCommand("t2c-opsecurity").setExecutor(new CmdExecuter()); plugin.getCommand("t2c-opsecurity").setExecutor(new CmdExecuter());
T2Cregister.listener(new OpCommand(), plugin); T2Cregister.listener(new OpCommand(), plugin);
T2Cregister.listener(new PlugManCommand(), plugin); T2Cregister.listener(new PlugManCommand(), plugin);
T2Cregister.listener(new Events(), plugin); T2Cregister.listener(new Events(), plugin);
if (SelectLibConfig.getBungee()) { if ((boolean) T2CLibConfig.VALUES.proxy.getValue()) {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:opsec"); Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:opsec");
T2Csend.debug(plugin, "registerIncomingPluginChannel §et2c:opsec"); T2Csend.debug(plugin, "registerIncomingPluginChannel §et2c:opsec");
} }
Timer.refreshTimer(); Timer.refreshTimer();
Permissions.register(); Permissions.register();
T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(),Util.getGit(),Util.getSpigotID(),Util.getDiscord(), Config.updateCheckOnJoin.valueBoolean, T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(), Util.getGit(), Util.getSpigotID(), Util.getDiscord(), (boolean) Config.VALUES.updateCheckOnJoin.getValue(),
Config.updateCheckSeePreReleaseUpdates.valueBoolean, Config.updateCheckTimeInterval.valueInt); (boolean) Config.VALUES.updateCheckSeePreReleaseUpdates.getValue(), (int) Config.VALUES.updateCheckTimeInterval.getValue());
Metrics.Bstats(plugin, Util.getBstatsID()); Metrics.Bstats(plugin, Util.getBstatsID());
T2Ctemplate.onLoadFooter(Util.getPrefix(), long_); T2Ctemplate.onLoadFooter(Util.getPrefix(), long_);
} }
public static void setConfigVersion() {
File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
yamlConfiguration.set("configVersion", Util.getConfigVersion());
try {
yamlConfiguration.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
} }