better debug information & async bugfix

This commit is contained in:
JaTiTV 2023-04-23 12:53:25 +02:00
parent 98fd0409fd
commit 9351c0dfb7
8 changed files with 62 additions and 35 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.0</version> <version>3.1.1_DEV-1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
@ -83,7 +83,7 @@
<dependency> <dependency>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId> <artifactId>T2CodeLib</artifactId>
<version>13.4</version> <version>14.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

@ -7,6 +7,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.PlayerCache; import net.t2code.opsecurity.objects.PlayerCache;
import net.t2code.opsecurity.objects.PlayerObject; import net.t2code.opsecurity.objects.PlayerObject;
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.entity.Player; import org.bukkit.entity.Player;
@ -17,7 +18,8 @@ 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 (!OPWhitelist.enable.valueBoolean) return true;
return OpCheck.opWhitelist(player); String debug = T2Cdebug.debugCode();
return OpCheck.opWhitelist(player,debug);
} }
public static boolean checkPermissionWhiteList(Player player) { public static boolean checkPermissionWhiteList(Player player) {

View File

@ -8,7 +8,7 @@ public class Util {
private static String infoText = ""; private static String infoText = "";
@Getter @Getter
private static String requiredT2CodeLibVersion = "13.4"; private static String requiredT2CodeLibVersion = "14.4";
@Getter @Getter
private static String prefix = "§8[§4T2C§8-§2OP§4Security§8]"; private static String prefix = "§8[§4T2C§8-§2OP§4Security§8]";

View File

@ -16,25 +16,26 @@ import org.bukkit.entity.Player;
import java.util.Map; import java.util.Map;
public class OpCheck { 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 (!OPWhitelist.enable.valueBoolean) return false;
if (!player.isOp()) 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()))); if (join) T2Csend.console(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
Bukkit.getScheduler().runTask(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().runTask(Main.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
execute(player, join); execute(player, join, debug);
} }
}); });
return true; 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.notifyJoinWarning.valueBoolean && join) {
if (Config.notifyBungee.valueBoolean) { if (Config.notifyBungee.valueBoolean) {
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 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) { if (OPWhitelist.noOpPlayerSetGameModeEnable.valueBoolean) {
@ -46,18 +47,18 @@ public class OpCheck {
if (OPWhitelist.noOpPlayerKickEnable.valueBoolean) { if (OPWhitelist.noOpPlayerKickEnable.valueBoolean) {
if (!OPWhitelist.customCommandsEnable.valueBoolean) { if (!OPWhitelist.customCommandsEnable.valueBoolean) {
if (Config.kickCustomCommand.valueBoolean) { if (Config.kickCustomCommand.valueBoolean) {
T2Ccmd.console(Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]", T2Ccmd.console( Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]",
OPWhitelist.noOpPlayerKickEnable.valueBoolean && OPWhitelist.noOpPlayerDeopEnable.valueBoolean && OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean OPWhitelist.noOpPlayerKickEnable.valueBoolean && OPWhitelist.noOpPlayerDeopEnable.valueBoolean && OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean
? 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(OPWhitelist.noOpPlayerDeopEnable.valueBoolean && OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean
? Language.opWhitelistKick.value + "\n \n" + Language.opWhitelistDeop.value : Language.opWhitelistKick.value); ? 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()))); + 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>" Events.notifyPlayer(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()) + "<br>"
+ Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId()))); + Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} else { } 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()))); Events.notifyPlayer(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
if (OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean) { if (OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean) {
@ -77,7 +78,7 @@ public class OpCheck {
T2Ccmd.console(Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]", Language.opWhitelistKick.value)); T2Ccmd.console(Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]", Language.opWhitelistKick.value));
} else player.kickPlayer(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()))); Events.notifyPlayer(Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]", String.valueOf(player.getUniqueId())));
} }
} }
@ -88,15 +89,15 @@ public class OpCheck {
} }
} }
public static Boolean opWhitelist(Player player) { public static Boolean opWhitelist(Player player, String debug) {
for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getOpHashMap().entrySet()) { for (Map.Entry<String, PlayerObject> playerObject : PlayerCache.getOpHashMap().entrySet()) {
T2Csend.debug(Main.getPlugin(), "--------- " + player.getName()); T2Csend.debug(Main.getPlugin(), "[" + debug + "] --------- " + player.getName());
T2Csend.debug(Main.getPlugin(), "opWhitelist playerObject Name: " + playerObject.getValue().playerName); T2Csend.debug(Main.getPlugin(), "[" + debug + "] opWhitelist playerObject Name: " + playerObject.getValue().playerName);
T2Csend.debug(Main.getPlugin(), "opWhitelist Player Name: " + player.getName()); T2Csend.debug(Main.getPlugin(), "[" + debug + "] opWhitelist Player Name: " + player.getName());
T2Csend.debug(Main.getPlugin(), "opWhitelist playerObject UUID: " + playerObject.getValue().uuid); T2Csend.debug(Main.getPlugin(), "[" + debug + "] opWhitelist playerObject UUID: " + playerObject.getValue().uuid);
T2Csend.debug(Main.getPlugin(), "opWhitelist Player UUID: " + player.getUniqueId().toString().replace("-", "")); T2Csend.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("-", ""))) { if (playerObject.getValue().playerName.equals(player.getName()) && playerObject.getValue().uuid.equals(player.getUniqueId().toString().replace("-", ""))) {
T2Csend.debug(Main.getPlugin(), "opWhitelist Player on list!"); T2Csend.debug(Main.getPlugin(), "[" + debug + "] opWhitelist Player on list!");
return true; return true;
} }
} }

View File

@ -16,7 +16,7 @@ import org.bukkit.entity.Player;
import java.util.Map; import java.util.Map;
public class PermissionCheck { 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; if (!PermissionWhitelist.enable.valueBoolean) return false;
for (String perm : PermissionWhitelist.permissions.valueStringList) { for (String perm : PermissionWhitelist.permissions.valueStringList) {
if (!player.hasPermission(perm)) return false; if (!player.hasPermission(perm)) return false;
@ -24,7 +24,7 @@ public class PermissionCheck {
Bukkit.getScheduler().runTask(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().runTask(Main.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
execute(player, join, perm); execute(player, join, perm, debug);
} }
}); });
return true; return true;
@ -32,8 +32,8 @@ public class PermissionCheck {
return false; return false;
} }
private static void execute(Player player, Boolean join, String perm) { private static void execute(Player player, Boolean join, String perm, String debug) {
if (join) T2Csend.console(Language.permissionWhitelistNotifyKick.value.replace("[player]", player.getName()).replace("[uuid]",String.valueOf(player.getUniqueId()))); 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.notifyJoinWarning.valueBoolean && join) {
if (Config.notifyBungee.valueBoolean) { if (Config.notifyBungee.valueBoolean) {
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())));
@ -44,7 +44,7 @@ public class PermissionCheck {
if (Config.kickCustomCommand.valueBoolean) { if (Config.kickCustomCommand.valueBoolean) {
T2Ccmd.console(Config.kickCommand.valueString.replace("[perm]", perm).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); } 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()))); player.getName()).replace("[perm]", perm).replace("[uuid]",String.valueOf(player.getUniqueId())));
} }
if (PermissionWhitelist.customCommandsEnable.valueBoolean) { if (PermissionWhitelist.customCommandsEnable.valueBoolean) {

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

View File

@ -7,6 +7,7 @@ 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.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.messages.T2Csend; 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 org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -53,7 +54,8 @@ public class Commands {
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; Player player = (Player) sender;
if (Config.onlyOPcanUseThePlugin.valueBoolean) { 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 sender.sendMessage(Util.getPrefix() + " §4You are not on the Whitelist!"); // todo
return; return;
} }

View File

@ -6,6 +6,7 @@ import net.t2code.opsecurity.check.OpCheck;
import net.t2code.opsecurity.check.PermissionCheck; import net.t2code.opsecurity.check.PermissionCheck;
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.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;
@ -28,7 +29,13 @@ public class Events implements Listener {
public void CommandSendEvent(PlayerCommandPreprocessEvent event) { public void CommandSendEvent(PlayerCommandPreprocessEvent event) {
if (!Config.checkOnCommand.valueBoolean) return; if (!Config.checkOnCommand.valueBoolean) return;
Player player = event.getPlayer(); 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; if (event.isCancelled()) return;
event.setCancelled(true); event.setCancelled(true);
} }
@ -38,7 +45,13 @@ public class Events implements Listener {
public void PlayerChatEvent(PlayerChatEvent event) { public void PlayerChatEvent(PlayerChatEvent event) {
if (!Config.checkOnChat.valueBoolean) return; if (!Config.checkOnChat.valueBoolean) return;
Player player = event.getPlayer(); 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; if (event.isCancelled()) return;
event.setCancelled(true); event.setCancelled(true);
} }
@ -47,11 +60,16 @@ public class Events implements Listener {
@EventHandler @EventHandler
public void onInteract(PlayerInteractEvent event) { public void onInteract(PlayerInteractEvent event) {
if (!Config.checkOnInteract.valueBoolean) return; if (!Config.checkOnInteract.valueBoolean) return;
Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() {
@Override @Override
public void run() { 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); event.setCancelled(true);
} }
} }
@ -61,12 +79,14 @@ public class Events implements Listener {
@EventHandler @EventHandler
public void onJoinCheck(PlayerJoinEvent event) { public void onJoinCheck(PlayerJoinEvent event) {
if (!Config.checkOnJoin.valueBoolean) return; if (!Config.checkOnJoin.valueBoolean) return;
Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
OpCheck.onCheck(player, true); Player player = event.getPlayer();
PermissionCheck.onCheck(player, true); String debug = T2Cdebug.debugCode();
OpCheck.onCheck(player, true, debug);
String debug2 = T2Cdebug.debugCode();
PermissionCheck.onCheck(player, true, debug2);
} }
}, 1L); }, 1L);
} }