12 Commits
3.0.5 ... 3.3

Author SHA1 Message Date
c89430b219 3.2
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.
2024-03-31 13:35:45 +02:00
052592cff6 3.1.3
The notify.allBungeePlayer option did not work as it should, this bug was fixed
2023-06-19 21:09:03 +02:00
f5dfca5f72 3.1.2
- API update to Minecraft version 1.20
- T2CodeLib API update to 15.0 (this version is required from now on)
2023-06-08 06:58:46 +02:00
0dc694d29f Security bugfixes and improved debug messages 2023-04-23 16:35:32 +02:00
9351c0dfb7 better debug information & async bugfix 2023-04-23 12:53:25 +02:00
98fd0409fd load bugfix
Fixed an error that occurred when loading the plugin, because since paper build 404 the T2CodeLib was loaded only after OPSecurity
2023-02-28 00:15:48 +01:00
a2bd88ac7c 3.1.0 | add API 2022-12-28 08:12:36 +01:00
dba1e57b91 code changes 2022-12-23 00:38:55 +01:00
e14f91c584 Update OPWhitelist.java 2022-12-22 02:14:04 +01:00
1547c16093 3.0.7 | Bugfix
- noOpPlayerDeop.enable' was missing in opWhitelist.yml and was read in incorrectly
- kick.customCommand.Enable' was corrected to 'kick.customCommand.enable' in config.yml
2022-12-12 11:38:45 +01:00
44507458e5 3.0.6 2022-11-20 20:17:55 +01:00
ea54d85ecc 3.0.5
https://git.t2code.net/JaTiTV/T2C-OPSecurity/releases/tag/3.0.5
2022-11-19 03:12:53 +01:00
21 changed files with 319 additions and 79 deletions

View File

@@ -6,7 +6,7 @@
<groupId>net.t2code</groupId>
<artifactId>T2C-OPSecurity</artifactId>
<version>3.0.4</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>13.4</version>
<version>16.4</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

View File

@@ -0,0 +1,60 @@
package net.t2code.opsecurity.API;
import net.t2code.opsecurity.check.OpCheck;
import net.t2code.opsecurity.check.PermissionCheck;
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.t2codelib.SPIGOT.api.debug.T2Cdebug;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class T2COpSecAPI {
public static boolean checkOPWhiteList(Player player) {
if (!OPWhitelist.enable.valueBoolean) return true;
String debug = T2Cdebug.debugCode();
return OpCheck.opWhitelist(player,debug);
}
public static boolean checkPermissionWhiteList(Player player, String debug) {
if (!PermissionWhitelist.enable.valueBoolean) return true;
return PermissionCheck.permWhitelist(player, debug);
}
public static T2COpSecAPIPlayerStatus detailCheckOPWhiteList(Player player) {
if (!OPWhitelist.enable.valueBoolean) return T2COpSecAPIPlayerStatus.playerOnOpWhitelist;
List<String> nameList = new ArrayList<>();
List<String> uuidList = new ArrayList<>();
for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getOpHashMap().entrySet()) {
nameList.add(playerObject.getValue().playerName);
uuidList.add(playerObject.getValue().uuid);
}
if (!nameList.contains(player.getName())) {
return T2COpSecAPIPlayerStatus.playerNameNotOnTheOpWhitelist;
}
if (!uuidList.contains(player.getUniqueId().toString().replace("-", ""))) {
return T2COpSecAPIPlayerStatus.playerUuidNotOnTheOpWhitelist;
}
return T2COpSecAPIPlayerStatus.playerOnOpWhitelist;
}
public static T2COpSecAPIPlayerStatus detailCheckPermissionWhiteList(Player player) {
if (!PermissionWhitelist.enable.valueBoolean) return T2COpSecAPIPlayerStatus.playerOnPermissionWhitelist;
List<String> nameList = new ArrayList<>();
List<String> uuidList = new ArrayList<>();
for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getPermissionHashMap().entrySet()) {
nameList.add(playerObject.getValue().playerName);
uuidList.add(playerObject.getValue().uuid);
}
if (!nameList.contains(player.getName())) {
return T2COpSecAPIPlayerStatus.playerNameNotOnThePermissionWhitelist;
}
if (!uuidList.contains(player.getUniqueId().toString().replace("-", ""))) {
return T2COpSecAPIPlayerStatus.playerUuidNotOnThePermissionWhitelist;
}
return T2COpSecAPIPlayerStatus.playerOnPermissionWhitelist;
}
}

View File

@@ -0,0 +1,10 @@
package net.t2code.opsecurity.API;
public enum T2COpSecAPIPlayerStatus {
playerOnOpWhitelist,
playerNameNotOnTheOpWhitelist,
playerUuidNotOnTheOpWhitelist,
playerOnPermissionWhitelist,
playerNameNotOnThePermissionWhitelist,
playerUuidNotOnThePermissionWhitelist
}

View File

@@ -8,7 +8,7 @@ public class Util {
private static String infoText = "";
@Getter
private static String requiredT2CodeLibVersion = "13.4";
private static String requiredT2CodeLibVersion = "15.0";
@Getter
private static String prefix = "§8[§4T2C§8-§2OP§4Security§8]";
@@ -27,5 +27,8 @@ public class Util {
@Getter
private static String discord = "http://dc.t2code.net";
@Getter
private static Integer configVersion = 2;
}

View File

@@ -4,11 +4,12 @@ import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.language.Language;
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.events.Events;
import net.t2code.opsecurity.objects.PlayerCash;
import net.t2code.opsecurity.objects.PlayerCache;
import net.t2code.opsecurity.objects.PlayerObject;
import net.t2code.opsecurity.system.BungeeSenderReceiver;
import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.commands.T2Ccmd;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -16,25 +17,26 @@ import org.bukkit.entity.Player;
import java.util.Map;
public class OpCheck {
public static Boolean onCheck(Player player, Boolean join) {
public static Boolean onCheck(Player player, Boolean join, String debug) {
if (!OPWhitelist.enable.valueBoolean) return false;
if (!player.isOp()) return false;
if (opWhitelist(player)) 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())));
Bukkit.getScheduler().runTask(Main.getPlugin(), new Runnable() {
@Override
public void run() {
execute(player, join);
execute(player, join, debug);
}
});
return true;
}
private static void execute(Player player, Boolean join) {
private static void execute(Player player, Boolean join, String debug) {
if (Config.notifyJoinWarning.valueBoolean && join) {
if (Config.notifyBungee.valueBoolean) {
BungeeSenderReceiver.sendToBungee(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} else Events.notifyPlayer(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} else
Events.notifyPlayer(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
}
if (OPWhitelist.noOpPlayerSetGameModeEnable.valueBoolean) {
@@ -52,12 +54,12 @@ public class OpCheck {
} else player.kickPlayer(OPWhitelist.noOpPlayerDeopEnable.valueBoolean && OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean
? Language.opWhitelistKick.value + "\n \n" + Language.opWhitelistDeop.value : Language.opWhitelistKick.value);
}
T2Csend.console(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>"
+ Language.opWhitelistNotifyKick.value.replace("[player]", player.getName().replace("[uuid]", String.valueOf(player.getUniqueId()))).replace("[uuid]", String.valueOf(player.getUniqueId())));
Events.notifyPlayer(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()) + "<br>"
+ Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} else {
T2Csend.console(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())));
if (OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean) {
@@ -77,7 +79,7 @@ public class OpCheck {
T2Ccmd.console(Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]", Language.opWhitelistKick.value));
} else player.kickPlayer(Language.opWhitelistKick.value);
}
T2Csend.console(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())));
}
}
@@ -88,9 +90,18 @@ public class OpCheck {
}
}
public static Boolean opWhitelist(Player player) {
for (Map.Entry<String, PlayerObject> playerObject : PlayerCash.getOpHashMap().entrySet()) {
if (playerObject.getValue().playerName.equals(player.getName()) && playerObject.getValue().uuid.equals(player.getUniqueId().toString())) return true;
public static Boolean opWhitelist(Player player, String debug) {
for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getOpHashMap().entrySet()) {
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] --------- " + player.getName()+" ---------");
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] opWhitelist playerObject Name: " + playerObject.getValue().playerName);
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] opWhitelist Player Name: " + player.getName());
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] opWhitelist playerObject UUID: " + playerObject.getValue().uuid);
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] opWhitelist Player UUID: " + player.getUniqueId().toString().replace("-", ""));
if (playerObject.getValue().playerName.equals(player.getName()) && playerObject.getValue().uuid.equals(player.getUniqueId().toString().replace("-", ""))) {
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] opWhitelist Player on list!");
T2Cdebug.debug(Main.getPlugin(),"");
return true;
} else T2Cdebug.debug(Main.getPlugin(),"");
}
return false;
}

View File

@@ -4,11 +4,12 @@ import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.language.Language;
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist;
import net.t2code.opsecurity.events.Events;
import net.t2code.opsecurity.objects.PlayerCash;
import net.t2code.opsecurity.objects.PlayerCache;
import net.t2code.opsecurity.objects.PlayerObject;
import net.t2code.opsecurity.system.BungeeSenderReceiver;
import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.commands.T2Ccmd;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -16,15 +17,16 @@ import org.bukkit.entity.Player;
import java.util.Map;
public class PermissionCheck {
public static Boolean onCheck(Player player, Boolean join) {
public static Boolean onCheck(Player player, Boolean join, String debug) {
if (!PermissionWhitelist.enable.valueBoolean) return false;
for (String perm : PermissionWhitelist.permissions.valueStringList) {
if (!player.hasPermission(perm)) continue;
if (permWhitelist(player)) continue;
if (!player.hasPermission(perm)) return false;
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] check Permission: " + perm);
if (permWhitelist(player, debug)) return false;
Bukkit.getScheduler().runTask(Main.getPlugin(), new Runnable() {
@Override
public void run() {
execute(player, join, perm);
execute(player, join, perm, debug);
}
});
return true;
@@ -32,19 +34,21 @@ public class PermissionCheck {
return false;
}
private static void execute(Player player, Boolean join, String perm) {
if (join) T2Csend.console(Language.permissionWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]",String.valueOf(player.getUniqueId())));
private static void execute(Player player, Boolean join, String perm, String debug) {
if (join)
T2Csend.console("[" + debug + "]" + Language.permissionWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
if (Config.notifyJoinWarning.valueBoolean && join) {
if (Config.notifyBungee.valueBoolean) {
BungeeSenderReceiver.sendToBungee(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} else Events.notifyPlayer(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]",String.valueOf(player.getUniqueId())));
} else
Events.notifyPlayer(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
}
if (PermissionWhitelist.playerWithPermissionKick.valueBoolean) {
if (Config.kickCustomCommand.valueBoolean) {
T2Ccmd.console(Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]", Language.permissionWhitelistKick.value));
T2Ccmd.console(Config.kickCommand.valueString.replace("[perm]", perm).replace("[player]", player.getName()).replace("[reason]", Language.permissionWhitelistKick.value));
} else player.kickPlayer(Language.permissionWhitelistKick.value);
T2Csend.console(Language.permissionWhitelistNotifyKick.value.replace("[player]",
T2Csend.console("[" + debug + "]" + Language.permissionWhitelistNotifyKick.value.replace("[player]",
player.getName()).replace("[perm]", perm).replace("[uuid]", String.valueOf(player.getUniqueId())));
}
if (PermissionWhitelist.customCommandsEnable.valueBoolean) {
@@ -54,9 +58,19 @@ public class PermissionCheck {
}
}
private static Boolean permWhitelist(Player player) {
for (Map.Entry<String, PlayerObject> playerObject : PlayerCash.getPermissionHashMap().entrySet()) {
if (playerObject.getValue().playerName.equals(player.getName()) && playerObject.getValue().uuid.equals(player.getUniqueId().toString())) return true;
public static Boolean permWhitelist(Player player, String debug) {
for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getPermissionHashMap().entrySet()) {
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] --------- " + player.getName() + " ---------");
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] permWhitelist playerObject Name: " + playerObject.getValue().playerName);
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] permWhitelist Player Name: " + player.getName());
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] permWhitelist playerObject UUID: " + playerObject.getValue().uuid);
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] permWhitelist Player UUID: " + player.getUniqueId().toString().replace("-", ""));
if (playerObject.getValue().playerName.equals(player.getName()) && playerObject.getValue().uuid.equals(player.getUniqueId().toString().replace("-", ""))) {
T2Cdebug.debug(Main.getPlugin(), "[" + debug + "] permWhitelist Player on list!");
T2Cdebug.debug(Main.getPlugin(), "");
return true;
} else T2Cdebug.debug(Main.getPlugin(), "");
}
return false;
}

View File

@@ -6,6 +6,7 @@ import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist;
import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -19,8 +20,9 @@ public class Timer {
@Override
public void run() {
for (Player player : Bukkit.getOnlinePlayers()) {
OpCheck.onCheck(player, false);
PermissionCheck.onCheck(player, false);
String debug = T2Cdebug.debugCode();
OpCheck.onCheck(player, false, debug);
PermissionCheck.onCheck(player, false, debug);
}
}
}, 0, 20L * Config.checkTimerRefreshInSec.valueInt);

View File

@@ -4,12 +4,8 @@ package net.t2code.opsecurity.command;
import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.objects.PlayerCash;
import net.t2code.opsecurity.objects.PlayerObject;
import net.t2code.opsecurity.system.Main;
import net.t2code.opsecurity.system.Permissions;
import net.t2code.t2codelib.SPIGOT.api.commands.T2Ctab;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -18,7 +14,6 @@ import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CmdExecuter implements CommandExecutor, TabCompleter {

View File

@@ -5,10 +5,9 @@ import net.t2code.opsecurity.check.OpCheck;
import net.t2code.opsecurity.config.FileSelect;
import net.t2code.opsecurity.config.config.Config;
import net.t2code.opsecurity.config.language.Language;
import net.t2code.opsecurity.enums.OpCommandRequest;
import net.t2code.opsecurity.objects.PlayerCash;
import net.t2code.opsecurity.system.Main;
import net.t2code.opsecurity.system.Permissions;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import org.bukkit.Bukkit;
@@ -55,7 +54,8 @@ public class Commands {
if (sender instanceof Player) {
Player player = (Player) sender;
if (Config.onlyOPcanUseThePlugin.valueBoolean) {
if (!OpCheck.opWhitelist(player)) {
String debug = T2Cdebug.debugCode();
if (!OpCheck.opWhitelist(player, debug)) {
sender.sendMessage(Util.getPrefix() + " §4You are not on the Whitelist!"); // todo
return;
}

View File

@@ -2,14 +2,17 @@ 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;
import net.t2code.opsecurity.objects.PlayerCash;
import net.t2code.opsecurity.objects.PlayerCache;
import net.t2code.opsecurity.objects.PlayerObject;
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;
@@ -23,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:
@@ -31,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());
@@ -84,7 +107,7 @@ public class FileSelect {
}
}
}
T2Csend.debug(Main.getPlugin(), "save: " + language);
T2Cdebug.debug(Main.getPlugin(), "save: " + language);
try {
yamlConfiguration.save(config);
} catch (IOException e) {
@@ -94,7 +117,7 @@ public class FileSelect {
String selectMSG;
File config = new File(Main.getPath(), "languages/" + Config.language.valueString + ".yml");
T2Csend.debug(Main.getPlugin(), config.getAbsolutePath());
T2Cdebug.debug(Main.getPlugin(), config.getAbsolutePath());
if (!config.isFile()) {
T2Csend.console(Util.getPrefix());
T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
@@ -108,14 +131,14 @@ public class FileSelect {
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (Language value : Language.values()) {
T2Csend.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));
}
T2Csend.console(Util.getPrefix() + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
}
public static void selectOpWhitelist() {
PlayerCash.getOpHashMap().clear();
PlayerCache.getOpHashMap().clear();
File config = new File(Main.getPath(), "opWhitelist.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (OPWhitelist value : OPWhitelist.values()) {
@@ -128,7 +151,7 @@ public class FileSelect {
break;
case STRINGLIST:
if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueBoolean);
yamlConfiguration.set(value.path, value.valueStringList);
}
value.valueStringList = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getStringList(value.path));
break;
@@ -144,7 +167,7 @@ public class FileSelect {
PlayerObject playerObject = new PlayerObject(
name,
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key)).replace("-", ""));
PlayerCash.getOpHashMap().put(name, playerObject);
PlayerCache.getOpHashMap().put(name, playerObject);
}
break;
case GAMEMODE:
@@ -168,7 +191,7 @@ public class FileSelect {
}
public static void selectPermissionWhitelist() {
PlayerCash.getPermissionHashMap().clear();
PlayerCache.getPermissionHashMap().clear();
File config = new File(Main.getPath(), "permissionWhitelist.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (PermissionWhitelist value : PermissionWhitelist.values()) {
@@ -196,8 +219,8 @@ public class FileSelect {
String name = yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key));
PlayerObject playerObject = new PlayerObject(
name,
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key).replace("-", "")));
PlayerCash.getPermissionHashMap().put(name, playerObject);
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key)).replace("-", ""));
PlayerCache.getPermissionHashMap().put(name, playerObject);
}
break;
}

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,13 +16,14 @@ 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),
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),
@@ -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

@@ -58,8 +58,9 @@ public enum Language {
"[prefix] <dark_red>Player <gold><hover:show_text:'<gold>Name:</gold> <yellow>[player]</yellow><br><gold>UUID:</gold> <yellow>[uuid]</yellow>'>[player]</hover></gold> has permission <gold>[perm]</gold> and is not authorized to do so! Therefore he was kicked! <gold><hover:show_text:'<gold>Name:</gold> <yellow>[player]</yellow><br><gold>UUID:</gold> <yellow>[uuid]</yellow>'>[player]</hover></gold> is not on the Player list!</dark_red>"),
permissionWhitelistKick("permissionWhitelist.kick",null,
"<dark_red>Du wurdest gekickt, da du Permissions besitzt, für die du keine Berechtigung besitzt!</dark_red>",
"<dark_red>You were kicked because you have permissions to which you do not have permission!</dark_red>"),
"&4Du wurdest gekickt, da du Permissions besitzt, für die du keine Berechtigung besitzt!",
"&4You were kicked because you have permissions to which you do not have permission!"),
exactKickReason("console.exactKickReason", null,
"[prefix] <dark_red>Genauer Grund:</dark_red> <gold>[reason]</gold>",
"[prefix] <dark_red>Exact reason:</dark_red> <gold>[reason]</gold>");

View File

@@ -9,7 +9,7 @@ import java.util.List;
public enum OPWhitelist {
enable("opWhitelist.enable", false, ConfigParam.BOOLEAN),
playerMustBeOnlineToOp("opWhitelist.playerMustBeOnlineToOp", true, ConfigParam.BOOLEAN),
noOpPlayerDeopEnable("opWhitelist.enable", 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),

View File

@@ -6,6 +6,7 @@ import net.t2code.opsecurity.check.OpCheck;
import net.t2code.opsecurity.check.PermissionCheck;
import net.t2code.opsecurity.system.Main;
import net.t2code.opsecurity.system.Permissions;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import org.bukkit.Bukkit;
@@ -28,17 +29,37 @@ public class Events implements Listener {
public void CommandSendEvent(PlayerCommandPreprocessEvent event) {
if (!Config.checkOnCommand.valueBoolean) return;
Player player = event.getPlayer();
if (OpCheck.onCheck(player, false) || PermissionCheck.onCheck(player, false)) {
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);
}
String debug2 = T2Cdebug.debugCode();
if (PermissionCheck.onCheck(player, false, debug2)) {
if (event.isCancelled()) return;
event.setCancelled(true);
}
}
@EventHandler
public void PlayerChatEvent(PlayerChatEvent event) {
if (!Config.checkOnChat.valueBoolean) return;
Player player = event.getPlayer();
if (OpCheck.onCheck(player, false) || PermissionCheck.onCheck(player, false)) {
String debug = T2Cdebug.debugCode();
if (OpCheck.onCheck(player, false, debug)) {
if (event.isCancelled()) return;
event.setCancelled(true);
}
String debug2 = T2Cdebug.debugCode();
if (PermissionCheck.onCheck(player, false, debug2)) {
if (event.isCancelled()) return;
event.setCancelled(true);
}
@@ -47,11 +68,16 @@ public class Events implements Listener {
@EventHandler
public void onInteract(PlayerInteractEvent event) {
if (!Config.checkOnInteract.valueBoolean) return;
Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() {
@Override
public void run() {
if (OpCheck.onCheck(player, false) || PermissionCheck.onCheck(player, false)) {
Player player = event.getPlayer();
String debug = T2Cdebug.debugCode();
if (OpCheck.onCheck(player, false, debug)) {
event.setCancelled(true);
}
String debug2 = T2Cdebug.debugCode();
if (PermissionCheck.onCheck(player, false, debug2)) {
event.setCancelled(true);
}
}
@@ -61,12 +87,14 @@ public class Events implements Listener {
@EventHandler
public void onJoinCheck(PlayerJoinEvent event) {
if (!Config.checkOnJoin.valueBoolean) return;
Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() {
@Override
public void run() {
OpCheck.onCheck(player, true);
PermissionCheck.onCheck(player, true);
Player player = event.getPlayer();
String debug = T2Cdebug.debugCode();
OpCheck.onCheck(player, true, debug);
String debug2 = T2Cdebug.debugCode();
PermissionCheck.onCheck(player, true, debug2);
}
}, 1L);
}

View File

@@ -1,11 +1,12 @@
package net.t2code.opsecurity.events;
import net.t2code.opsecurity.check.OpCheck;
import net.t2code.opsecurity.config.language.Language;
import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.enums.OpCommandRequest;
import net.t2code.opsecurity.objects.PlayerCash;
import net.t2code.opsecurity.objects.PlayerCache;
import net.t2code.opsecurity.objects.PlayerObject;
import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.player.T2CnameHistory;
import org.bukkit.Bukkit;
@@ -57,10 +58,12 @@ public class OpCommand implements Listener {
if (command.charAt(0) == '/') command = command.replaceFirst("/", "");
String arg = command.replace("op ", "");
Player target = Bukkit.getPlayer(arg);
if (OPWhitelist.playerMustBeOnlineToOp.valueBoolean) {
if (target == null) return OpCommandRequest.mustOnline;
if (!opWhitelist(target.getName(), target.getUniqueId().toString())) return OpCommandRequest.notWhitelisted;
}
String targetUUID;
if (target != null) {
targetUUID = target.getUniqueId().toString();
@@ -76,8 +79,16 @@ public class OpCommand implements Listener {
}
private static Boolean opWhitelist(String playerName, String playerUuid) {
for (Map.Entry<String, PlayerObject> playerObject : PlayerCash.getOpHashMap().entrySet()) {
if (playerObject.getValue().playerName.equals(playerName) && playerObject.getValue().uuid.equals(playerUuid)) return true;
for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getOpHashMap().entrySet()) {
T2Cdebug.debug(Main.getPlugin(), "--------- " + playerName);
T2Cdebug.debug(Main.getPlugin(),"opWhitelist (op command) playerObject Name: "+playerObject.getValue().playerName );
T2Cdebug.debug(Main.getPlugin(),"opWhitelist (op command) Player Name: "+ playerName );
T2Cdebug.debug(Main.getPlugin(),"opWhitelist (op command) playerObject UUID: "+playerObject.getValue().uuid );
T2Cdebug.debug(Main.getPlugin(),"opWhitelist (op command) Player UUID: "+ playerUuid );
if (playerObject.getValue().playerName.equals(playerName) && playerObject.getValue().uuid.equals(playerUuid.replace("-", ""))) {
T2Cdebug.debug(Main.getPlugin(),"opWhitelist (op command) on list!");
return true;
}
}
return false;
}

View File

@@ -4,7 +4,7 @@ import lombok.Getter;
import java.util.HashMap;
public class PlayerCash {
public class PlayerCache {
@Getter
private static HashMap<String, PlayerObject> opHashMap = new HashMap<String, PlayerObject>();
@Getter

View File

@@ -1,6 +1,7 @@
package net.t2code.opsecurity.system;
import net.t2code.opsecurity.events.Events;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -27,7 +28,7 @@ public class BungeeSenderReceiver implements PluginMessageListener {
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(message));
T2Csend.debug(Main.getPlugin(), "stream: " + stream.toString());
T2Cdebug.debug(Main.getPlugin(), "stream: " + stream.toString());
try {
String subChannel = stream.readUTF();
String information = stream.readUTF();

View File

@@ -9,11 +9,17 @@ import net.t2code.opsecurity.events.Events;
import net.t2code.opsecurity.events.OpCommand;
import net.t2code.opsecurity.events.PlugManCommand;
import net.t2code.opsecurity.check.Timer;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
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;
@@ -33,12 +39,17 @@ public class Load {
FileSelect.selectOpWhitelist();
FileSelect.selectPermissionWhitelist();
setConfigVersion();
plugin.getCommand("t2c-opsecurity").setExecutor(new CmdExecuter());
T2Cregister.listener(new OpCommand(), plugin);
T2Cregister.listener(new PlugManCommand(), plugin);
T2Cregister.listener(new Events(), plugin);
if (SelectLibConfig.getBungee()) {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "t2c:opsec");
T2Csend.debug(plugin, "registerIncomingPluginChannel §et2c:opsec");
}
Timer.refreshTimer();
Permissions.register();
T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(),Util.getGit(),Util.getSpigotID(),Util.getDiscord(), Config.updateCheckOnJoin.valueBoolean,
@@ -46,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

@@ -32,6 +32,20 @@ public final class Main extends JavaPlugin {
autor = this.getDescription().getAuthors();
version = this.getDescription().getVersion();
if (pluginNotFound("T2CodeLib", 96388, Util.getRequiredT2CodeLibVersion())) return;
load();
}
private static void load(){
if (!Bukkit.getPluginManager().getPlugin("T2CodeLib").isEnabled()){
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
load();
}
},5L);
return;
}
t2codeLib = true;
Load.onLoad(plugin,autor,version);
}

View File

@@ -6,9 +6,11 @@ api-version: 1.13
load: STARTUP
prefix: T2C-OPSecurity
authors: [ JaTiTV ]
softdepend:
- T2CodeLib
- OPSecurity
commands:
t2c-opsecurity:
aliases: [opsec, opsecurity]