diff --git a/OpSecurity V3/pom.xml b/OpSecurity V3/pom.xml index 76bef4f..15be42e 100644 --- a/OpSecurity V3/pom.xml +++ b/OpSecurity V3/pom.xml @@ -6,7 +6,7 @@ net.t2code T2C-OPSecurity - 3.1.3 + 3.2 jar @@ -76,14 +76,14 @@ org.spigotmc spigot-api - 1.19.2-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT provided net.t2code T2CodeLib - 15.0 + 16.4 provided diff --git a/OpSecurity V3/src/main/java/net/t2code/opsecurity/Util.java b/OpSecurity V3/src/main/java/net/t2code/opsecurity/Util.java index f766c32..c68b921 100644 --- a/OpSecurity V3/src/main/java/net/t2code/opsecurity/Util.java +++ b/OpSecurity V3/src/main/java/net/t2code/opsecurity/Util.java @@ -27,5 +27,8 @@ public class Util { @Getter private static String discord = "http://dc.t2code.net"; + @Getter + private static Integer configVersion = 2; + } diff --git a/OpSecurity V3/src/main/java/net/t2code/opsecurity/command/Commands.java b/OpSecurity V3/src/main/java/net/t2code/opsecurity/command/Commands.java index a8426e8..9cd595c 100644 --- a/OpSecurity V3/src/main/java/net/t2code/opsecurity/command/Commands.java +++ b/OpSecurity V3/src/main/java/net/t2code/opsecurity/command/Commands.java @@ -16,7 +16,7 @@ import org.bukkit.entity.Player; public class Commands { - public static void help(CommandSender sender){ + public static void help(CommandSender sender) { if (!sender.hasPermission(Permissions.help)) { T2Csend.sender(sender, Language.noPermissionForOpSec.value); return; @@ -55,7 +55,7 @@ public class Commands { Player player = (Player) sender; if (Config.onlyOPcanUseThePlugin.valueBoolean) { 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 return; } @@ -66,7 +66,7 @@ public class Commands { Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §6Plugin reload..."); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); - // Load.onLoad(Main.getPlugin(),Main.getAutor(),Main.getVersion()); + // Load.onLoad(Main.getPlugin(),Main.getAutor(),Main.getVersion()); FileSelect.selectConfig(); FileSelect.selectLanguage(); FileSelect.selectOpWhitelist(); @@ -81,6 +81,6 @@ public class Commands { sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7<" + Permissions.info + ">"); return; } - T2Ctemplate.sendInfo(sender,Main.getPlugin(),Util.getSpigotID(),Util.getDiscord(),Util.getInfoText()); + T2Ctemplate.sendInfo(sender, Main.getPlugin(), Util.getSpigotID(), Util.getDiscord(), Util.getInfoText()); } } diff --git a/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/FileSelect.java b/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/FileSelect.java index 2e65f67..ca88a48 100644 --- a/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/FileSelect.java +++ b/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/FileSelect.java @@ -2,6 +2,7 @@ package net.t2code.opsecurity.config; import net.t2code.opsecurity.Util; 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.opWhitelist.OPWhitelist; import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist; @@ -11,6 +12,7 @@ import net.t2code.opsecurity.system.Main; import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug; import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; +import net.t2code.t2codelib.SPIGOT.api.yaml.T2Cconfig; import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg; import org.bukkit.GameMode; import org.bukkit.Sound; @@ -24,6 +26,20 @@ 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: @@ -32,6 +48,12 @@ public class FileSelect { } 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()); diff --git a/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/config/Config.java b/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/config/Config.java index 531b139..b19b6b0 100644 --- a/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/config/Config.java +++ b/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/config/Config.java @@ -4,6 +4,9 @@ import net.t2code.opsecurity.enums.ConfigParam; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import org.bukkit.Sound; +import java.util.Arrays; +import java.util.List; + public enum Config { language("plugin.language", "english", ConfigParam.STRING), @@ -13,10 +16,11 @@ public enum Config { updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates",true,ConfigParam.BOOLEAN), updateCheckTimeInterval("plugin.updateCheck.timeInterval",60,ConfigParam.INTEGER), - checkOnJoin("check.onJoin", true, ConfigParam.BOOLEAN), - checkOnInteract("check.onInteract", true, ConfigParam.BOOLEAN), - checkOnCommand("check.onCommand", true, ConfigParam.BOOLEAN), - checkOnChat("check.onChat", true, ConfigParam.BOOLEAN), + checkOnJoin("check.onJoin.enable", true, ConfigParam.BOOLEAN), + checkOnInteract("check.onInteract.enable", true, ConfigParam.BOOLEAN), + checkOnCommand("check.onCommand.enable", true, ConfigParam.BOOLEAN), + 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), @@ -28,6 +32,7 @@ public enum Config { public String path; public String valueString; + public List valueStringList; public Integer valueInt; public Boolean valueBoolean; public Sound sound; @@ -56,6 +61,11 @@ public enum Config { this.valueBoolean = value; this.configParam = cEnum; } + Config(String path, List value, ConfigParam cEnum) { + this.path = path; + this.valueStringList = value; + this.configParam = cEnum; + } public static Sound sound() { if (T2CmcVersion.isMc1_8()) { diff --git a/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/config/Converter.java b/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/config/Converter.java index a70060d..fb68aae 100644 --- a/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/config/Converter.java +++ b/OpSecurity V3/src/main/java/net/t2code/opsecurity/config/config/Converter.java @@ -4,6 +4,7 @@ import net.t2code.opsecurity.config.opWhitelist.OPWhitelist; import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist; import net.t2code.opsecurity.objects.PlayerObject; import net.t2code.opsecurity.system.Main; +import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; @@ -93,4 +94,37 @@ public class Converter { } } } + + public static void convertCheck() { + File config = new File(Main.getPath(), "config.yml"); + YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); + + + if (!yamlConfiguration.contains("check.onJoin.enable")) { + Boolean onJoin = yamlConfiguration.getBoolean("check.onJoin"); + T2Csend.debugmsg(Main.getPlugin(),"onJoin = " + onJoin); + yamlConfiguration.set("check.onJoin.enable", onJoin); + } + if (!yamlConfiguration.contains("check.onInteract.enable")) { + Boolean onInteract = yamlConfiguration.getBoolean("check.onInteract"); + T2Csend.debugmsg(Main.getPlugin(),"onInteract = " + onInteract); + yamlConfiguration.set("check.onInteract.enable", onInteract); + } + if (!yamlConfiguration.contains("check.onCommand.enable")) { + Boolean onCommand = yamlConfiguration.getBoolean("check.onCommand"); + T2Csend.debugmsg(Main.getPlugin(),"onCommand = " + onCommand); + yamlConfiguration.set("check.onCommand.enable", onCommand); + } + if (!yamlConfiguration.contains("check.onChat.enable")) { + Boolean onChat = yamlConfiguration.getBoolean("check.onChat"); + T2Csend.debugmsg(Main.getPlugin(),"onChat = " + onChat); + yamlConfiguration.set("check.onChat.enable", onChat); + } + + try { + yamlConfiguration.save(config); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/OpSecurity V3/src/main/java/net/t2code/opsecurity/events/Events.java b/OpSecurity V3/src/main/java/net/t2code/opsecurity/events/Events.java index eee59b6..7e0b576 100644 --- a/OpSecurity V3/src/main/java/net/t2code/opsecurity/events/Events.java +++ b/OpSecurity V3/src/main/java/net/t2code/opsecurity/events/Events.java @@ -30,6 +30,13 @@ public class Events implements Listener { if (!Config.checkOnCommand.valueBoolean) return; Player player = event.getPlayer(); String debug = T2Cdebug.debugCode(); + + for (String s : Config.checkOnCommandWhitelist.valueStringList){ + if (event.getMessage().startsWith("/"+s)) { + return; + } + } + if (OpCheck.onCheck(player, false, debug)) { if (event.isCancelled()) return; event.setCancelled(true); @@ -41,6 +48,7 @@ public class Events implements Listener { } } + @EventHandler public void PlayerChatEvent(PlayerChatEvent event) { if (!Config.checkOnChat.valueBoolean) return; diff --git a/OpSecurity V3/src/main/java/net/t2code/opsecurity/system/Load.java b/OpSecurity V3/src/main/java/net/t2code/opsecurity/system/Load.java index af10769..1144bf6 100644 --- a/OpSecurity V3/src/main/java/net/t2code/opsecurity/system/Load.java +++ b/OpSecurity V3/src/main/java/net/t2code/opsecurity/system/Load.java @@ -15,8 +15,11 @@ import net.t2code.t2codelib.SPIGOT.api.register.T2Cregister; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; import org.checkerframework.checker.units.qual.C; +import java.io.File; +import java.io.IOException; import java.util.List; import java.util.logging.Level; @@ -36,6 +39,8 @@ public class Load { FileSelect.selectOpWhitelist(); FileSelect.selectPermissionWhitelist(); + setConfigVersion(); + plugin.getCommand("t2c-opsecurity").setExecutor(new CmdExecuter()); T2Cregister.listener(new OpCommand(), plugin); @@ -52,4 +57,14 @@ public class Load { Metrics.Bstats(plugin, Util.getBstatsID()); 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(); + } + } } diff --git a/OpSecurity V3/src/main/resources/plugin.yml b/OpSecurity V3/src/main/resources/plugin.yml index b37b12c..51f853e 100644 --- a/OpSecurity V3/src/main/resources/plugin.yml +++ b/OpSecurity V3/src/main/resources/plugin.yml @@ -7,6 +7,7 @@ load: STARTUP prefix: T2C-OPSecurity authors: [ JaTiTV ] + softdepend: - T2CodeLib