From f8b86086db3e3977b69e3503d3c3efef01a5b4a2 Mon Sep 17 00:00:00 2001 From: JaTiTV Date: Tue, 5 Jul 2022 20:03:22 +0200 Subject: [PATCH] remove textBuilder and other changes --- .../java/net/t2code/alias/Spigot/Main.java | 3 + .../cmdManagement/RegisterCommands.java | 148 ++++++++++-------- .../alias/Spigot/objects/AliasObjekt.java | 38 +---- .../net/t2code/alias/Spigot/system/Load.java | 21 ++- 4 files changed, 109 insertions(+), 101 deletions(-) diff --git a/src/main/java/net/t2code/alias/Spigot/Main.java b/src/main/java/net/t2code/alias/Spigot/Main.java index f0c60c9..6531807 100644 --- a/src/main/java/net/t2code/alias/Spigot/Main.java +++ b/src/main/java/net/t2code/alias/Spigot/Main.java @@ -1,6 +1,7 @@ package net.t2code.alias.Spigot; import net.t2code.alias.Spigot.objects.AliasObjekt; +import net.t2code.alias.Spigot.objects.SubAliasObjekt; import net.t2code.alias.Spigot.system.Load; import net.t2code.alias.Util; import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; @@ -23,7 +24,9 @@ public final class Main extends JavaPlugin { public static List autor; public static Main plugin; public static HashMap aliasHashMap = new HashMap<>(); + public static HashMap subAliasHashMap = new HashMap<>(); public static ArrayList allAliases = new ArrayList<>(); + public static ArrayList allSubAliases = new ArrayList<>(); @Override public void onEnable() { diff --git a/src/main/java/net/t2code/alias/Spigot/cmdManagement/RegisterCommands.java b/src/main/java/net/t2code/alias/Spigot/cmdManagement/RegisterCommands.java index efbf5b1..074f234 100644 --- a/src/main/java/net/t2code/alias/Spigot/cmdManagement/RegisterCommands.java +++ b/src/main/java/net/t2code/alias/Spigot/cmdManagement/RegisterCommands.java @@ -1,23 +1,28 @@ package net.t2code.alias.Spigot.cmdManagement; -import net.md_5.bungee.api.chat.ClickEvent; import net.t2code.alias.Spigot.Main; import net.t2code.alias.Spigot.config.config.SelectConfig; import net.t2code.alias.Spigot.config.languages.SelectMessages; import net.t2code.alias.Spigot.objects.AliasObjekt; +import net.t2code.alias.Spigot.objects.SubAliasObjekt; import net.t2code.alias.Spigot.system.*; import net.t2code.alias.Util; import net.t2code.lib.Spigot.Lib.commands.Cmd; +import net.t2code.lib.Spigot.Lib.commands.Tab; import net.t2code.lib.Spigot.Lib.eco.Eco; -import net.t2code.lib.Spigot.Lib.messages.TextBuilder; import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.plugins.PluginCheck; import net.t2code.lib.Spigot.Lib.replace.Replace; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -public class RegisterCommands extends Command { +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class RegisterCommands extends Command implements TabCompleter { private String alias; private String prefix = Util.getPrefix(); @@ -34,51 +39,68 @@ public class RegisterCommands extends Command { send.sender(sender, SelectMessages.aliasDisabled); return true; } - if (sender instanceof Player) { - Player player = (Player) sender; - - if (alias.adminEnable) { - if (player.hasPermission(alias.adminPermission)) { - if (alias.adminCommandEnable) { - adminCommand(alias, player); - } - if (alias.adminMessageEnable) { - adminMessage(alias, player, prefix); - } - return true; - } - } - - if (alias.permNecessary) { - if (!(player.hasPermission("t2code.alias.use." + this.alias.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) { - send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" + this.alias.toLowerCase()) - .replace("[perm]", "t2code.alias.use." + this.alias.toLowerCase())); - return true; - } - } - if (alias.costEnable) { - if (!(alias.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass")) ){ - if (!Eco.moneyRemove(prefix, player, alias.costPrice)) { - send.player(player, SelectMessages.noMoney); - return true; - } - if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", alias.costPrice.toString())); - } - } - if (alias.commandEnable) { - command(alias, player); - } - if (alias.messageEnable) { - message(alias, player, prefix); + if (args.length == 0) { + if (sender instanceof Player) { + exPlayer(sender, alias); + } else { + if (alias.consoleEnable) { + console(alias, sender, prefix); + } else send.sender(sender, SelectMessages.onlyForPlayer); } } else { - if (alias.consoleEnable) { - console(alias, sender, prefix); - } else send.sender(sender, SelectMessages.onlyForPlayer); + for (String sals : Main.allSubAliases) { + SubAliasObjekt sal = Main.subAliasHashMap.get(sals); + if (args.length == sal.subAliasArg) { + for (String al : sal.subAliasList) { + if (args[sal.subAliasArg].toLowerCase().equals(al)) { + RegisterSubAliasCommands.execute(sender, sal, al); + } + } + } + } } return true; } + private void exPlayer(CommandSender sender, AliasObjekt alias) { + Player player = (Player) sender; + + if (alias.adminEnable) { + if (player.hasPermission(alias.adminPermission)) { + if (alias.adminCommandEnable) { + adminCommand(alias, player); + } + if (alias.adminMessageEnable) { + adminMessage(alias, player, prefix); + } + return; + } + } + + if (alias.permNecessary) { + if (!(player.hasPermission("t2code.alias.use." + this.alias.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) { + send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" + this.alias.toLowerCase()) + .replace("[perm]", "t2code.alias.use." + this.alias.toLowerCase())); + return; + } + } + if (alias.costEnable) { + if (!(alias.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) { + if (!Eco.moneyRemove(prefix, player, alias.costPrice)) { + send.player(player, SelectMessages.noMoney); + return; + } + if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", alias.costPrice.toString())); + } + } + if (alias.commandEnable) { + command(alias, player); + } + if (alias.messageEnable) { + message(alias, player, prefix); + } + } + private static void adminCommand(AliasObjekt alias, Player player) { for (String cmd : alias.adminCommands) { if (alias.adminBungeeCommand) { @@ -107,21 +129,10 @@ public class RegisterCommands extends Command { String hover; if (PluginCheck.papi()) { text = Replace.replace(prefix, player, replacePlayer(msg, player)); - hover = Replace.replace(prefix, player, alias.adminHover); } else { text = Replace.replace(prefix, replacePlayer(msg, player)); - hover = Replace.replace(prefix, alias.adminHover); - } - if (alias.adminTextBuilder) { - TextBuilder textBuilder = new TextBuilder(text); - textBuilder.addHover(hover); - if (alias.adminClickEvent) { - textBuilder.addClickEvent(ClickEvent.Action.valueOf(alias.adminAction), alias.adminActionValue); - } - player.spigot().sendMessage(textBuilder.build()); - } else { - send.player(player, text); } + send.player(player, text); } } @@ -153,21 +164,10 @@ public class RegisterCommands extends Command { String hover; if (PluginCheck.papi()) { text = Replace.replace(prefix, player, replacePlayer(msg, player)); - hover = Replace.replace(prefix, player, alias.hover); } else { text = Replace.replace(prefix, replacePlayer(msg, player)); - hover = Replace.replace(prefix, alias.hover); - } - if (alias.textBuilder) { - TextBuilder textBuilder = new TextBuilder(text); - textBuilder.addHover(hover); - if (alias.clickEvent) { - textBuilder.addClickEvent(ClickEvent.Action.valueOf(alias.action), alias.actionValue); - } - player.spigot().sendMessage(textBuilder.build()); - } else { - send.player(player, text); } + send.player(player, text); } } @@ -196,5 +196,21 @@ public class RegisterCommands extends Command { private static String replacePlayer(String s, Player player) { return s.replace("[player]", player.getName()); } + + private static HashMap arg1 = new HashMap(); + + @Override + public List onTabComplete(CommandSender sender, Command cmd, String s, String[] args) { + List list = new ArrayList<>(); + arg1.clear(); + for (String sals : Main.allSubAliases) { + SubAliasObjekt sal = Main.subAliasHashMap.get(sals); + for (String al : sal.subAliasList) { + arg1.put(al, "t2code.alias.use.subalias." + al.toLowerCase()); + } + Tab.tab(list, sender, sal.subAliasArg, args, arg1); + } + return list; + } } diff --git a/src/main/java/net/t2code/alias/Spigot/objects/AliasObjekt.java b/src/main/java/net/t2code/alias/Spigot/objects/AliasObjekt.java index a6d149f..cf9be93 100644 --- a/src/main/java/net/t2code/alias/Spigot/objects/AliasObjekt.java +++ b/src/main/java/net/t2code/alias/Spigot/objects/AliasObjekt.java @@ -4,23 +4,21 @@ import java.util.List; public class AliasObjekt { public Boolean aliasEnable; - public Boolean commandEnable; + public List aliasList; + public Boolean permNecessary; public Boolean costEnable; public Double costPrice; public Boolean costAllowBypass; + public Boolean commandEnable; public Boolean commandAsConsole; public Boolean bungeeCommand; public List command; public Boolean messageEnable; public List messages; - public Boolean textBuilder; - public String hover; - public Boolean clickEvent; - public String action; - public String actionValue; + public Boolean adminEnable; public String adminPermission; @@ -30,11 +28,6 @@ public class AliasObjekt { public List adminCommands; public Boolean adminMessageEnable; public List adminMessages; - public Boolean adminTextBuilder; - public String adminHover; - public Boolean adminClickEvent; - public String adminAction; - public String adminActionValue; public Boolean consoleEnable; public Boolean consoleCommandEnable; public Boolean consoleBungeeCommand; @@ -43,6 +36,7 @@ public class AliasObjekt { public List consoleMessages; public AliasObjekt(Boolean aliasEnable, + List aliasList, Boolean permNecessary, Boolean costEnable, @@ -55,11 +49,6 @@ public class AliasObjekt { List command, Boolean messageEnable, List messages, - Boolean textBuilder, - String hover, - Boolean clickEvent, - String action, - String actionValue, Boolean adminEnable, String adminPermission, @@ -69,11 +58,6 @@ public class AliasObjekt { List adminCommands, Boolean adminMessageEnable, List adminMessages, - Boolean adminTextBuilder, - String adminHover, - Boolean adminClickEvent, - String adminAction, - String adminActionValue, Boolean consoleEnable, Boolean consoleCommandEnable, @@ -82,6 +66,7 @@ public class AliasObjekt { Boolean consoleMessageEnable, List consoleMessages) { this.aliasEnable = aliasEnable; + this.aliasList=aliasList; this.permNecessary = permNecessary; this.costEnable = costEnable; @@ -94,11 +79,6 @@ public class AliasObjekt { this.command = command; this.messageEnable = messageEnable; this.messages = messages; - this.textBuilder = textBuilder; - this.hover = hover; - this.clickEvent = clickEvent; - this.action = action; - this.actionValue = actionValue; this.adminEnable = adminEnable; this.adminPermission = adminPermission; this.adminCommandEnable = adminCommandEnable; @@ -107,11 +87,7 @@ public class AliasObjekt { this.adminCommands = adminCommands; this.adminMessageEnable = adminMessageEnable; this.adminMessages = adminMessages; - this.adminTextBuilder = adminTextBuilder; - this.adminHover = adminHover; - this.adminClickEvent = adminClickEvent; - this.adminAction = adminAction; - this.adminActionValue = adminActionValue; + this.consoleEnable = consoleEnable; this.consoleCommandEnable = consoleCommandEnable; diff --git a/src/main/java/net/t2code/alias/Spigot/system/Load.java b/src/main/java/net/t2code/alias/Spigot/system/Load.java index 642954e..c62027f 100644 --- a/src/main/java/net/t2code/alias/Spigot/system/Load.java +++ b/src/main/java/net/t2code/alias/Spigot/system/Load.java @@ -2,14 +2,12 @@ package net.t2code.alias.Spigot.system; import net.t2code.alias.Spigot.Main; import net.t2code.alias.Spigot.cmdManagement.AliasCmdExecuter; -import net.t2code.alias.Spigot.config.config.CreateConfig; -import net.t2code.alias.Spigot.config.config.CreateExampleAliasConfig; -import net.t2code.alias.Spigot.config.config.SelectAlias; -import net.t2code.alias.Spigot.config.config.SelectConfig; +import net.t2code.alias.Spigot.config.config.*; import net.t2code.alias.Spigot.config.languages.LanguagesCreate; import net.t2code.alias.Spigot.config.languages.SelectMessages; import net.t2code.alias.Util; import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; +import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.update.UpdateAPI; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -37,24 +35,39 @@ public class Load { CreateExampleAliasConfig.configCreate(); } catch (Exception e) { e.printStackTrace(); + }try { + CreateExampleSubAliasConfig.configCreate(); + } catch (Exception e) { + e.printStackTrace(); } } try { plugin.saveResource("Alias/X_aliasDeclaration_X.yml",true); } catch (Exception e) { e.printStackTrace(); + }try { + plugin.saveResource("SubAlias/X_subaliasDeclaration_X.yml",true); + } catch (Exception e) { + e.printStackTrace(); } CreateConfig.configCreate(); LanguagesCreate.langCreate(); SelectConfig.onSelect(); SelectMessages.onSelect(Util.getPrefix()); SelectAlias.onSelect(); + SelectSubAlias.onSelect(); if (SelectConfig.Bungee) { Main.plugin.getServer().getMessenger().registerOutgoingPluginChannel(Main.plugin, "BungeeCord"); Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "t2codealias:bungee"); } AliasRegisterPermissions.onPermRegister(); + + send.debugmsg(plugin,Main.aliasHashMap.toString()); + send.debugmsg(plugin,Main.allAliases.toString()); + send.debugmsg(plugin,Main.subAliasHashMap.toString()); + + send.debugmsg(plugin,Main.allSubAliases.toString()); } }