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>
<artifactId>T2C-OPSecurity</artifactId>
<version>3.1.3</version>
<version>3.2</version>
<packaging>jar</packaging>
@ -76,14 +76,14 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- t2code -->
<dependency>
<groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId>
<version>15.0</version>
<version>16.4</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

View File

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

View File

@ -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());
}
}

View File

@ -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());

View File

@ -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<String> 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<String> value, ConfigParam cEnum) {
this.path = path;
this.valueStringList = value;
this.configParam = cEnum;
}
public static Sound sound() {
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.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);
}
}
}

View File

@ -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;

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.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();
}
}
}

View File

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