In this update, minor bugs have been fixed and the config has been slightly revised.

Config changes:
- check.onJoin -> check.onJoin.enable
- check.onInteract -> check.onInteract.enable
- check.onCommand -> check.onCommand.enable
- check.onChat -> check.onChat.enable
- add check.onCommand.whitelist

A whitelist has been added for commands for which no check is performed.
This commit is contained in:
JaTiTV 2024-03-31 13:35:45 +02:00
parent 052592cff6
commit c89430b219
9 changed files with 104 additions and 11 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.1.3</version> <version>3.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
@ -76,14 +76,14 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version> <version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- t2code --> <!-- t2code -->
<dependency> <dependency>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId> <artifactId>T2CodeLib</artifactId>
<version>15.0</version> <version>16.4</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

View File

@ -27,5 +27,8 @@ public class Util {
@Getter @Getter
private static String discord = "http://dc.t2code.net"; private static String discord = "http://dc.t2code.net";
@Getter
private static Integer configVersion = 2;
} }

View File

@ -2,6 +2,7 @@ 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.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist; 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.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.system.config.languages.SelectLibMsg; import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -24,6 +26,20 @@ public class FileSelect {
public static void selectConfig() { public static void selectConfig() {
File config = new File(Main.getPath(), "config.yml"); File config = new File(Main.getPath(), "config.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); 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()) { for (Config value : Config.values()) {
switch (value.configParam) { switch (value.configParam) {
case STRING: case STRING:
@ -32,6 +48,12 @@ public class FileSelect {
} }
value.valueString = T2Creplace.replace(Util.getPrefix(), Objects.requireNonNull(yamlConfiguration.getString(value.path))); value.valueString = T2Creplace.replace(Util.getPrefix(), Objects.requireNonNull(yamlConfiguration.getString(value.path)));
break; 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: case SOUND:
if (!yamlConfiguration.contains(value.path)) { if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.sound.toString()); yamlConfiguration.set(value.path, value.sound.toString());

View File

@ -4,6 +4,9 @@ import net.t2code.opsecurity.enums.ConfigParam;
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
import org.bukkit.Sound; import org.bukkit.Sound;
import java.util.Arrays;
import java.util.List;
public enum Config { public enum Config {
language("plugin.language", "english", ConfigParam.STRING), language("plugin.language", "english", ConfigParam.STRING),
@ -13,10 +16,11 @@ public enum Config {
updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates",true,ConfigParam.BOOLEAN), updateCheckSeePreReleaseUpdates("plugin.updateCheck.seePreReleaseUpdates",true,ConfigParam.BOOLEAN),
updateCheckTimeInterval("plugin.updateCheck.timeInterval",60,ConfigParam.INTEGER), updateCheckTimeInterval("plugin.updateCheck.timeInterval",60,ConfigParam.INTEGER),
checkOnJoin("check.onJoin", true, ConfigParam.BOOLEAN), checkOnJoin("check.onJoin.enable", true, ConfigParam.BOOLEAN),
checkOnInteract("check.onInteract", true, ConfigParam.BOOLEAN), checkOnInteract("check.onInteract.enable", true, ConfigParam.BOOLEAN),
checkOnCommand("check.onCommand", true, ConfigParam.BOOLEAN), checkOnCommand("check.onCommand.enable", true, ConfigParam.BOOLEAN),
checkOnChat("check.onChat", 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), checkTimerEnable("check.timer.enable", true, ConfigParam.BOOLEAN),
checkTimerRefreshInSec("check.timer.refreshInSec", 60, ConfigParam.INTEGER), checkTimerRefreshInSec("check.timer.refreshInSec", 60, ConfigParam.INTEGER),
kickCustomCommand("kick.customCommand.enable", false, ConfigParam.BOOLEAN), kickCustomCommand("kick.customCommand.enable", false, ConfigParam.BOOLEAN),
@ -28,6 +32,7 @@ public enum Config {
public String path; public String path;
public String valueString; public String valueString;
public List<String> valueStringList;
public Integer valueInt; public Integer valueInt;
public Boolean valueBoolean; public Boolean valueBoolean;
public Sound sound; public Sound sound;
@ -56,6 +61,11 @@ public enum Config {
this.valueBoolean = value; this.valueBoolean = value;
this.configParam = cEnum; this.configParam = cEnum;
} }
Config(String path, List<String> value, ConfigParam cEnum) {
this.path = path;
this.valueStringList = value;
this.configParam = cEnum;
}
public static Sound sound() { public static Sound sound() {
if (T2CmcVersion.isMc1_8()) { if (T2CmcVersion.isMc1_8()) {

View File

@ -4,6 +4,7 @@ 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 org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; 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);
}
}
} }

View File

@ -30,6 +30,13 @@ public class Events implements Listener {
if (!Config.checkOnCommand.valueBoolean) return; if (!Config.checkOnCommand.valueBoolean) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
String debug = T2Cdebug.debugCode(); String debug = T2Cdebug.debugCode();
for (String s : Config.checkOnCommandWhitelist.valueStringList){
if (event.getMessage().startsWith("/"+s)) {
return;
}
}
if (OpCheck.onCheck(player, false, debug)) { if (OpCheck.onCheck(player, false, debug)) {
if (event.isCancelled()) return; if (event.isCancelled()) return;
event.setCancelled(true); event.setCancelled(true);
@ -41,6 +48,7 @@ public class Events implements Listener {
} }
} }
@EventHandler @EventHandler
public void PlayerChatEvent(PlayerChatEvent event) { public void PlayerChatEvent(PlayerChatEvent event) {
if (!Config.checkOnChat.valueBoolean) return; if (!Config.checkOnChat.valueBoolean) return;

View File

@ -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.api.update.T2CupdateAPI;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig; import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.checkerframework.checker.units.qual.C; import org.checkerframework.checker.units.qual.C;
import java.io.File;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -36,6 +39,8 @@ public class Load {
FileSelect.selectOpWhitelist(); FileSelect.selectOpWhitelist();
FileSelect.selectPermissionWhitelist(); FileSelect.selectPermissionWhitelist();
setConfigVersion();
plugin.getCommand("t2c-opsecurity").setExecutor(new CmdExecuter()); plugin.getCommand("t2c-opsecurity").setExecutor(new CmdExecuter());
T2Cregister.listener(new OpCommand(), plugin); T2Cregister.listener(new OpCommand(), plugin);
@ -52,4 +57,14 @@ public class Load {
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();
}
}
} }

View File

@ -7,6 +7,7 @@ load: STARTUP
prefix: T2C-OPSecurity prefix: T2C-OPSecurity
authors: [ JaTiTV ] authors: [ JaTiTV ]
softdepend: softdepend:
- T2CodeLib - T2CodeLib