From 5d72e0d48d9be12ad9a8b01b6b63dc5d5b6f5bdf Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Sat, 15 Jun 2024 18:47:17 +0200 Subject: [PATCH] 1.5 New features: - The option "CooldownInSec.Global" has been added to give an alias a global cooldown that counts for all players. - The option "CooldownInSec.Player" has been added to give an alias a cooldown that counts for a single player. The permissions have been revised: - t2code.alias.admin -> t2c.alias.admin - t2code.alias.updatemsg -> t2c.alias.updatemsg - t2code.alias.command.reload -> t2c.alias.command.reload - t2code.alias.command.info -> t2c.alias.command.info - t2code.alias.buy.bypass -> t2c.alias.buy.all.bypass - The bypass for payment can now also be set individually for each alias / subalias: t2c.alias.buy.[alias].bypass / t2c.alias.sub.buy.all.bypass --- README.md | 8 +- pom.xml | 3 + .../cmdManagement/AliasCmdExecuter.java | 18 ++--- .../Spigot/cmdManagement/ExecuteAlias.java | 75 ++++++++++++++++--- .../alias/Spigot/cmdManagement/TabEvent.java | 2 +- .../config/alias/AliasConfigConverter.java | 25 ++++++- .../alias/CreateExampleAliasConfig.java | 8 +- .../Spigot/config/alias/SelectAlias.java | 12 ++- .../alias/Spigot/config/config/Config.java | 1 - .../alias/Spigot/config/config/Language.java | 4 + .../subAlias/CreateExampleSubAliasConfig.java | 7 +- .../config/subAlias/SelectSubAlias.java | 13 +++- .../alias/Spigot/objects/AliasObject.java | 6 ++ .../alias/Spigot/objects/SubAliasObject.java | 5 ++ .../system/AliasRegisterPermissions.java | 35 +++++++-- .../alias/Spigot/system/PluginEvents.java | 2 +- .../resources/Alias/X_aliasDeclaration_X.yml | 42 ++++++++--- .../SubAlias/X_subAliasDeclaration_X.yml | 29 +++++-- src/main/resources/X_configDeclaration_X.yml | 2 +- src/main/resources/plugin.yml | 37 ++++++--- 20 files changed, 263 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 6b6cc60..d944609 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,14 @@ WebUI: https://webui.adventure.kyori.net **/t2code-alias** | **/alias** -**/alias info** - Open the T2C-Alias info. | *t2code.alias.command.info* +**/alias info** - Open the T2C-Alias info. | *t2c.alias.command.info* -**/alias reload** - Reload the plugin. | *t2code.alias.command.reload* +**/alias reload** - Reload the plugin. | *t2c.alias.command.reload* -*t2code.alias.admin* - Permission for all T2C-Alias Commands +*t2c.alias.admin* - Permission for all T2C-Alias Commands -*t2code.alias.updatemsg* - Get a notification when an update is available when joining +*t2c.alias.updatemsg* - Get a notification when an update is available when joining --- diff --git a/pom.xml b/pom.xml index 4abfa2d..abb1feb 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,9 @@ Alias 1.5 + + + jar T2C-Alias diff --git a/src/main/java/net/t2code/alias/Spigot/cmdManagement/AliasCmdExecuter.java b/src/main/java/net/t2code/alias/Spigot/cmdManagement/AliasCmdExecuter.java index 4d7cd17..a3a1cb1 100644 --- a/src/main/java/net/t2code/alias/Spigot/cmdManagement/AliasCmdExecuter.java +++ b/src/main/java/net/t2code/alias/Spigot/cmdManagement/AliasCmdExecuter.java @@ -23,18 +23,18 @@ public class AliasCmdExecuter implements CommandExecutor, TabCompleter { if (args.length == 0) { // Command - if (sender.hasPermission("t2code.alias.command.info")) { + if (sender.hasPermission("t2c.alias.command.info")) { Commands.info(sender); } else T2Csend.sender(sender, Language.noPermission.value.replace("[cmd]", "/t2code-alias info") - .replace("[perm]", "t2code.alias.command.info")); + .replace("[perm]", "t2c.alias.command.info")); } else { switch (args[0].toLowerCase()) { case "reload": case "rl": - if (sender.hasPermission("t2code.alias.command.reload") || sender.isOp()) { + if (sender.hasPermission("t2c.alias.command.reload") || sender.isOp()) { Commands.reload(sender); } else T2Csend.sender(sender, Language.noPermission.value.replace("[cmd]", "/t2code-alias reload") - .replace("[perm]", "t2code.alias.command.reload")); + .replace("[perm]", "t2c.alias.command.reload")); break; case "confirm": if (Config.buyConfirmDefault.value == Confirm.COMMAND) ExecuteAlias.storage(sender, true); @@ -45,10 +45,10 @@ public class AliasCmdExecuter implements CommandExecutor, TabCompleter { case "info": case "plugin": case "version": - if (sender.hasPermission("t2code.alias.command.info")) { + if (sender.hasPermission("t2c.alias.command.info")) { Commands.info(sender); } else T2Csend.sender(sender, Language.noPermission.value.replace("[cmd]", "/t2code-alias info") - .replace("[perm]", "t2code.alias.command.info")); + .replace("[perm]", "t2c.alias.command.info")); break; } @@ -58,9 +58,9 @@ public class AliasCmdExecuter implements CommandExecutor, TabCompleter { //TabCompleter private static HashMap arg1 = new HashMap() {{ - put("reload", "t2code.alias.command.reload"); - put("rl", "t2code.alias.command.reload"); - put("info", "t2code.alias.command.info"); + put("reload", "t2c.alias.command.reload"); + put("rl", "t2c.alias.command.reload"); + put("info", "t2c.alias.command.info"); }}; @Override diff --git a/src/main/java/net/t2code/alias/Spigot/cmdManagement/ExecuteAlias.java b/src/main/java/net/t2code/alias/Spigot/cmdManagement/ExecuteAlias.java index bcffa54..fc54710 100644 --- a/src/main/java/net/t2code/alias/Spigot/cmdManagement/ExecuteAlias.java +++ b/src/main/java/net/t2code/alias/Spigot/cmdManagement/ExecuteAlias.java @@ -52,7 +52,7 @@ public class ExecuteAlias { Player player = (Player) sender; if (aliasObject.adminEnable) { - if (player.hasPermission(aliasObject.adminPermission.replace("", alias.toLowerCase()))) { + if (player.hasPermission(aliasObject.adminPermission.replace("[alias]", alias.toLowerCase()))) { if (aliasObject.adminCommandEnable) { aliasAdminCommand(aliasObject, alias, player, args); } @@ -64,18 +64,18 @@ public class ExecuteAlias { } if (aliasObject.permNecessary) { - if (!(player.hasPermission(aliasObject.permission.replace("", alias.toLowerCase())) || player.hasPermission("t2code.alias.admin"))) { + if (!(player.hasPermission(aliasObject.permission.replace("[alias]", alias.toLowerCase())) || player.hasPermission("t2c.alias.admin"))) { String npmsg; if (aliasObject.permissionMSG == null || aliasObject.permissionMSG.equals("")) { npmsg = Language.noPermission.value; } else npmsg = aliasObject.permissionMSG; T2Csend.player(player, npmsg.replace("[cmd]", "/" + alias.toLowerCase()) - .replace("[perm]", aliasObject.permission.replace("", alias.toLowerCase())).replace("[alias]", alias)); + .replace("[perm]", aliasObject.permission.replace("[alias]", alias.toLowerCase())).replace("[alias]", alias)); return; } } if (aliasObject.costEnable && aliasObject.costConfirm) { - if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) { + if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy." + alias.toLowerCase() + ".bypass"))) { Cache.aliasStorage.put(player.getUniqueId(), new AliasStorageObject(aliasObject, alias, args, false)); switch ((Confirm) Config.buyConfirmDefault.value) { case GUI: @@ -99,8 +99,35 @@ public class ExecuteAlias { } protected static void executeAlias(Player player, AliasObject aliasObject, String alias, String[] args) { + if (aliasObject.cooldownGlobal != 0) { + if (!(player.hasPermission("t2code.alias.cooldown.global." + alias.toLowerCase() + ".bypass") && player.hasPermission("t2c.alias.cooldown.global.all.bypass"))) { + if (aliasObject.globalCooldownInt != 0) { + Long duration = System.currentTimeMillis() - aliasObject.globalCooldownInt; + if (!(duration > (aliasObject.cooldownGlobal * 1000))) { + T2Csend.player(player, Language.cooldownGlobal.value.replace("[cooldown]", String.valueOf(aliasObject.cooldownGlobal - (int) (duration / 1000)))); + return; + + } + } + aliasObject.globalCooldownInt = System.currentTimeMillis(); + } + } + + if (aliasObject.cooldownPlayer != 0) { + if (!(player.hasPermission("t2code.alias.cooldown.player." + alias.toLowerCase() + ".bypass") && player.hasPermission("t2c.alias.cooldown.player.all.bypass"))) { + Long cooldown = aliasObject.cooldownPlayerMap.get(player.getUniqueId()); + if (cooldown != null) { + Long duration = System.currentTimeMillis() - cooldown; + if (!(duration > (aliasObject.cooldownPlayer * 1000))) { + T2Csend.player(player, Language.cooldownPlayer.value.replace("[cooldown]", String.valueOf(aliasObject.cooldownPlayer - (int) (duration / 1000)))); + return; + } + } + aliasObject.cooldownPlayerMap.put(player.getUniqueId(), System.currentTimeMillis()); + } + } if (aliasObject.costEnable) { - if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) { + if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy." + alias.toLowerCase() + ".bypass") && player.hasPermission("t2c.alias.buy.all.bypass"))) { if (!T2Ceco.moneyRemove(prefix, player, aliasObject.costPrice)) { T2Csend.player(player, Language.noMoney.value); return; @@ -109,6 +136,7 @@ public class ExecuteAlias { T2Csend.player(player, Language.buy.value.replace("[price]", aliasObject.costPrice.toString() + " " + Config.buyCurrency.value)); } } + if (aliasObject.commandEnable) { aliasCommand(aliasObject, alias, player, args); } @@ -127,7 +155,7 @@ public class ExecuteAlias { Player player = (Player) sender; if (aliasObject.adminEnable) { - if (player.hasPermission(aliasObject.adminPermission.replace("", alias.toLowerCase()))){ + if (player.hasPermission(aliasObject.adminPermission.replace("[alias]", alias.toLowerCase()))) { if (aliasObject.adminCommandEnable) { subAliasAdminCommand(aliasObject, alias, player, args); } @@ -139,13 +167,13 @@ public class ExecuteAlias { } if (aliasObject.permNecessary) { - if (!(player.hasPermission(aliasObject.permission.replace("", alias.toLowerCase())) || player.hasPermission("t2code.alias.admin"))) { + if (!(player.hasPermission(aliasObject.permission.replace("[alias]", alias.toLowerCase())) || player.hasPermission("t2code.alias.admin"))) { String npmsg; if (aliasObject.permissionMSG == null || aliasObject.permissionMSG.equals("")) { npmsg = Language.noPermission.value; } else npmsg = aliasObject.permissionMSG; T2Csend.player(player, npmsg.replace("[cmd]", "/" + alias.toLowerCase()) - .replace("[perm]", aliasObject.permission.replace("", alias.toLowerCase())).replace("[alias]", alias)); + .replace("[perm]", aliasObject.permission.replace("[alias]", alias.toLowerCase())).replace("[alias]", alias)); return; } } @@ -179,8 +207,37 @@ public class ExecuteAlias { } protected static void executeSubAlias(Player player, SubAliasObject aliasObject, String alias, String[] args) { + + if (aliasObject.cooldownGlobal != 0) { + if (!(player.hasPermission("t2c.alias.sub.cooldown.global." + alias.toLowerCase() + ".bypass") && player.hasPermission("t2c.alias.sub.cooldown.global.all.bypass"))) { + if (aliasObject.globalCooldownInt != 0) { + Long duration = System.currentTimeMillis() - aliasObject.globalCooldownInt; + if (!(duration > (aliasObject.cooldownGlobal * 1000))) { + T2Csend.player(player, Language.cooldownGlobal.value.replace("[cooldown]", String.valueOf(aliasObject.cooldownGlobal - (int) (duration / 1000)))); + return; + } + } + aliasObject.globalCooldownInt = System.currentTimeMillis(); + } + } + + if (aliasObject.cooldownPlayer != 0) { + if (!(player.hasPermission("t2c.alias.sub.cooldown.player." + alias.toLowerCase() + ".bypass") && player.hasPermission("t2c.alias.sub.cooldown.player.all.bypass"))) { + Long cooldown = aliasObject.cooldownPlayerMap.get(player.getUniqueId()); + if (cooldown != null) { + Long duration = System.currentTimeMillis() - cooldown; + if (!(duration > (aliasObject.cooldownPlayer * 1000))) { + T2Csend.player(player, Language.cooldownPlayer.value.replace("[cooldown]", String.valueOf(aliasObject.cooldownPlayer - (int) (duration / 1000)))); + return; + } + } + aliasObject.cooldownPlayerMap.put(player.getUniqueId(), System.currentTimeMillis()); + } + } + + if (aliasObject.costEnable) { - if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) { + if (!(aliasObject.costAllowBypass && player.hasPermission("t2c.alias.sub.buy." + alias.toLowerCase() + ".bypass") && player.hasPermission("t2c.alias.sub.buy.all.bypass"))) { if (!T2Ceco.moneyRemove(prefix, player, aliasObject.costPrice)) { T2Csend.player(player, Language.noMoney.value); return; diff --git a/src/main/java/net/t2code/alias/Spigot/cmdManagement/TabEvent.java b/src/main/java/net/t2code/alias/Spigot/cmdManagement/TabEvent.java index e01dfd4..e6af560 100644 --- a/src/main/java/net/t2code/alias/Spigot/cmdManagement/TabEvent.java +++ b/src/main/java/net/t2code/alias/Spigot/cmdManagement/TabEvent.java @@ -31,7 +31,7 @@ public class TabEvent implements Listener { String[] args = input.split(" ", -1); for (String al : aliasObject.subAliasList) { - arg1.put(al, aliasObject.permission.replace("", al.toLowerCase())); + arg1.put(al, aliasObject.permission.replace("[alias]", al.toLowerCase())); } int arg = aliasObject.subAliasArg; if (args.length - 1 == arg) { diff --git a/src/main/java/net/t2code/alias/Spigot/config/alias/AliasConfigConverter.java b/src/main/java/net/t2code/alias/Spigot/config/alias/AliasConfigConverter.java index dca41f0..d95d2b3 100644 --- a/src/main/java/net/t2code/alias/Spigot/config/alias/AliasConfigConverter.java +++ b/src/main/java/net/t2code/alias/Spigot/config/alias/AliasConfigConverter.java @@ -36,8 +36,29 @@ public class AliasConfigConverter { public static void convertAddPermission(YamlConfiguration yamlConfiguration, File config_gui, Boolean subalias) { if (subalias) { - yamlConfiguration.set("SubAlias.Permission.Permission", "t2code.alias.use.subalias."); - } else yamlConfiguration.set("Alias.Permission.Permission", "t2code.alias.use."); + yamlConfiguration.set("SubAlias.Permission.Permission", "t2c.alias.sub.use.[alias]"); + } else yamlConfiguration.set("Alias.Permission.Permission", "t2c.alias.use.[alias]"); + try { + yamlConfiguration.save(config_gui); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void convertAddCooldownInSecGlobal(YamlConfiguration yamlConfiguration, File config_gui, Boolean subalias) { + if (subalias) { + yamlConfiguration.set("Alias.CooldownInSec.Global", 0); + } else yamlConfiguration.set("Alias.CooldownInSec.Global", 0); + try { + yamlConfiguration.save(config_gui); + } catch (IOException e) { + e.printStackTrace(); + } + } + public static void convertAddCooldownInSecPlayer(YamlConfiguration yamlConfiguration, File config_gui, Boolean subalias) { + if (subalias) { + yamlConfiguration.set("Alias.CooldownInSec.Player", 0); + } else yamlConfiguration.set("Alias.CooldownInSec.Player", 0); try { yamlConfiguration.save(config_gui); } catch (IOException e) { diff --git a/src/main/java/net/t2code/alias/Spigot/config/alias/CreateExampleAliasConfig.java b/src/main/java/net/t2code/alias/Spigot/config/alias/CreateExampleAliasConfig.java index 9d62705..419cddc 100644 --- a/src/main/java/net/t2code/alias/Spigot/config/alias/CreateExampleAliasConfig.java +++ b/src/main/java/net/t2code/alias/Spigot/config/alias/CreateExampleAliasConfig.java @@ -25,11 +25,11 @@ public class CreateExampleAliasConfig { T2Cconfig.set("Alias.AliasList", Arrays.asList("aliasexample1","t2caliasexample"),yamlConfiguration); T2Cconfig.set("Alias.Permission.Necessary", true, yamlConfiguration); - T2Cconfig.set("Alias.Permission.Permission", "t2code.alias.use.", yamlConfiguration); + T2Cconfig.set("Alias.Permission.Permission", "t2c.alias.use.[alias]", yamlConfiguration); T2Cconfig.set("Alias.Permission.CustomNoPermissionMSG", "", yamlConfiguration); - T2Cconfig.set("Alias.Cooldown.Global", 0, yamlConfiguration); - T2Cconfig.set("Alias.Cooldown.Player", 0, yamlConfiguration); + T2Cconfig.set("Alias.CooldownInSec.Global", 0, yamlConfiguration); + T2Cconfig.set("Alias.CooldownInSec.Player", 0, yamlConfiguration); T2Cconfig.set("Alias.Cost.Enable", false,yamlConfiguration); T2Cconfig.set("Alias.Cost.Confirm", true,yamlConfiguration); @@ -45,7 +45,7 @@ public class CreateExampleAliasConfig { T2Cconfig.set("Alias.Message.Messages", Arrays.asList("This is a test alias", "With this you can use several functions such as colored text, Use Command'>clickable texts, For example Warps'>shorten commands of other plugins and much more.", "http://dc.t2code.net'>If you have any questions, please contact our support Discord."), yamlConfiguration); T2Cconfig.set("Alias.Admin.Enable", false, yamlConfiguration); - T2Cconfig.set("Alias.Admin.Permission", "t2code.alias.admin", yamlConfiguration); + T2Cconfig.set("Alias.Admin.Permission", "t2c.alias.[alias].admin", yamlConfiguration); T2Cconfig.set("Alias.Admin.Command.Enable", true, yamlConfiguration); T2Cconfig.set("Alias.Admin.Command.CommandAsConsole", true, yamlConfiguration); diff --git a/src/main/java/net/t2code/alias/Spigot/config/alias/SelectAlias.java b/src/main/java/net/t2code/alias/Spigot/config/alias/SelectAlias.java index 1f30999..97a6d81 100644 --- a/src/main/java/net/t2code/alias/Spigot/config/alias/SelectAlias.java +++ b/src/main/java/net/t2code/alias/Spigot/config/alias/SelectAlias.java @@ -63,8 +63,16 @@ public class SelectAlias { } String permissionMSG = yamlConfiguration.getString("Alias.Permission.CustomNoPermissionMSG"); - Integer cooldownGlobal = yamlConfiguration.getInt("Alias.Cooldown.Global"); - Integer cooldownPlayer = yamlConfiguration.getInt("Alias.Cooldown.Player"); + + if (yamlConfiguration.get("Alias.CooldownInSec.Global") == null) { + AliasConfigConverter.convertAddCooldownInSecGlobal(yamlConfiguration, config_gui, false); + } + Integer cooldownGlobal = yamlConfiguration.getInt("Alias.CooldownInSec.Global"); + + if (yamlConfiguration.get("Alias.CooldownInSec.Player") == null) { + AliasConfigConverter.convertAddCooldownInSecPlayer(yamlConfiguration, config_gui, false); + } + Integer cooldownPlayer = yamlConfiguration.getInt("Alias.CooldownInSec.Player"); Boolean costEnable = yamlConfiguration.getBoolean("Alias.Cost.Enable"); if (yamlConfiguration.get("Alias.Cost.Confirm") == null) { diff --git a/src/main/java/net/t2code/alias/Spigot/config/config/Config.java b/src/main/java/net/t2code/alias/Spigot/config/config/Config.java index 93e8bcf..f767b77 100644 --- a/src/main/java/net/t2code/alias/Spigot/config/config/Config.java +++ b/src/main/java/net/t2code/alias/Spigot/config/config/Config.java @@ -3,7 +3,6 @@ package net.t2code.alias.Spigot.config.config; import net.t2code.alias.Spigot.enums.ConfigParam; import net.t2code.alias.Spigot.enums.Confirm; import net.t2code.alias.Util; -import net.t2code.t2codelib.SPIGOT.api.items.T2CitemBuilder; import net.t2code.t2codelib.SPIGOT.api.items.T2CitemVersion; import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion; import org.bukkit.Sound; diff --git a/src/main/java/net/t2code/alias/Spigot/config/config/Language.java b/src/main/java/net/t2code/alias/Spigot/config/config/Language.java index eaa1f4f..f3748bc 100644 --- a/src/main/java/net/t2code/alias/Spigot/config/config/Language.java +++ b/src/main/java/net/t2code/alias/Spigot/config/config/Language.java @@ -27,6 +27,10 @@ public enum Language { buy("cost.buy", null, "[prefix] Du hast f[ue]r diesen Command [price] bezahlt.", "[prefix] You have paid [price] for this command.", ConfigParam.STRING), noMoney("cost.noMoney", null, "[prefix] Du hast nicht gen[ue]gend Geld für diesen Command!", "[prefix] You don't have enough money for this command!", ConfigParam.STRING), + + cooldownPlayer("cooldown.player",null,"[prefix] Du musst noch [cooldown] Sekunden warten um diesen Command erneut zu nutzen.","[prefix] You must wait [cooldown] seconds to use this command again.",ConfigParam.STRING), + cooldownGlobal("cooldown.global",null,"[prefix] Du musst noch [cooldown] Sekunden warten um diesen Command zu nutzen.","[prefix] You have to wait [cooldown] seconds to use this command.",ConfigParam.STRING), + confirmCommand("cost.confirm.command", null, "[prefix] Für diesen Befehl musst du [price] bezahlen!
[prefix] Klicke zum bestätigen'>Bestätigen - Klicke zum abbrechen'>Abbrechen", "[prefix] For this command you have to pay [price]!
[prefix] Click to confirm'>Confirm - click to cancel'>Cancel", ConfigParam.STRING), confirmChat("cost.confirm.chat", null, "[prefix] Für diesen Befehl musst du [price] bezahlen!
[prefix] Klicke zum bestätigen'>Bestätigen - Klicke zum abbrechen'>Abbrechen", diff --git a/src/main/java/net/t2code/alias/Spigot/config/subAlias/CreateExampleSubAliasConfig.java b/src/main/java/net/t2code/alias/Spigot/config/subAlias/CreateExampleSubAliasConfig.java index 1c35e67..07d73f9 100644 --- a/src/main/java/net/t2code/alias/Spigot/config/subAlias/CreateExampleSubAliasConfig.java +++ b/src/main/java/net/t2code/alias/Spigot/config/subAlias/CreateExampleSubAliasConfig.java @@ -25,9 +25,12 @@ public class CreateExampleSubAliasConfig { T2Cconfig.set("SubAlias.SubAliasFor", "aliasexample1", yamlConfiguration); T2Cconfig.set("SubAlias.Permission.Necessary", true, yamlConfiguration); - T2Cconfig.set("SubAlias.Permission.Permission", "t2code.alias.use.subalias.", yamlConfiguration); + T2Cconfig.set("SubAlias.Permission.Permission", "t2c.alias.sub.use.[alias]", yamlConfiguration); T2Cconfig.set("SubAlias.Permission.CustomNoPermissionMSG", "", yamlConfiguration); + T2Cconfig.set("SubAlias.CooldownInSec.Global", 0, yamlConfiguration); + T2Cconfig.set("SubAlias.CooldownInSec.Player", 0, yamlConfiguration); + T2Cconfig.set("SubAlias.Cost.Enable", false, yamlConfiguration); T2Cconfig.set("SubAlias.Cost.Confirm", true,yamlConfiguration); T2Cconfig.set("SubAlias.Cost.Price", 0.0, yamlConfiguration); @@ -42,7 +45,7 @@ public class CreateExampleSubAliasConfig { T2Cconfig.set("SubAlias.Message.Messages",Arrays.asList(), yamlConfiguration); T2Cconfig.set("SubAlias.Admin.Enable", false, yamlConfiguration); - T2Cconfig.set("SubAlias.Admin.Permission", "t2code.alias.admin", yamlConfiguration); + T2Cconfig.set("SubAlias.Admin.Permission", "t2c.alias.admin", yamlConfiguration); T2Cconfig.set("SubAlias.Admin.Command.Enable", true, yamlConfiguration); T2Cconfig.set("SubAlias.Admin.Command.CommandAsConsole", true, yamlConfiguration); diff --git a/src/main/java/net/t2code/alias/Spigot/config/subAlias/SelectSubAlias.java b/src/main/java/net/t2code/alias/Spigot/config/subAlias/SelectSubAlias.java index 8fd35dd..5c8b5f4 100644 --- a/src/main/java/net/t2code/alias/Spigot/config/subAlias/SelectSubAlias.java +++ b/src/main/java/net/t2code/alias/Spigot/config/subAlias/SelectSubAlias.java @@ -66,8 +66,15 @@ public class SelectSubAlias { } String permissionMSG = yamlConfiguration.getString("SubAlias.Permission.CustomNoPermissionMSG"); - Integer cooldownGlobal = yamlConfiguration.getInt("Alias.Cooldown.Global"); - Integer cooldownPlayer = yamlConfiguration.getInt("Alias.Cooldown.Player"); + if (yamlConfiguration.get("SubAlias.CooldownInSec.Global") == null) { + AliasConfigConverter.convertAddCooldownInSecGlobal(yamlConfiguration, config_gui, true); + } + Integer cooldownGlobal = yamlConfiguration.getInt("SubAlias.CooldownInSec.Global"); + + if (yamlConfiguration.get("SubAlias.CooldownInSec.Player") == null) { + AliasConfigConverter.convertAddCooldownInSecPlayer(yamlConfiguration, config_gui, true); + } + Integer cooldownPlayer = yamlConfiguration.getInt("SubAlias.CooldownInSec.Player"); Boolean costEnable = yamlConfiguration.getBoolean("SubAlias.Cost.Enable"); if (yamlConfiguration.get("SubAlias.Cost.Confirm") == null) { @@ -106,9 +113,11 @@ public class SelectSubAlias { SubAliasObject subAlias = new SubAliasObject(aliasEnable, subAliasList, subAliasFor, subAliasArg, permNecessary, permission, permissionMSG, cooldownGlobal, cooldownPlayer, costEnable, costConfirm, costPrice, costAllowBypass, commandEnable, commandAsConsole, bungeeCommand, command, messageEnable, messages, adminEnable, adminPermission, adminCommandEnable, adminCommandAsConsole, adminBungeeCommand, adminCommands, adminMessageEnable, adminMessages, consoleEnable, consoleCommandEnable, consoleBungeeCommand, consoleCommands, consoleMessageEnable, consoleMessages); + for (String sal : subAliasList) { Main.subAliasHashMap.put(sal, subAlias); } + Main.allSubAliases.addAll(subAliasList); Main.allForSubAliases.add(subAliasFor); T2Csend.console(Prefix + " §aSubAlias file §e" + config_gui.getName() + " §awas loaded"); diff --git a/src/main/java/net/t2code/alias/Spigot/objects/AliasObject.java b/src/main/java/net/t2code/alias/Spigot/objects/AliasObject.java index b113477..6e4eb04 100644 --- a/src/main/java/net/t2code/alias/Spigot/objects/AliasObject.java +++ b/src/main/java/net/t2code/alias/Spigot/objects/AliasObject.java @@ -1,8 +1,14 @@ package net.t2code.alias.Spigot.objects; +import java.util.HashMap; import java.util.List; +import java.util.UUID; public class AliasObject { + + public HashMap cooldownPlayerMap = new HashMap<>(); + public Long globalCooldownInt = 0L; + public Boolean aliasEnable; public List aliasList; diff --git a/src/main/java/net/t2code/alias/Spigot/objects/SubAliasObject.java b/src/main/java/net/t2code/alias/Spigot/objects/SubAliasObject.java index 69fca60..c289037 100644 --- a/src/main/java/net/t2code/alias/Spigot/objects/SubAliasObject.java +++ b/src/main/java/net/t2code/alias/Spigot/objects/SubAliasObject.java @@ -1,8 +1,13 @@ package net.t2code.alias.Spigot.objects; +import java.util.HashMap; import java.util.List; +import java.util.UUID; public class SubAliasObject { + public HashMap cooldownPlayerMap = new HashMap<>(); + public Long globalCooldownInt = 0L; + public Boolean subAliasEnable; public List subAliasList; public Integer subAliasArg; diff --git a/src/main/java/net/t2code/alias/Spigot/system/AliasRegisterPermissions.java b/src/main/java/net/t2code/alias/Spigot/system/AliasRegisterPermissions.java index 648132d..ac38e39 100644 --- a/src/main/java/net/t2code/alias/Spigot/system/AliasRegisterPermissions.java +++ b/src/main/java/net/t2code/alias/Spigot/system/AliasRegisterPermissions.java @@ -5,6 +5,7 @@ import net.t2code.alias.Spigot.objects.AliasObject; import net.t2code.alias.Spigot.objects.SubAliasObject; import net.t2code.t2codelib.SPIGOT.api.register.T2Cregister; import org.bukkit.Bukkit; +import org.bukkit.permissions.PermissionDefault; public class AliasRegisterPermissions { @@ -13,22 +14,40 @@ public class AliasRegisterPermissions { for (AliasObject aliasObject : Main.aliasHashMap.values()) { for (String alias : aliasObject.aliasList) { - if (aliasObject.permission != null && Bukkit.getPluginManager().getPermission(aliasObject.permission.replace("", alias).toLowerCase()) == null) { - T2Cregister.permission(aliasObject.permission.replace("", alias).toLowerCase(), Main.getPlugin()); + if (aliasObject.permission != null && Bukkit.getPluginManager().getPermission(aliasObject.permission.replace("[alias]", alias).toLowerCase()) == null) { + T2Cregister.permission(aliasObject.permission.replace("[alias]", alias).toLowerCase(), Main.getPlugin()); } - if (aliasObject.adminPermission != null && Bukkit.getPluginManager().getPermission(aliasObject.adminPermission.replace("", alias).toLowerCase()) == null) { - T2Cregister.permission(aliasObject.adminPermission.replace("", alias).toLowerCase(), Main.getPlugin()); + if (aliasObject.adminPermission != null && Bukkit.getPluginManager().getPermission(aliasObject.adminPermission.replace("[alias]", alias).toLowerCase()) == null) { + T2Cregister.permission(aliasObject.adminPermission.replace("[alias]", alias).toLowerCase(), Main.getPlugin()); + } + if (Bukkit.getPluginManager().getPermission("t2c.alias.buy." + alias.toLowerCase() + ".bypass") == null) { + T2Cregister.permission("t2c.alias.buy." + alias.toLowerCase() + ".bypass", PermissionDefault.OP, Main.getPlugin()); + } + if (Bukkit.getPluginManager().getPermission("t2c.alias.cooldown.global." + alias.toLowerCase() + ".bypass") == null) { + T2Cregister.permission("t2c.alias.cooldown.global." + alias.toLowerCase() + ".bypass", PermissionDefault.OP, Main.getPlugin()); + } + if (Bukkit.getPluginManager().getPermission("t2c.alias.cooldown.player." + alias.toLowerCase() + ".bypass") == null) { + T2Cregister.permission("t2c.alias.cooldown.player." + alias.toLowerCase() + ".bypass", PermissionDefault.OP, Main.getPlugin()); } } } for (SubAliasObject subAliasObject : Main.subAliasHashMap.values()) { for (String alias : subAliasObject.subAliasList) { - if (subAliasObject.permission != null && Bukkit.getPluginManager().getPermission(subAliasObject.permission.replace("", alias).toLowerCase()) == null) { - T2Cregister.permission(subAliasObject.permission.replace("", alias).toLowerCase(), Main.getPlugin()); + if (subAliasObject.permission != null && Bukkit.getPluginManager().getPermission(subAliasObject.permission.replace("[alias]", alias).toLowerCase()) == null) { + T2Cregister.permission(subAliasObject.permission.replace("[alias]", alias).toLowerCase(), Main.getPlugin()); } - if (subAliasObject.adminPermission != null && Bukkit.getPluginManager().getPermission(subAliasObject.adminPermission.replace("", alias).toLowerCase()) == null) { - T2Cregister.permission(subAliasObject.adminPermission.replace("", alias).toLowerCase(), Main.getPlugin()); + if (subAliasObject.adminPermission != null && Bukkit.getPluginManager().getPermission(subAliasObject.adminPermission.replace("[alias]", alias).toLowerCase()) == null) { + T2Cregister.permission(subAliasObject.adminPermission.replace("[alias]", alias).toLowerCase(), Main.getPlugin()); + } + if (Bukkit.getPluginManager().getPermission("t2c.alias.sub.buy." + alias.toLowerCase() + ".bypass") == null) { + T2Cregister.permission("t2c.alias.sub.buy." + alias.toLowerCase() + ".bypass", PermissionDefault.OP, Main.getPlugin()); + } + if (Bukkit.getPluginManager().getPermission("t2c.alias.sub.cooldown.global." + alias.toLowerCase() + ".bypass") == null) { + T2Cregister.permission("t2c.alias.sub.cooldown.global." + alias.toLowerCase() + ".bypass", PermissionDefault.OP, Main.getPlugin()); + } + if (Bukkit.getPluginManager().getPermission("t2c.alias.sub.cooldown.player." + alias.toLowerCase() + ".bypass") == null) { + T2Cregister.permission("t2c.alias.sub.cooldown.player." + alias.toLowerCase() + ".bypass", PermissionDefault.OP, Main.getPlugin()); } } } diff --git a/src/main/java/net/t2code/alias/Spigot/system/PluginEvents.java b/src/main/java/net/t2code/alias/Spigot/system/PluginEvents.java index 2b15b1c..4e5487a 100644 --- a/src/main/java/net/t2code/alias/Spigot/system/PluginEvents.java +++ b/src/main/java/net/t2code/alias/Spigot/system/PluginEvents.java @@ -22,6 +22,6 @@ public class PluginEvents implements Listener { @EventHandler public void onJoinEvent(PlayerLoginEvent event) { - T2CupdateAPI.join(Main.getPlugin(), Util.getPrefix(), "t2code.alias.updatemsg", event.getPlayer(), Util.getSpigotID(), Util.getDiscord()); + T2CupdateAPI.join(Main.getPlugin(), Util.getPrefix(), "t2c.alias.updatemsg", event.getPlayer(), Util.getSpigotID(), Util.getDiscord()); } } diff --git a/src/main/resources/Alias/X_aliasDeclaration_X.yml b/src/main/resources/Alias/X_aliasDeclaration_X.yml index 295cf98..637a9bc 100644 --- a/src/main/resources/Alias/X_aliasDeclaration_X.yml +++ b/src/main/resources/Alias/X_aliasDeclaration_X.yml @@ -11,25 +11,43 @@ Alias: AliasList: - aliasexample1 - aliasexample2 + - Permission: # Here you can say if a permission is needed to use the alias# Necessary: true # Here you can set the permission for the alias. - # The placeholder is the alias name. + # The placeholder <[alias] is the alias name. # If you have set multiple alias referrers in the list 'Alias.AliasList' you have a permission for each alias. - Permission: 't2code.alias.use.' + Permission: 't2c.alias.use.[alias]' # Here you can set a custom No Permission message for this alias. If you want to use the default message, just leave this blank. CustomNoPermissionMSG: "" + + CooldownInSec: + # Here you can set a global cooldown for this alias. + # The value corresponds to the seconds. + # At 0, the cooldown is deactivated. + # The placeholder [alias] is the alias name. + # Bypass permission: t2c.alias.cooldown.global.[alias].bypass + # (The global cooldown is above the player cooldown). + Global: 0 + # Here you can set a player-specific cooldown for this alias. + # The value corresponds to the seconds. + # At 0, the cooldown is deactivated. + # The placeholder [alias] is the alias name. + # Bypass permission: t2c.alias.cooldown.player.[alias].bypass + Player: 0 + Cost: # Here you can say if you have to pay for the alias Enable: false # Here you set the price Price: 0.0 - # Here you define if the bypass is activated or if you have to pay despite the bypass (t2code.alias.buy.bypass). + # Here you define if the bypass is activated or if you have to pay despite the bypass (t2c.alias.buy.[alias].bypass). AllowByPass: true # Here you can set if you have to confirm if you want to pay before executing the command # In the config.yml you can set under 'buy.confirm.use' if a command, a chatListener or a GUI should be used to confirm the command. Confirm: true + Command: # Here you can tell the alias to execute one or more commands Enable: false @@ -41,7 +59,8 @@ Alias: BungeeCommand: false # Here you can specify one or more commands to be executed. # Placeholder: [player] = The player who executes the alias - Commands: [ ] + Commands: [] + Message: # Here you can specify whether the player should receive a message. Enable: false @@ -67,7 +86,7 @@ Alias: # You can also use MiniMessage: # Wiki: https://docs.adventure.kyori.net/minimessage/format.html # WebUI: https://webui.adventure.kyori.net - Messages: [ ] + Messages: [] # Here you can specify that players with the permission () have a different function than other players. # For example, you can say that players should come to a certain point and players with the admin function only to the server to the position where they were before. @@ -78,9 +97,9 @@ Alias: # Here you can enable or disable the admin function Enable: false # Here you set the permission for the admin function - # The placeholder is the alias name. + # The placeholder [alias] is the alias name. # If you have set multiple alias referrers in the list 'Alias.AliasList' you have a permission for each alias. - Permission: t2code.alias.admin + Permission: t2c.alias.[alias].admin Command: # Here you can tell the alias to execute one or more commands Enable: false @@ -92,7 +111,8 @@ Alias: BungeeCommand: false # Here you can specify one or more commands to be executed. # Placeholder: [player] = The player who executes the alias - Commands: [ ] + Commands: [] + Message: # Here you can specify whether the player should receive a message. Enable: false @@ -118,7 +138,7 @@ Alias: # You can also use MiniMessage: # Wiki: https://docs.adventure.kyori.net/minimessage/format.html # WebUI: https://webui.adventure.kyori.net - Messages: [ ] + Messages: [] Console: # Here you can define if the alias is also usable in the console and what it should do from there. @@ -130,9 +150,9 @@ Alias: # For this option, BungeeCord must be set to true in config.yml and the plugin must also work on the proxy as a bridge. BungeeCommand: false # Here you can specify one or more commands to be executed. - Commands: [ ] + Commands: [] Message: # Here you can specify whether the player should receive a message. Enable: false # Specify here the message that the player should get. - Messages: [ ] \ No newline at end of file + Messages: [] \ No newline at end of file diff --git a/src/main/resources/SubAlias/X_subAliasDeclaration_X.yml b/src/main/resources/SubAlias/X_subAliasDeclaration_X.yml index cb2b607..aa11ca0 100644 --- a/src/main/resources/SubAlias/X_subAliasDeclaration_X.yml +++ b/src/main/resources/SubAlias/X_subAliasDeclaration_X.yml @@ -19,21 +19,38 @@ SubAlias: # Here you can say if a permission is needed to use the alias# Necessary: true # Here you can set the permission for the alias. - # The placeholder is the alias name. + # The placeholder [alias] is the subalias name. # If you have set multiple alias referrers in the list 'Alias.SubAliasList' you have a permission for each alias. - Permission: 't2code.alias.use.subalias.' + Permission: 't2c.subalias.use.[alias]' # Here you can set a custom No Permission message for this alias. If you want to use the default message, just leave this blank. CustomNoPermissionMSG: "" + + CooldownInSec: + # Here you can set a global cooldown for this alias. + # The value corresponds to the seconds. + # At 0, the cooldown is deactivated. + # The placeholder [alias] is the subalias name. + # Bypass permission: t2c.alias.sub.cooldown.global.[alias].bypass + # (The global cooldown is above the player cooldown). + Global: 0 + # Here you can set a player-specific cooldown for this alias. + # The value corresponds to the seconds. + # At 0, the cooldown is deactivated. + # The placeholder [alias] is the subalias name. + # Bypass permission: t2c.alias.sub.cooldown.player.[alias].bypass + Player: 0 + Cost: # Here you can say if you have to pay for the alias Enable: false # Here you set the price Price: 0.0 - # Here you define if the bypass is activated or if you have to pay despite the bypass (t2code.alias.buy.bypass). + # Here you define if the bypass is activated or if you have to pay despite the bypass (t2c.alias.buy.[alias].bypass). AllowByPass: true # Here you can set if you have to confirm if you want to pay before executing the command # In the config.yml you can set under 'buy.confirm.use' if a command, a chatListener or a GUI should be used to confirm the command. Confirm: true + Command: # Here you can tell the alias to execute one or more commands Enable: false @@ -46,6 +63,7 @@ SubAlias: # Here you can specify one or more commands to be executed. # Placeholder: [player] = The player who executes the alias Commands: [] + Message: # Here you can specify whether the player should receive a message. Enable: false @@ -82,9 +100,9 @@ SubAlias: # Here you can enable or disable the admin function Enable: false # Here you set the permission for the admin function - # The placeholder is the alias name. + # The placeholder [alias] is the alias name. # If you have set multiple alias referrers in the list 'Alias.SubAliasList' you have a permission for each alias. - Permission: t2code.alias.admin + Permission: t2c.alias.sub.[alias].admin Command: # Here you can tell the alias to execute one or more commands Enable: false @@ -97,6 +115,7 @@ SubAlias: # Here you can specify one or more commands to be executed. # Placeholder: [player] = The player who executes the alias Commands: [] + Message: # Here you can specify whether the player should receive a message. Enable: false diff --git a/src/main/resources/X_configDeclaration_X.yml b/src/main/resources/X_configDeclaration_X.yml index 145cdae..567a907 100644 --- a/src/main/resources/X_configDeclaration_X.yml +++ b/src/main/resources/X_configDeclaration_X.yml @@ -10,7 +10,7 @@ plugin: # In this option you can set the language of the plugin. language: english updateCheck: - # In this option you can set if players with the permission 't2code.alias.updatemsg' will get an update message on join when an update for the plugin is available. + # In this option you can set if players with the permission 't2c.alias.updatemsg' will get an update message on join when an update for the plugin is available. onJoin: true # In this option you can set whether you want to receive and display beta and snapshot versions in the update check. seePreReleaseUpdates: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2efc7f8..14c33a6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -16,20 +16,39 @@ commands: aliases: [t2c-a, alias] permissions: - t2code.alias.admin: + t2c.alias.admin: default: op children: - t2code.alias.updatemsg: true - t2code.alias.command.reload: true - t2code.alias.command.info: true - t2code.alias.buy.bypass: true + t2c.alias.updatemsg: true + t2c.alias.command.reload: true + t2c.alias.command.info: true + + t2c.alias.buy.all.bypass: true + t2c.alias.cooldown.global.all.bypass: true + t2c.alias.cooldown.player.all.bypass: true + + t2c.alias.sub.buy.all.bypass: true + t2c.alias.sub.cooldown.global.all.bypass: true + t2c.alias.sub.cooldown.player.all.bypass: true - t2code.alias.buy.bypass: + t2c.alias.updatemsg: default: op - t2code.alias.updatemsg: + t2c.alias.command.reload: default: op - t2code.alias.command.reload: + t2c.alias.command.info: default: op - t2code.alias.command.info: + + t2c.alias.buy.all.bypass: + default: op + t2c.alias.cooldown.global.all.bypass: + default: op + t2c.alias.cooldown.player.all.bypass: + default: op + + t2c.alias.sub.buy.all.bypass: + default: op + t2c.alias.sub.cooldown.global.all.bypass: + default: op + t2c.alias.sub.cooldown.player.all.bypass: default: op