3.0.0-SNAPSHOT-#1

This commit is contained in:
JaTiTV 2022-11-03 19:15:07 +01:00
parent 758d5e7a8d
commit d9206e63a7
30 changed files with 555 additions and 239 deletions

View File

@ -103,6 +103,7 @@ public class Check {
} }
} }
} }
if (SelectConfig.playerWhithPermissionKick && SelectConfig.permCommandEnable) { if (SelectConfig.playerWhithPermissionKick && SelectConfig.permCommandEnable) {
T2Ccmd.console(SelectConfig.kickCommand.replace("[player]", player.getName()).replace("[reason]", T2Creplace.replace(Util.getPrefix(), SelectMessages.Perm_kick))); T2Ccmd.console(SelectConfig.kickCommand.replace("[player]", player.getName()).replace("[reason]", T2Creplace.replace(Util.getPrefix(), SelectMessages.Perm_kick)));
T2Csend.console(T2Creplace.replace(Util.getPrefix(), SelectMessages.Perm_consoleKick.replace("[player]", T2Csend.console(T2Creplace.replace(Util.getPrefix(), SelectMessages.Perm_consoleKick.replace("[player]",
@ -120,6 +121,7 @@ public class Check {
for (String cmd : SelectConfig.permCommand) { for (String cmd : SelectConfig.permCommand) {
T2Ccmd.console(cmd.replace("[player]", player.getName()).replace("[perm]", s)); T2Ccmd.console(cmd.replace("[player]", player.getName()).replace("[perm]", s));
} }
} }
return true; return true;
} }

View File

@ -40,7 +40,6 @@ public class OPCommand implements Listener {
@EventHandler @EventHandler
public void onOpPlayer(PlayerCommandPreprocessEvent event) { public void onOpPlayer(PlayerCommandPreprocessEvent event) {
if (SelectConfig.opWhitelistEnable) { if (SelectConfig.opWhitelistEnable) {
if ((event.getMessage().toLowerCase().startsWith("/op ") || event.getMessage().toLowerCase().startsWith("/minecraft:op "))) { if ((event.getMessage().toLowerCase().startsWith("/op ") || event.getMessage().toLowerCase().startsWith("/minecraft:op "))) {
switch (this.isNotOPWTL(event.getMessage())) { switch (this.isNotOPWTL(event.getMessage())) {

View File

@ -12,7 +12,6 @@ import org.bukkit.event.server.ServerCommandEvent;
public class PlugManCommand implements Listener { public class PlugManCommand implements Listener {
@EventHandler @EventHandler
public void onOPServer(ServerCommandEvent event) { public void onOPServer(ServerCommandEvent event) {
if ((event.getCommand().toLowerCase().contains("plugman disable") && event.getCommand().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase())) if ((event.getCommand().toLowerCase().contains("plugman disable") && event.getCommand().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase()))

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2C-OPSecurity</artifactId> <artifactId>T2C-OPSecurity</artifactId>
<version>1.0-SNAPSHOT</version> <version>3.0.0-SNAPSHOT-#1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>T2C-OPSecurity</name> <name>T2C-OPSecurity</name>

View File

@ -1,31 +1,28 @@
package net.t2code.opsecurity; package net.t2code.opsecurity;
import lombok.Getter;
public class Util { public class Util {
public static String getInfoText() {
return "";
}
public static String getRequiredT2CodeLibVersion() { @Getter
return "13.0"; private static String infoText = "";
}
public static String getPrefix() { @Getter
return "§8[§T2C§8-§2OP§4Security§8]"; private static String requiredT2CodeLibVersion = "13.1";
}
public static Integer getSpigotID() { @Getter
return 90739; private static String prefix = "§8[§4T2C§8-§2OP§4Security§8]";
}
public static Integer getBstatsID() { @Getter
return 10858; private static Integer spigotID = 90739;
}
public static String getSpigot() { @Getter
return "https://www.spigotmc.org/resources/" + getSpigotID(); private static Integer bstatsID = 10858;
}
@Getter
private static String spigot = "https://www.spigotmc.org/resources/" + getSpigotID();
@Getter
private static String discord = "http://dc.t2code.net";
public static String getDiscord() {
return "http://dc.t2code.net";
}
} }

View File

@ -0,0 +1,77 @@
package net.t2code.opsecurity.check;
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.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.messages.T2Csend;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Map;
public class OpCheck {
public static Boolean onCheck(Player player, Boolean join) {
if (!OPWhitelist.enable.valueBoolean) return false;
if (!player.isOp()) return false;
if (opWhitelist(player)) return false;
if (join) T2Csend.console(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()));
if (Config.notifyJoinWarning.valueBoolean&& join) {
if (Config.notifyBungee.valueBoolean ) {
BungeeSenderReceiver.sendToBungee(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()));
} else Events.notifyPlayer(Language.opWhitelistNotifyOnJoin.value.replace("[player]", player.getName()));
}
if (OPWhitelist.noOpPlayerDeopEnable.valueBoolean) {
player.setOp(false);
if (OPWhitelist.noOpPlayerKickEnable.valueBoolean) {
if (!OPWhitelist.customCommandsEnable.valueBoolean) T2Ccmd.console(Config.kickCommand.path.replace("[player]", player.getName()).replace("[reason]",
OPWhitelist.noOpPlayerKickEnable.valueBoolean && OPWhitelist.noOpPlayerDeopEnable.valueBoolean && OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean
? Language.opWhitelistKick.value + "<br><br>" + Language.opWhitelistDeop.value : Language.opWhitelistKick.value));
T2Csend.console(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()) + "<br>"
+ Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()));
Events.notifyPlayer(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()) + "<br>"
+ Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()));
} else {
T2Csend.console(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()));
Events.notifyPlayer(Language.opWhitelistNotifyDeop.value.replace("[player]", player.getName()));
if (OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean) {
Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
@Override
public void run() {
T2Csend.player(player, Language.opWhitelistDeop.value);
}
}, 5L);
}
}
}
if (OPWhitelist.noOpPlayerKickEnable.valueBoolean) {
if (!OPWhitelist.customCommandsEnable.valueBoolean)
T2Ccmd.console(Config.kickCommand.path.replace("[player]", player.getName()).replace("[reason]", Language.opWhitelistKick.value));
T2Csend.console(Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()));
Events.notifyPlayer(Language.opWhitelistNotifyKick.value.replace("[player]", player.getName()));
}
if (OPWhitelist.customCommandsEnable.valueBoolean) {
for (String cmd : OPWhitelist.customCommandsCommands.valueStringList) {
T2Ccmd.console(cmd.replace("[player]", player.getName()));
}
}
return true;
}
private static Boolean opWhitelist(Player player) {
for (Map.Entry<String, PlayerObject> playerObject : PlayerCash.getOpHashMap().entrySet()){
if (playerObject.getValue().playerName.equals(player.getName())) return true;
if (playerObject.getValue().uuid.equals(player.getUniqueId().toString())) return true;
}
T2Csend.console(Language.exactKickReason.value.replace("[reason]", "Player UUID: " + player.getUniqueId().toString() + " not whitelisted (opWhitelist)"));
return false;
}
}

View File

@ -0,0 +1,53 @@
package net.t2code.opsecurity.check;
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.PlayerObject;
import net.t2code.opsecurity.system.BungeeSenderReceiver;
import net.t2code.t2codelib.SPIGOT.api.commands.T2Ccmd;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.entity.Player;
import java.util.Map;
public class PermissionCheck {
public static Boolean onCheck(Player player, Boolean join) {
if (!PermissionWhitelist.enable.valueBoolean) return false;
for (String perm : PermissionWhitelist.permissions.valueStringList) {
if (!player.hasPermission(perm)) continue;
if (permWhitelist(player)) continue;
if (join) T2Csend.console(Language.permissionWhitelistNotifyKick.value.replace("[player]", player.getName()));
if (Config.notifyJoinWarning.valueBoolean && join) {
if (Config.notifyBungee.valueBoolean) {
BungeeSenderReceiver.sendToBungee(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()));
} else Events.notifyPlayer(Language.permissionWhitelistNotifyOnJoin.value.replace("[player]", player.getName()));
}
if (PermissionWhitelist.playerWithPermissionKick.valueBoolean) {
T2Ccmd.console(Config.kickCommand.valueString.replace("[player]", player.getName()).replace("[reason]", Language.permissionWhitelistKick.value));
T2Csend.console(Language.permissionWhitelistNotifyKick.value.replace("[player]",
player.getName()).replace("[perm]", perm));
}
if (PermissionWhitelist.customCommandsCommands.valueBoolean) {
for (String cmd : PermissionWhitelist.customCommandsCommands.valueStringList) {
T2Ccmd.console(cmd.replace("[player]", player.getName()).replace("[perm]", perm));
}
}
return true;
}
return false;
}
private static Boolean permWhitelist(Player player) {
for (Map.Entry<String, PlayerObject> playerObject : PlayerCash.getPermissionHashMap().entrySet()){
if (playerObject.getValue().playerName.equals(player.getName())) return true;
if (playerObject.getValue().uuid.equals(player.getUniqueId().toString())) return true;
}
T2Csend.console(Language.exactKickReason.value.replace("[reason]", "Player UUID: " + player.getUniqueId().toString() + " not whitelisted (permissionWhitelist)"));
return false;
}
}

View File

@ -0,0 +1,29 @@
// This claas was created by JaTiTV
package net.t2code.opsecurity.check;
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 org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class Timer {
public static void refreshTimer() {
if (!(OPWhitelist.enable.valueBoolean && PermissionWhitelist.enable.valueBoolean)) return;
if (!Config.checkTimerEnable.valueBoolean) return;
Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getPlugin(), new Runnable() {
@Override
public void run() {
for (Player player : Bukkit.getOnlinePlayers()) {
OpCheck.onCheck(player, false);
PermissionCheck.onCheck(player, false);
}
}
}, 0, 20L * Config.checkTimerRefreshInSec.valueInt);
}
}

View File

@ -4,15 +4,15 @@ package net.t2code.opsecurity.command;
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.language.Language; import net.t2code.opsecurity.config.opWhitelist.OPWhitelist;
import net.t2code.opsecurity.system.Main;
import net.t2code.opsecurity.system.Permissions; import net.t2code.opsecurity.system.Permissions;
import net.t2code.t2codelib.SPIGOT.api.commands.T2Ctab;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -42,6 +42,11 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
case "version": case "version":
case "ver": case "ver":
Commands.info(sender); Commands.info(sender);
break;
case "test":
T2Csend.debugmsg(Main.getPlugin(), OPWhitelist.enable.valueBoolean.toString());
T2Csend.debugmsg(Main.getPlugin(), Config.onlyOPcanUseThePlugin.valueBoolean.toString());
break; break;
case "help": case "help":
default: default:
@ -61,63 +66,7 @@ public class CmdExecuter implements CommandExecutor, TabCompleter {
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) { public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
if (sender instanceof Player) { T2Ctab.tab(list,sender,0,args,arg1);
Player p = (Player) sender;
if (args.length == 1) {
for (String command : arg1.keySet()) {
Boolean passend = true;
for (int i = 0; i < args[0].length(); i++) {
if (args[0].length() >= command.length()) {
passend = false;
} else {
if (args[0].charAt(i) != command.charAt(i)) {
passend = false;
}
}
}
if (hasPermission(p, arg1.get(command)) && passend) {
list.add(command);
}
}
}
if (args.length == 2) {
switch (args[0]) {
case "give":
if (hasPermission(p, arg1.get("give"))) {
for (Player player : Bukkit.getOnlinePlayers()) {
Boolean passend = true;
for (int i = 0; i < args[1].length(); i++) {
if (args[1].length() >= player.getName().length()) {
passend = false;
} else {
if (args[1].charAt(i) != player.getName().charAt(i)) {
passend = false;
}
}
}
if (hasPermission(p, arg1.get(player)) && passend) {
list.add(player.getName());
}
}
}
break;
}
}
}
return list; return list;
} }
public static boolean hasPermission(Player player, String permission) {
if (player.isOp()) {
return true;
}
String[] Permissions = permission.split(";");
for (String perm : Permissions) {
if (player.hasPermission(perm)) {
return true;
}
}
return false;
}
} }

View File

@ -1,11 +1,14 @@
package net.t2code.opsecurity.command; package net.t2code.opsecurity.command;
import net.t2code.opsecurity.Util; import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.config.FileSelect;
import net.t2code.opsecurity.config.config.Config; 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.objects.PlayerCash; import net.t2code.opsecurity.objects.PlayerCash;
import net.t2code.opsecurity.system.Main;
import net.t2code.opsecurity.system.Permissions; import net.t2code.opsecurity.system.Permissions;
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 org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -49,21 +52,25 @@ public class Commands {
} }
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; Player player = (Player) sender;
if (!PlayerCash.opHashMap.containsKey(player.getName().toLowerCase())) { if (!PlayerCash.getOpHashMap().containsKey(player.getName().toLowerCase())) {
sender.sendMessage(Util.getPrefix() + " §4You are not on the Whitelist!"); sender.sendMessage(Util.getPrefix() + " §4You are not on the Whitelist!");
return; return;
} }
if (!PlayerCash.opHashMap.get(player.getName().toLowerCase()).UUID.equals(player.getUniqueId().toString().replace("-", ""))) { if (!PlayerCash.getOpHashMap().get(player.getName().toLowerCase()).uuid.equals(player.getUniqueId().toString().replace("-", ""))) {
sender.sendMessage(Util.getPrefix() + " §4You are not on the Whitelist!"); sender.sendMessage(Util.getPrefix() + " §4You are not on the Whitelist!");
return; return;
} }
T2Csend.player(player, Language.reloadStart.value); T2Csend.player(player, Language.reloadStart.value);
} }
if (sender instanceof Player) T2Csend.player((Player) sender, SelectMessages.ReloadEnd); if (sender instanceof Player) T2Csend.player((Player) sender, Language.reloadEnd.value);
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §6Plugin reload..."); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §6Plugin reload...");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------");
Load.loadReload(); // Load.onLoad(Main.getPlugin(),Main.getAutor(),Main.getVersion());
FileSelect.selectConfig();
FileSelect.selectLanguage();
FileSelect.selectOpWhitelist();
FileSelect.selectPermissionWhitelist();
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §2Plugin successfully reloaded."); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §2Plugin successfully reloaded.");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------"); Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + "§8-------------------------------");
@ -75,6 +82,6 @@ public class Commands {
sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7<" + Permissions.info + ">"); sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7<" + Permissions.info + ">");
return; return;
} }
T2CodeTemplate.sendInfo(sender, Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), Main.autor, Main.version, UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion); T2Ctemplate.sendInfo(sender,Main.getPlugin(),Util.getSpigotID(),Util.getDiscord(),Util.getInfoText());
} }
} }

View File

@ -4,12 +4,14 @@ import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.config.config.Config; 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.config.opWhitelist.OPWhitelist; 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.PlayerCash;
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.T2Creplace;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg; import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
import org.bukkit.Sound;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
@ -26,14 +28,14 @@ public class FileSelect {
if (!yamlConfiguration.contains(value.path)) { if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueString); yamlConfiguration.set(value.path, value.valueString);
} }
value.valueString = yamlConfiguration.getString(value.path); value.valueString = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getString(value.path));
break; break;
case SOUND: case SOUND:
if (!yamlConfiguration.contains(value.path)) { if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueString); yamlConfiguration.set(value.path, value.sound.toString());
} }
try { try {
value.valueString = yamlConfiguration.getString(value.path); value.sound = Sound.valueOf(yamlConfiguration.getString(value.path));
} catch (Exception ex) { } catch (Exception ex) {
T2Csend.console("§4\n§4\n§4\n" + SelectLibMsg.soundNotFound.replace("[prefix]", Util.getPrefix()) T2Csend.console("§4\n§4\n§4\n" + SelectLibMsg.soundNotFound.replace("[prefix]", Util.getPrefix())
.replace("[sound]", "§8" + value.path + ": §6" + yamlConfiguration.getString(value.path)) + "§4\n§4\n§4\n"); .replace("[sound]", "§8" + value.path + ": §6" + yamlConfiguration.getString(value.path)) + "§4\n§4\n§4\n");
@ -49,6 +51,7 @@ public class FileSelect {
if (!yamlConfiguration.contains(value.path)) { if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueInt); yamlConfiguration.set(value.path, value.valueInt);
} }
value.valueInt = yamlConfiguration.getInt(value.path); value.valueInt = yamlConfiguration.getInt(value.path);
break; break;
} }
@ -64,8 +67,7 @@ public class FileSelect {
public static void selectLanguage() { public static void selectLanguage() {
long long_ = System.currentTimeMillis(); long long_ = System.currentTimeMillis();
File directory = new File(Main.getPath(), "languages");
if (!directory.exists()) {
for (String language : defaultLanguages) { for (String language : defaultLanguages) {
File config = new File(Main.getPath(), "languages/" + language + ".yml"); File config = new File(Main.getPath(), "languages/" + language + ".yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
@ -81,17 +83,18 @@ public class FileSelect {
} }
} }
} }
T2Csend.debugmsg(Main.getPlugin(),"save: "+language); T2Csend.debug(Main.getPlugin(), "save: " + language);
try { try {
yamlConfiguration.save(config); yamlConfiguration.save(config);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
String selectMSG; String selectMSG;
File config = new File(Main.getPath(), "languages/" + Config.language + ".yml"); File config = new File(Main.getPath(), "languages/" + Config.language.valueString + ".yml");
T2Csend.debug(Main.getPlugin(), config.getAbsolutePath());
if (!config.isFile()) { if (!config.isFile()) {
T2Csend.console(Util.getPrefix()); T2Csend.console(Util.getPrefix());
T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
@ -99,13 +102,14 @@ public class FileSelect {
T2Csend.console(Util.getPrefix() + " §6The default language §eEnglish §6is used!"); T2Csend.console(Util.getPrefix() + " §6The default language §eEnglish §6is used!");
T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); T2Csend.console(Util.getPrefix() + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
T2Csend.console(Util.getPrefix()); T2Csend.console(Util.getPrefix());
config = new File(Main.getPath(), "languages/" + "english_messages.yml"); config = new File(Main.getPath(), "languages/" + "english.yml");
selectMSG = "english"; selectMSG = "english";
} else selectMSG = Config.language.valueString; } else selectMSG = Config.language.valueString;
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (Language value : Language.values()) { for (Language value : Language.values()) {
value.value = yamlConfiguration.getString(value.path); T2Csend.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"); T2Csend.console(Util.getPrefix() + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
} }
@ -125,7 +129,7 @@ public class FileSelect {
if (!yamlConfiguration.contains(value.path)) { if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueBoolean); yamlConfiguration.set(value.path, value.valueBoolean);
} }
value.valueStringList = yamlConfiguration.getStringList(value.path); value.valueStringList = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getStringList(value.path));
break; break;
case PLAYERLIST: case PLAYERLIST:
if (!yamlConfiguration.contains(value.pathPlayerListPath)) { if (!yamlConfiguration.contains(value.pathPlayerListPath)) {
@ -138,10 +142,9 @@ public class FileSelect {
PlayerObject playerObject = new PlayerObject( PlayerObject playerObject = new PlayerObject(
yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key)), yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key)),
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key).replace("-", ""))); yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key).replace("-", "")));
PlayerCash.opHashMap.put(key, playerObject); PlayerCash.getOpHashMap().put(key, playerObject);
} }
break; break;
} }
} }
try { try {
@ -154,7 +157,7 @@ public class FileSelect {
public static void selectPermissionWhitelist() { public static void selectPermissionWhitelist() {
File config = new File(Main.getPath(), "permissionWhitelist.yml"); File config = new File(Main.getPath(), "permissionWhitelist.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
for (OPWhitelist value : OPWhitelist.values()) { for (PermissionWhitelist value : PermissionWhitelist.values()) {
switch (value.cEnum) { switch (value.cEnum) {
case BOOLEAN: case BOOLEAN:
if (!yamlConfiguration.contains(value.path)) { if (!yamlConfiguration.contains(value.path)) {
@ -166,7 +169,7 @@ public class FileSelect {
if (!yamlConfiguration.contains(value.path)) { if (!yamlConfiguration.contains(value.path)) {
yamlConfiguration.set(value.path, value.valueBoolean); yamlConfiguration.set(value.path, value.valueBoolean);
} }
value.valueStringList = yamlConfiguration.getStringList(value.path); value.valueStringList = T2Creplace.replace(Util.getPrefix(), yamlConfiguration.getStringList(value.path));
break; break;
case PLAYERLIST: case PLAYERLIST:
if (!yamlConfiguration.contains(value.pathPlayerListPath)) { if (!yamlConfiguration.contains(value.pathPlayerListPath)) {
@ -179,7 +182,7 @@ public class FileSelect {
PlayerObject playerObject = new PlayerObject( PlayerObject playerObject = new PlayerObject(
yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key)), yamlConfiguration.getString(value.pathPlayerName.replace("KEY", key)),
yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key).replace("-", ""))); yamlConfiguration.getString(value.pathPlayerUuid.replace("KEY", key).replace("-", "")));
PlayerCash.opHashMap.put(key, playerObject); PlayerCash.getPermissionHashMap().put(key, playerObject);
} }
break; break;
} }
@ -190,6 +193,4 @@ public class FileSelect {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@ -1,28 +1,31 @@
package net.t2code.opsecurity.config.config; package net.t2code.opsecurity.config.config;
import net.t2code.opsecurity.config.ConfigParam; 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;
public enum Config { public enum Config {
language("Plugin.Language", "english", ConfigParam.STRING), language("plugin.language", "english", ConfigParam.STRING),
onlyOPcanUseThePlugin("Plugin.OnlyOPcanUseThePlugin", true, ConfigParam.BOOLEAN), onlyOPcanUseThePlugin("plugin.onlyOPcanUseThePlugin", true, ConfigParam.BOOLEAN),
checkOnJoin("Check.OnJoin", true, ConfigParam.BOOLEAN), checkOnJoin("check.onJoin", true, ConfigParam.BOOLEAN),
checkOnInteract("Check.OnInteract", true, ConfigParam.BOOLEAN), checkOnInteract("check.onInteract", true, ConfigParam.BOOLEAN),
checkOnCommand("Check.OnCommand", true, ConfigParam.BOOLEAN), checkOnCommand("check.onCommand", true, ConfigParam.BOOLEAN),
checkOnChat("Check.OnChat", true, ConfigParam.BOOLEAN), checkOnChat("check.onChat", 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),
kickCommand("Kick.Command", "minecraft:kick [player] [reason]", ConfigParam.STRING), kickCommand("kick.command", "minecraft:kick [player] [reason]", ConfigParam.STRING),
notifyJoinWarning("Notify.JoinWarn.Enable", true, ConfigParam.BOOLEAN), notifyJoinWarning("notify.joinWarn.enable", true, ConfigParam.BOOLEAN),
notifySoundEnable("Notify.SoundEnable", true, ConfigParam.BOOLEAN), notifyBungee("notify.allBungeePlayer.enable", false, ConfigParam.BOOLEAN),
notifySoundValue("Notify.SoundEnable", sound(), ConfigParam.SOUND); notifySoundEnable("notify.soundEnable", true, ConfigParam.BOOLEAN),
notifySoundValue("notify.sound", sound(), ConfigParam.SOUND);
public String path; public String path;
public String valueString; public String valueString;
public Integer valueInt; public Integer valueInt;
public Boolean valueBoolean; public Boolean valueBoolean;
public Sound sound;
public ConfigParam cEnum; public ConfigParam cEnum;
Config(String path, String value, ConfigParam cEnum) { Config(String path, String value, ConfigParam cEnum) {
@ -31,6 +34,12 @@ public enum Config {
this.cEnum = cEnum; this.cEnum = cEnum;
} }
Config(String path, Sound value, ConfigParam cEnum) {
this.path = path;
this.sound = value;
this.cEnum = cEnum;
}
Config(String path, Integer value, ConfigParam cEnum) { Config(String path, Integer value, ConfigParam cEnum) {
this.path = path; this.path = path;
this.valueInt = value; this.valueInt = value;
@ -42,12 +51,13 @@ public enum Config {
this.valueBoolean = value; this.valueBoolean = value;
this.cEnum = cEnum; this.cEnum = cEnum;
} }
public static String sound(){
if (T2CmcVersion.isMc1_8()){ public static Sound sound() {
return "NOTE_PIANO"; if (T2CmcVersion.isMc1_8()) {
} else if (T2CmcVersion.isMc1_9()||T2CmcVersion.isMc1_10()||T2CmcVersion.isMc1_11()||T2CmcVersion.isMc1_12()){ return Sound.valueOf("NOTE_PIANO");
return "BLOCK_NOTE_HARP"; } else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
} else return "BLOCK_NOTE_BLOCK_HARP"; return Sound.valueOf("BLOCK_NOTE_HARP");
} else return Sound.valueOf("BLOCK_NOTE_BLOCK_HARP");
} }
} }

View File

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

View File

@ -13,7 +13,7 @@ public enum Language {
"[prefix] <red>Du hast keine Berechtigung für OPSecurity!</red>", "[prefix] <red>Du hast keine Berechtigung für OPSecurity!</red>",
"[prefix] <red>You do not have permission for OPSecurity!</red>"), "[prefix] <red>You do not have permission for OPSecurity!</red>"),
PlayerMustBeOnlineToOp("plugin.PlayerMustBeOnlineToOp",null, playerMustBeOnlineToOp("plugin.PlayerMustBeOnlineToOp",null,
"[prefix] <dark_red>Der Spieler muss online sein, um OP zu erhalten!</dark_red>", "[prefix] <dark_red>Der Spieler muss online sein, um OP zu erhalten!</dark_red>",
"[prefix] <dark_red>Player must be online to get op!</dark_red>"), "[prefix] <dark_red>Player must be online to get op!</dark_red>"),
@ -29,38 +29,37 @@ public enum Language {
"[prefix] <dark_red>Der angegebene Spieler befindet sich nicht auf der OP_Whitelist!</dark_red>", "[prefix] <dark_red>Der angegebene Spieler befindet sich nicht auf der OP_Whitelist!</dark_red>",
"[prefix] <dark_red>The specified player is not on the OP_Whitelist!</dark_red>"), "[prefix] <dark_red>The specified player is not on the OP_Whitelist!</dark_red>"),
opWhitelistConsoleOnJoin("opWhitelist.consoleOnJoin",null, opWhitelistNotifyOnJoin("opWhitelist.notify.onJoin",null,
"[prefix] <dark_red>Spieler <gold>[player]</gold> ist dem Server beigetreten, befindet sich aber nicht auf der OP_Whitelist!</dark_red>", "[prefix] <dark_red>Spieler <gold>[player]</gold> ist dem Server beigetreten, befindet sich aber nicht auf der OP_Whitelist!</dark_red>",
"[prefix] <dark_red>Player <gold>[player]</gold> is joined to the server but is not on the OP_Whitelist!</dark_red>"), "[prefix] <dark_red>Player <gold>[player]</gold> is joined to the server but is not on the OP_Whitelist!</dark_red>"),
opWhitelistNotifyDeop("opWhitelist.notify.deop",null,
"[prefix] <dark_red>Spieler <gold>[player]</gold> wurde OP entfernt da er nicht auf der Spielerliste steht!</dark_red>",
"[prefix] <dark_red>Player <gold>[player]</gold> was removed OP because he is not on the playerlist!</dark_red>"),
opWhitelistNotifyKick("opWhitelist.notify.kick",null,
"[prefix] <dark_red>Spieler <gold>[player]</gold> wurde gekickt, da er nicht auf der OP_Whitelist steht!</dark_red>",
"[prefix] <dark_red>Player <gold>[player]</gold> was kicked because he is not on the OP_Whitelist!</dark_red>"),
opWhitelistDeop("opWhitelist.deop",null, opWhitelistDeop("opWhitelist.deop",null,
"[prefix] <dark_red>Dir wurde OP entfernt da du dazu keine Permission besitzt.</dark_red>", "[prefix] <dark_red>Dir wurde OP entfernt da du dazu keine Permission besitzt.</dark_red>",
"[prefix] <dark_red>You have been removed from OP because you do not have permission.</dark_red>"), "[prefix] <dark_red>You have been removed from OP because you do not have permission.</dark_red>"),
opWhitelistConsoleDeop("opWhitelist.consoleDeop",null,
"[prefix] <dark_red>Spieler <gold>[player]</gold> wurde OP entfernt da er nicht auf der Spielerliste steht!</dark_red>",
"[prefix] <dark_red>Player <gold>[player]</gold> was removed OP because he is not on the playerlist!</dark_red>"),
opWhitelistKick("opWhitelist.kick",null, opWhitelistKick("opWhitelist.kick",null,
"<dark_red>Du hast op bist dazu aber nicht berechtigt, deswegen wurdest du gekickt!</dark_red>", "<dark_red>Du hast op bist dazu aber nicht berechtigt, deswegen wurdest du gekickt!</dark_red>",
"<dark_red>You have op but are not authorized to do so, that's why you were kicked!</dark_red>"), "<dark_red>You have op but are not authorized to do so, that's why you were kicked!</dark_red>"),
opWhitelistConsoleKick("opWhitelist.consoleKick",null, permissionWhitelistNotifyOnJoin("permissionWhitelist.notify.onJoin",null,
"[prefix] <dark_red>Spieler <gold>[player]</gold> wurde gekickt, da er nicht auf der OP_Whitelist steht!</dark_red>",
"[prefix] <dark_red>Player <gold>[player]</gold> was kicked because he is not on the OP_Whitelist!</dark_red>"),
permissionWhitelistConsoleOnJoin("permissionWhitelist.consoleOnJoin",null,
"[prefix] <dark_red>Player <gold>[player]</gold> hat die Permission <gold>[perm]</gold> und ist dazu nicht berechtigt! <gold>[player]</gold> ist nicht in der Spielerliste!</dark_red>", "[prefix] <dark_red>Player <gold>[player]</gold> hat die Permission <gold>[perm]</gold> und ist dazu nicht berechtigt! <gold>[player]</gold> ist nicht in der Spielerliste!</dark_red>",
"[prefix] <dark_red>Player <gold>[player]</gold> has permission <gold>[perm]</gold> and is not authorized to do so! <gold>[player]</gold> is not on the Player list!</dark_red>"), "[prefix] <dark_red>Player <gold>[player]</gold> has permission <gold>[perm]</gold> and is not authorized to do so! <gold>[player]</gold> is not on the Player list!</dark_red>"),
permissionWhitelistNotifyKick("permissionWhitelist.notify.kick",null,
"[prefix] <dark_red>Spieler <gold>[player]</gold> hat die Permission <gold>[perm]</gold> und ist dazu nicht berechtigt! Daher wurde er gekickt! <gold>[player]</gold> ist nicht in der Spielerliste!</dark_red>",
"[prefix] <dark_red>Player <gold>[player]</gold> has permission <gold>[perm]</gold> and is not authorized to do so! Therefore he was kicked! <gold>[player]</gold> is not on the Player list!</dark_red>"),
permissionWhitelistKick("permissionWhitelist.kick",null, permissionWhitelistKick("permissionWhitelist.kick",null,
"<dark_red>Du wurdest gekickt, da du Permissions besitzt, für die du keine Berechtigung besitzt!</dark_red>", "<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>"), "<dark_red>You were kicked because you have permissions to which you do not have permission!</dark_red>"),
permissionWhitelistConsoleKick("permissionWhitelist.consoleKick",null,
"[prefix] <dark_red>Spieler <gold>[player]</gold> hat die Permission <gold>[perm]</gold> und ist dazu nicht berechtigt! Daher wurde er gekickt! <gold>[player]</gold> ist nicht in der Spielerliste!</dark_red>",
"[prefix] <dark_red>Player <gold>[player]</gold> has permission <gold>[perm]</gold> and is not authorized to do so! Therefore he was kicked! <gold>[player]</gold> is not on the Player list!</dark_red>"),
exactKickReason("console.exactKickReason", null, exactKickReason("console.exactKickReason", null,
"[prefix] <dark_red>Genauer Grund:</dark_red> <gold>[reason]</gold>", "[prefix] <dark_red>Genauer Grund:</dark_red> <gold>[reason]</gold>",
"[prefix] <dark_red>Exact reason:</dark_red> <gold>[reason]</gold>"); "[prefix] <dark_red>Exact reason:</dark_red> <gold>[reason]</gold>");

View File

@ -1,6 +1,6 @@
package net.t2code.opsecurity.config.opWhitelist; package net.t2code.opsecurity.config.opWhitelist;
import net.t2code.opsecurity.config.ConfigParam; import net.t2code.opsecurity.enums.ConfigParam;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -23,6 +23,7 @@ public enum OPWhitelist {
public String valuePlayerName; public String valuePlayerName;
public String valuePlayerUuid; public String valuePlayerUuid;
public List<String> valueStringList; public List<String> valueStringList;
public Boolean valueBoolean; public Boolean valueBoolean;
public ConfigParam cEnum; public ConfigParam cEnum;

View File

@ -1,6 +1,6 @@
package net.t2code.opsecurity.config.permissionWhitelist; package net.t2code.opsecurity.config.permissionWhitelist;
import net.t2code.opsecurity.config.ConfigParam; import net.t2code.opsecurity.enums.ConfigParam;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package net.t2code.opsecurity.config; package net.t2code.opsecurity.enums;
public enum ConfigParam { public enum ConfigParam {
STRING, STRING,

View File

@ -0,0 +1,7 @@
package net.t2code.opsecurity.enums;
public enum OpCommandRequest {
ok,
mustOnline,
notWhitelisted
}

View File

@ -0,0 +1,83 @@
package net.t2code.opsecurity.events;
import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.config.config.Config;
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.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.*;
public class Events implements Listener {
public static void notifyPlayer(String msg) {
if (!Config.notifyJoinWarning.valueBoolean) return;
for (Player notifyPlayer : Bukkit.getOnlinePlayers()) {
if (!notifyPlayer.hasPermission(Permissions.notify)) continue;
T2Csend.player(notifyPlayer, msg);
if (Config.notifySoundEnable.valueBoolean) notifyPlayer.playSound(notifyPlayer.getLocation(), Config.notifySoundValue.sound, 3, 1);
}
}
@EventHandler
public void CommandSendEvent(PlayerCommandPreprocessEvent event) {
if (!Config.checkOnCommand.valueBoolean) return;
Player player = event.getPlayer();
T2Csend.debugmsg(Main.getPlugin(), "1 "+ OpCheck.onCheck(player,false));
T2Csend.debugmsg(Main.getPlugin(), "1 "+ PermissionCheck.onCheck(player,false));
if (OpCheck.onCheck(player, false) || PermissionCheck.onCheck(player, false)) {
if (event.isCancelled()) return;
event.setCancelled(true);
}
}
@EventHandler
public void PlayerChatEvent(PlayerChatEvent event) {
if (!Config.checkOnChat.valueBoolean) return;
Player player = event.getPlayer();
T2Csend.debugmsg(Main.getPlugin(), "2 "+OpCheck.onCheck(player,false));
T2Csend.debugmsg(Main.getPlugin(), "2 "+PermissionCheck.onCheck(player,false));
if (OpCheck.onCheck(player, false) || PermissionCheck.onCheck(player, false)) {
if (event.isCancelled()) return;
event.setCancelled(true);
}
}
@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)) {
event.setCancelled(true);
}
}
}, 1L);
}
@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);
}
}, 1L);
}
@EventHandler
public void onJoinEvent(PlayerLoginEvent event) {
Player player = event.getPlayer();
T2CupdateAPI.join(Main.getPlugin(), Util.getPrefix(), Permissions.updatemsg, player, Util.getSpigotID(), Util.getDiscord());
}
}

View File

@ -0,0 +1,76 @@
package net.t2code.opsecurity.events;
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.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.player.T2CnameHistory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import java.io.IOException;
public class OpCommand implements Listener {
@EventHandler
public void onOPServer(ServerCommandEvent event) {
if (!OPWhitelist.enable.valueBoolean) return;
if ((event.getCommand().toLowerCase().startsWith("op ") || event.getCommand().toLowerCase().startsWith("minecraft:op "))) {
switch (isNotOPWTL(event.getCommand())) {
case mustOnline:
T2Csend.sender(event.getSender(), Language.playerMustBeOnlineToOp.value);
event.setCancelled(true);
break;
case notWhitelisted:
T2Csend.sender(event.getSender(), Language.opWhitelistOpCommand.value);
event.setCancelled(true);
break;
}
}
}
@EventHandler
public void onOpPlayer(PlayerCommandPreprocessEvent event) {
if (!OPWhitelist.enable.valueBoolean) return;
if ((event.getMessage().toLowerCase().startsWith("/op ") || event.getMessage().toLowerCase().startsWith("/minecraft:op "))) {
switch (isNotOPWTL(event.getMessage())) {
case mustOnline:
T2Csend.player(event.getPlayer(), Language.playerMustBeOnlineToOp.value);
event.setCancelled(true);
break;
case notWhitelisted:
T2Csend.player(event.getPlayer(), Language.opWhitelistOpCommand.value);
event.setCancelled(true);
break;
}
}
}
private OpCommandRequest isNotOPWTL(String command) {
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 (!PlayerCash.getOpHashMap().get(target.getName()).playerName.equals(target.getName())) return OpCommandRequest.notWhitelisted;
if (!PlayerCash.getOpHashMap().get(target.getName()).uuid.equals(target.getUniqueId().toString().replace("-", ""))) return OpCommandRequest.notWhitelisted;
}
String targetUUID;
if (target != null) {
targetUUID = target.getUniqueId().toString();
} else {
try {
targetUUID = T2CnameHistory.NameLookup.getPlayerUUID(arg);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (!PlayerCash.getOpHashMap().get(target.getName()).playerName.equals(arg)) return OpCommandRequest.notWhitelisted;
if (!PlayerCash.getOpHashMap().get(target.getName()).uuid.equals(targetUUID.replace("-", ""))) return OpCommandRequest.notWhitelisted;
return OpCommandRequest.ok;
}
}

View File

@ -0,0 +1,38 @@
// This claas was created by JaTiTV
package net.t2code.opsecurity.events;
import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
public class PlugManCommand implements Listener {
@EventHandler
public void onOPServer(ServerCommandEvent event) {
if ((event.getCommand().toLowerCase().contains("plugman disable") && event.getCommand().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase()))
|| (event.getCommand().toLowerCase().contains("plugman reload") && event.getCommand().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase()))
|| (event.getCommand().toLowerCase().contains("plugman unload") && event.getCommand().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase()))
|| (event.getCommand().toLowerCase().contains("plugman restart") && event.getCommand().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase()))
) {
event.setCancelled(true);
T2Csend.console(Util.getPrefix() + " §4OPSecurity cannot be deactivated!");
}
}
@EventHandler
public void onOpPlayer(PlayerCommandPreprocessEvent event) {
if (event.getMessage().toLowerCase().startsWith("/plugman disable") && event.getMessage().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase())
|| (event.getMessage().toLowerCase().startsWith("/plugman reload") && event.getMessage().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase()))
|| (event.getMessage().toLowerCase().startsWith("/plugman unload") && event.getMessage().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase()))
|| (event.getMessage().toLowerCase().startsWith("/plugman restart") && event.getMessage().toLowerCase().contains(Main.getPlugin().getDescription().getName().toLowerCase()))
) {
event.setCancelled(true);
T2Csend.player(event.getPlayer(), Util.getPrefix() + " §4OPSecurity cannot be deactivated!");
}
}
}

View File

@ -1,8 +1,12 @@
package net.t2code.opsecurity.objects; package net.t2code.opsecurity.objects;
import lombok.Getter;
import java.util.HashMap; import java.util.HashMap;
public class PlayerCash { public class PlayerCash {
public static HashMap<String, PlayerObject> opHashMap = new HashMap<String, PlayerObject>(); @Getter
public static HashMap<String, PlayerObject> permissionHashMap = new HashMap<String, PlayerObject>(); private static HashMap<String, PlayerObject> opHashMap = new HashMap<String, PlayerObject>();
@Getter
private static HashMap<String, PlayerObject> permissionHashMap = new HashMap<String, PlayerObject>();
} }

View File

@ -1,7 +1,5 @@
package net.t2code.opsecurity.objects; package net.t2code.opsecurity.objects;
import java.util.UUID;
public class PlayerObject { public class PlayerObject {
public String playerName; public String playerName;
public String uuid; public String uuid;

View File

@ -0,0 +1,41 @@
package net.t2code.opsecurity.system;
import net.t2code.opsecurity.events.Events;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.io.*;
public class BungeeSenderReceiver implements PluginMessageListener {
public static void sendToBungee(String information) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(stream);
try {
output.writeUTF(information.toString());
} catch (IOException e) {
e.printStackTrace();
}
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendPluginMessage(Main.getPlugin(), "t2c:opsec", stream.toByteArray());
return;
}
}
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(message));
T2Csend.debug(Main.getPlugin(), "stream: " + stream.toString());
try {
String subChannel = stream.readUTF();
String information = stream.readUTF();
if (subChannel.equals("T2Cconsole")) {
Events.notifyPlayer(information);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,12 +1,15 @@
package net.t2code.opsecurity.system; package net.t2code.opsecurity.system;
import net.t2code.opsecurity.Util; import net.t2code.opsecurity.Util;
import net.t2code.opsecurity.command.CmdExecuter;
import net.t2code.opsecurity.config.FileSelect; import net.t2code.opsecurity.config.FileSelect;
import net.t2code.opsecurity.config.config.Converter; import net.t2code.opsecurity.config.config.Converter;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; 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.T2Ctemplate; import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck; import net.t2code.t2codelib.SPIGOT.api.register.T2Cregister;
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginManager;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI; import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import java.util.List; import java.util.List;
@ -16,25 +19,25 @@ public class Load {
public static void onLoad(Main plugin, List<String> autor, String version) { public static void onLoad(Main plugin, List<String> autor, String version) {
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord()); long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
if (T2CpluginCheck.opSec()){
T2CpluginManager.disable("OPSecurity");
T2Csend.warning(plugin,"OPSecurity has been deactivated, because T2C-OPSecurity is a newer version!");
}
try { try {
Converter.convert(); Converter.convert();
} catch (Exception ex){ } catch (Exception ex) {
plugin.getLogger().log(Level.SEVERE,ex.getMessage()); plugin.getLogger().log(Level.SEVERE, ex.getMessage());
ex.printStackTrace(); ex.printStackTrace();
} }
FileSelect.selectConfig(); FileSelect.selectConfig();
FileSelect.selectLanguage(); FileSelect.selectLanguage();
FileSelect.selectOpWhitelist(); FileSelect.selectOpWhitelist();
FileSelect.selectPermissionWhitelist(); FileSelect.selectPermissionWhitelist();
//plugin.getCommand("t2c-opsecurity").setExecutor(new CmdExecuter()); plugin.getCommand("t2c-opsecurity").setExecutor(new CmdExecuter());
T2Cregister.listener(new OpCommand(), plugin);
T2Cregister.listener(new PlugManCommand(), plugin);
T2Cregister.listener(new Events(), plugin);
Timer.refreshTimer();
Permissions.register(); Permissions.register();
T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(), Util.getSpigotID(), Util.getDiscord()); T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(), Util.getSpigotID(), Util.getDiscord());
Metrics.Bstats(plugin, Util.getBstatsID()); Metrics.Bstats(plugin, Util.getBstatsID());

View File

@ -42,7 +42,7 @@ public final class Main extends JavaPlugin {
if (t2codeLib) T2Ctemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord()); if (t2codeLib) T2Ctemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
} }
public static Boolean pluginNotFound(String pl, Integer spigotID, String ver) { private static Boolean pluginNotFound(String pl, Integer spigotID, String ver) {
if (Bukkit.getPluginManager().getPlugin(pl) == null) { if (Bukkit.getPluginManager().getPlugin(pl) == null) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!"); plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: " Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: "

View File

@ -1,19 +0,0 @@
Plugin:
Language: english
OnlyOPcanUseThePlugin: true
Check:
OnJoin: true
OnInteract: true
OnCommand: true
OnChat: true
Timer:
Enable: true
RefreshInSec: 60
Kick:
Command: minecraft:kick [player] [reason]
Notify:
JoinWarn:
Enable: true
Sound:
Enable: true
Sound: BLOCK_NOTE_BLOCK_HARP

View File

@ -1,20 +0,0 @@
opWhitelist:
enable: false
playerMustBeOnlineToOp: true
noOpPlayerDeop:
enable: true
playerSendMessage: true
noOpPlayerKick:
enable: true
customCommands:
enable: false
commands:
- kick [player] &4You have op but are not authorized to do so, that's why you
were kicked!
whitelist:
player1:
name: 'PlayerName'
uuid: '00000000000000000000000000000000'
player2:
name: 'PlayerName'
uuid: '00000000000000000000000000000000'

View File

@ -1,18 +0,0 @@
permissionWhitelist:
enable: false
playerWithPermissionKick: true
permissions:
- '*'
- opsecurity.admin
customCommands:
enable: false
commands:
- lp user [player] permission unset *
- lp user [player] permission unset opsecurity.admin
whitelist:
player1:
name: 'PlayerName'
uuid: '00000000000000000000000000000000'
player2:
name: 'PlayerName'
uuid: '00000000000000000000000000000000'

View File

@ -1,4 +1,5 @@
name: T2C-OPSecurity name: T2C-OPSecurity
provides: [OPSecurity]
version: '${project.version}' version: '${project.version}'
main: net.t2code.opsecurity.system.Main main: net.t2code.opsecurity.system.Main
api-version: 1.13 api-version: 1.13