1.1.0 | SubAlias, MiniMessage and more #3

Merged
JaTiTV merged 9 commits from 1.1 into main 2022-07-14 19:57:24 +00:00
4 changed files with 109 additions and 101 deletions
Showing only changes of commit f8b86086db - Show all commits

View File

@ -1,6 +1,7 @@
package net.t2code.alias.Spigot; package net.t2code.alias.Spigot;
import net.t2code.alias.Spigot.objects.AliasObjekt; 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.Spigot.system.Load;
import net.t2code.alias.Util; import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
@ -23,7 +24,9 @@ public final class Main extends JavaPlugin {
public static List<String> autor; public static List<String> autor;
public static Main plugin; public static Main plugin;
public static HashMap<String, AliasObjekt> aliasHashMap = new HashMap<>(); public static HashMap<String, AliasObjekt> aliasHashMap = new HashMap<>();
public static HashMap<String, SubAliasObjekt> subAliasHashMap = new HashMap<>();
public static ArrayList<String> allAliases = new ArrayList<>(); public static ArrayList<String> allAliases = new ArrayList<>();
public static ArrayList<String> allSubAliases = new ArrayList<>();
@Override @Override
public void onEnable() { public void onEnable() {

View File

@ -1,23 +1,28 @@
package net.t2code.alias.Spigot.cmdManagement; 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.Main;
import net.t2code.alias.Spigot.config.config.SelectConfig; import net.t2code.alias.Spigot.config.config.SelectConfig;
import net.t2code.alias.Spigot.config.languages.SelectMessages; import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.alias.Spigot.objects.AliasObjekt; import net.t2code.alias.Spigot.objects.AliasObjekt;
import net.t2code.alias.Spigot.objects.SubAliasObjekt;
import net.t2code.alias.Spigot.system.*; import net.t2code.alias.Spigot.system.*;
import net.t2code.alias.Util; import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.commands.Cmd; 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.eco.Eco;
import net.t2code.lib.Spigot.Lib.messages.TextBuilder;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck; import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
import net.t2code.lib.Spigot.Lib.replace.Replace; import net.t2code.lib.Spigot.Lib.replace.Replace;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; 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 alias;
private String prefix = Util.getPrefix(); private String prefix = Util.getPrefix();
@ -34,51 +39,68 @@ public class RegisterCommands extends Command {
send.sender(sender, SelectMessages.aliasDisabled); send.sender(sender, SelectMessages.aliasDisabled);
return true; return true;
} }
if (sender instanceof Player) { if (args.length == 0) {
Player player = (Player) sender; if (sender instanceof Player) {
exPlayer(sender, alias);
if (alias.adminEnable) { } else {
if (player.hasPermission(alias.adminPermission)) { if (alias.consoleEnable) {
if (alias.adminCommandEnable) { console(alias, sender, prefix);
adminCommand(alias, player); } else send.sender(sender, SelectMessages.onlyForPlayer);
}
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);
} }
} else { } else {
if (alias.consoleEnable) { for (String sals : Main.allSubAliases) {
console(alias, sender, prefix); SubAliasObjekt sal = Main.subAliasHashMap.get(sals);
} else send.sender(sender, SelectMessages.onlyForPlayer); if (args.length == sal.subAliasArg) {
for (String al : sal.subAliasList) {
if (args[sal.subAliasArg].toLowerCase().equals(al)) {
RegisterSubAliasCommands.execute(sender, sal, al);
}
}
}
}
} }
return true; 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) { private static void adminCommand(AliasObjekt alias, Player player) {
for (String cmd : alias.adminCommands) { for (String cmd : alias.adminCommands) {
if (alias.adminBungeeCommand) { if (alias.adminBungeeCommand) {
@ -107,21 +129,10 @@ public class RegisterCommands extends Command {
String hover; String hover;
if (PluginCheck.papi()) { if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player)); text = Replace.replace(prefix, player, replacePlayer(msg, player));
hover = Replace.replace(prefix, player, alias.adminHover);
} else { } else {
text = Replace.replace(prefix, replacePlayer(msg, player)); 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; String hover;
if (PluginCheck.papi()) { if (PluginCheck.papi()) {
text = Replace.replace(prefix, player, replacePlayer(msg, player)); text = Replace.replace(prefix, player, replacePlayer(msg, player));
hover = Replace.replace(prefix, player, alias.hover);
} else { } else {
text = Replace.replace(prefix, replacePlayer(msg, player)); 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) { private static String replacePlayer(String s, Player player) {
return s.replace("[player]", player.getName()); return s.replace("[player]", player.getName());
} }
private static HashMap<String, String> arg1 = new HashMap<String, String>();
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
List<String> 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;
}
} }

View File

@ -4,23 +4,21 @@ import java.util.List;
public class AliasObjekt { public class AliasObjekt {
public Boolean aliasEnable; public Boolean aliasEnable;
public Boolean commandEnable; public List<String> aliasList;
public Boolean permNecessary; public Boolean permNecessary;
public Boolean costEnable; public Boolean costEnable;
public Double costPrice; public Double costPrice;
public Boolean costAllowBypass; public Boolean costAllowBypass;
public Boolean commandEnable;
public Boolean commandAsConsole; public Boolean commandAsConsole;
public Boolean bungeeCommand; public Boolean bungeeCommand;
public List<String> command; public List<String> command;
public Boolean messageEnable; public Boolean messageEnable;
public List<String> messages; public List<String> messages;
public Boolean textBuilder;
public String hover;
public Boolean clickEvent;
public String action;
public String actionValue;
public Boolean adminEnable; public Boolean adminEnable;
public String adminPermission; public String adminPermission;
@ -30,11 +28,6 @@ public class AliasObjekt {
public List<String> adminCommands; public List<String> adminCommands;
public Boolean adminMessageEnable; public Boolean adminMessageEnable;
public List<String> adminMessages; public List<String> adminMessages;
public Boolean adminTextBuilder;
public String adminHover;
public Boolean adminClickEvent;
public String adminAction;
public String adminActionValue;
public Boolean consoleEnable; public Boolean consoleEnable;
public Boolean consoleCommandEnable; public Boolean consoleCommandEnable;
public Boolean consoleBungeeCommand; public Boolean consoleBungeeCommand;
@ -43,6 +36,7 @@ public class AliasObjekt {
public List<String> consoleMessages; public List<String> consoleMessages;
public AliasObjekt(Boolean aliasEnable, public AliasObjekt(Boolean aliasEnable,
List<String> aliasList,
Boolean permNecessary, Boolean permNecessary,
Boolean costEnable, Boolean costEnable,
@ -55,11 +49,6 @@ public class AliasObjekt {
List<String> command, List<String> command,
Boolean messageEnable, Boolean messageEnable,
List<String> messages, List<String> messages,
Boolean textBuilder,
String hover,
Boolean clickEvent,
String action,
String actionValue,
Boolean adminEnable, Boolean adminEnable,
String adminPermission, String adminPermission,
@ -69,11 +58,6 @@ public class AliasObjekt {
List<String> adminCommands, List<String> adminCommands,
Boolean adminMessageEnable, Boolean adminMessageEnable,
List<String> adminMessages, List<String> adminMessages,
Boolean adminTextBuilder,
String adminHover,
Boolean adminClickEvent,
String adminAction,
String adminActionValue,
Boolean consoleEnable, Boolean consoleEnable,
Boolean consoleCommandEnable, Boolean consoleCommandEnable,
@ -82,6 +66,7 @@ public class AliasObjekt {
Boolean consoleMessageEnable, Boolean consoleMessageEnable,
List<String> consoleMessages) { List<String> consoleMessages) {
this.aliasEnable = aliasEnable; this.aliasEnable = aliasEnable;
this.aliasList=aliasList;
this.permNecessary = permNecessary; this.permNecessary = permNecessary;
this.costEnable = costEnable; this.costEnable = costEnable;
@ -94,11 +79,6 @@ public class AliasObjekt {
this.command = command; this.command = command;
this.messageEnable = messageEnable; this.messageEnable = messageEnable;
this.messages = messages; this.messages = messages;
this.textBuilder = textBuilder;
this.hover = hover;
this.clickEvent = clickEvent;
this.action = action;
this.actionValue = actionValue;
this.adminEnable = adminEnable; this.adminEnable = adminEnable;
this.adminPermission = adminPermission; this.adminPermission = adminPermission;
this.adminCommandEnable = adminCommandEnable; this.adminCommandEnable = adminCommandEnable;
@ -107,11 +87,7 @@ public class AliasObjekt {
this.adminCommands = adminCommands; this.adminCommands = adminCommands;
this.adminMessageEnable = adminMessageEnable; this.adminMessageEnable = adminMessageEnable;
this.adminMessages = adminMessages; this.adminMessages = adminMessages;
this.adminTextBuilder = adminTextBuilder;
this.adminHover = adminHover;
this.adminClickEvent = adminClickEvent;
this.adminAction = adminAction;
this.adminActionValue = adminActionValue;
this.consoleEnable = consoleEnable; this.consoleEnable = consoleEnable;
this.consoleCommandEnable = consoleCommandEnable; this.consoleCommandEnable = consoleCommandEnable;

View File

@ -2,14 +2,12 @@ package net.t2code.alias.Spigot.system;
import net.t2code.alias.Spigot.Main; import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.cmdManagement.AliasCmdExecuter; import net.t2code.alias.Spigot.cmdManagement.AliasCmdExecuter;
import net.t2code.alias.Spigot.config.config.CreateConfig; import net.t2code.alias.Spigot.config.config.*;
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.languages.LanguagesCreate; import net.t2code.alias.Spigot.config.languages.LanguagesCreate;
import net.t2code.alias.Spigot.config.languages.SelectMessages; import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.alias.Util; import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; 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 net.t2code.lib.Spigot.Lib.update.UpdateAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -37,24 +35,39 @@ public class Load {
CreateExampleAliasConfig.configCreate(); CreateExampleAliasConfig.configCreate();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}try {
CreateExampleSubAliasConfig.configCreate();
} catch (Exception e) {
e.printStackTrace();
} }
} }
try { try {
plugin.saveResource("Alias/X_aliasDeclaration_X.yml",true); plugin.saveResource("Alias/X_aliasDeclaration_X.yml",true);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}try {
plugin.saveResource("SubAlias/X_subaliasDeclaration_X.yml",true);
} catch (Exception e) {
e.printStackTrace();
} }
CreateConfig.configCreate(); CreateConfig.configCreate();
LanguagesCreate.langCreate(); LanguagesCreate.langCreate();
SelectConfig.onSelect(); SelectConfig.onSelect();
SelectMessages.onSelect(Util.getPrefix()); SelectMessages.onSelect(Util.getPrefix());
SelectAlias.onSelect(); SelectAlias.onSelect();
SelectSubAlias.onSelect();
if (SelectConfig.Bungee) { if (SelectConfig.Bungee) {
Main.plugin.getServer().getMessenger().registerOutgoingPluginChannel(Main.plugin, "BungeeCord"); Main.plugin.getServer().getMessenger().registerOutgoingPluginChannel(Main.plugin, "BungeeCord");
Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "t2codealias:bungee"); Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "t2codealias:bungee");
} }
AliasRegisterPermissions.onPermRegister(); 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());
} }
} }