1. trial version for SubCommands / Sub TabComplete
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.t2code.alias.Spigot.cmdManagement;
|
||||
|
||||
import net.t2code.alias.Spigot.Main;
|
||||
import net.t2code.alias.Spigot.config.languages.SelectMessages;
|
||||
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -9,6 +10,7 @@ import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -60,6 +62,11 @@ public class AliasCmdExecuter implements CommandExecutor, TabCompleter {
|
||||
List<String> list = new ArrayList<>();
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
send.debugmsg(Main.plugin, "------------");
|
||||
send.debugmsg(Main.plugin, "tab a: " + 0);
|
||||
send.debugmsg(Main.plugin, "tab a: " + args.length);
|
||||
send.debugmsg(Main.plugin, "tab a: " + Arrays.toString(args));
|
||||
send.debugmsg(Main.plugin, "tab a: " + arg1.toString());
|
||||
if (args.length == 1) {
|
||||
for (String command : arg1.keySet()) {
|
||||
Boolean passend = true;
|
||||
|
@@ -0,0 +1,288 @@
|
||||
package net.t2code.alias.Spigot.cmdManagement;
|
||||
|
||||
import net.t2code.alias.Spigot.config.config.SelectConfig;
|
||||
import net.t2code.alias.Spigot.config.languages.SelectMessages;
|
||||
import net.t2code.alias.Spigot.objects.AliasObject;
|
||||
import net.t2code.alias.Spigot.objects.SubAliasObject;
|
||||
import net.t2code.alias.Spigot.system.BCommandSenderReciver;
|
||||
import net.t2code.alias.Util;
|
||||
import net.t2code.lib.Spigot.Lib.commands.Cmd;
|
||||
import net.t2code.lib.Spigot.Lib.eco.Eco;
|
||||
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.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ExecuteAlias {
|
||||
private static final String prefix = Util.getPrefix();
|
||||
|
||||
protected static void aliasPlayer(CommandSender sender, AliasObject aliasObject, String alias) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (aliasObject.adminEnable) {
|
||||
if (player.hasPermission(aliasObject.adminPermission)) {
|
||||
if (aliasObject.adminCommandEnable) {
|
||||
aliasAdminCommand(aliasObject, player);
|
||||
}
|
||||
if (aliasObject.adminMessageEnable) {
|
||||
aliasAdminMessage(aliasObject, player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (aliasObject.permNecessary) {
|
||||
if (!(player.hasPermission("t2code.alias.use." + alias.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) {
|
||||
send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" + alias.toLowerCase())
|
||||
.replace("[perm]", "t2code.alias.use." + alias.toLowerCase()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (aliasObject.costEnable) {
|
||||
if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) {
|
||||
if (!Eco.moneyRemove(prefix, player, aliasObject.costPrice)) {
|
||||
send.player(player, SelectMessages.noMoney);
|
||||
return;
|
||||
}
|
||||
if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", aliasObject.costPrice.toString()));
|
||||
}
|
||||
}
|
||||
if (aliasObject.commandEnable) {
|
||||
aliasCommand(aliasObject, player);
|
||||
}
|
||||
if (aliasObject.messageEnable) {
|
||||
aliasMessage(aliasObject, player);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void subAliasPlayer(CommandSender sender, SubAliasObject aliasObject, String alias) {
|
||||
if (!aliasObject.subAliasEnable) {
|
||||
send.sender(sender, SelectMessages.aliasDisabled);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (aliasObject.adminEnable) {
|
||||
if (player.hasPermission(aliasObject.adminPermission)) {
|
||||
if (aliasObject.adminCommandEnable) {
|
||||
subAliasAdminCommand(aliasObject, player);
|
||||
}
|
||||
if (aliasObject.adminMessageEnable) {
|
||||
subAliasAdminMessage(aliasObject, player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (aliasObject.permNecessary) {
|
||||
if (!(player.hasPermission("t2code.alias.use.subalias." + alias.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) {
|
||||
send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" + alias.toLowerCase())
|
||||
.replace("[perm]", "t2code.alias.subalias.use." + alias.toLowerCase()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (aliasObject.costEnable) {
|
||||
if (!(aliasObject.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass"))) {
|
||||
if (!Eco.moneyRemove(prefix, player, aliasObject.costPrice)) {
|
||||
send.player(player, SelectMessages.noMoney);
|
||||
return;
|
||||
}
|
||||
if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", aliasObject.costPrice.toString()));
|
||||
}
|
||||
}
|
||||
if (aliasObject.commandEnable) {
|
||||
subAliasCommand(aliasObject, player);
|
||||
}
|
||||
if (aliasObject.messageEnable) {
|
||||
subAliasMessage(aliasObject, player);
|
||||
}
|
||||
} else {
|
||||
if (aliasObject.consoleEnable) {
|
||||
subAliasConsole(aliasObject, sender);
|
||||
} else send.sender(sender, SelectMessages.onlyForPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void aliasConsole(AliasObject alias, CommandSender sender, String prefix) {
|
||||
if (alias.consoleCommandEnable) {
|
||||
for (String cmd : alias.consoleCommands) {
|
||||
if (alias.consoleBungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
BCommandSenderReciver.sendToBungee(sender, cmd, true);
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
Cmd.console(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (alias.consoleMessageEnable) {
|
||||
for (String msg : alias.consoleMessages) {
|
||||
send.console(Replace.replace(prefix, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void subAliasConsole(SubAliasObject alias, CommandSender sender) {
|
||||
if (alias.consoleCommandEnable) {
|
||||
for (String cmd : alias.consoleCommands) {
|
||||
if (alias.consoleBungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
BCommandSenderReciver.sendToBungee(sender, cmd, true);
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
Cmd.console(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (alias.consoleMessageEnable) {
|
||||
for (String msg : alias.consoleMessages) {
|
||||
send.console(Replace.replace(prefix, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void aliasAdminCommand(AliasObject alias, Player player) {
|
||||
for (String cmd : alias.adminCommands) {
|
||||
if (alias.adminBungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), alias.adminCommandAsConsole);
|
||||
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (alias.adminCommandAsConsole) {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void subAliasAdminCommand(SubAliasObject alias, Player player) {
|
||||
for (String cmd : alias.adminCommands) {
|
||||
if (alias.adminBungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), alias.adminCommandAsConsole);
|
||||
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (alias.adminCommandAsConsole) {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void aliasAdminMessage(AliasObject alias, Player player) {
|
||||
for (String msg : alias.adminMessages) {
|
||||
String text;
|
||||
String hover;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(prefix, player, replacePlayer(msg, player));
|
||||
} else {
|
||||
text = Replace.replace(prefix, replacePlayer(msg, player));
|
||||
}
|
||||
send.player(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void subAliasAdminMessage(SubAliasObject alias, Player player) {
|
||||
for (String msg : alias.adminMessages) {
|
||||
String text;
|
||||
String hover;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(prefix, player, replacePlayer(msg, player));
|
||||
} else {
|
||||
text = Replace.replace(prefix, replacePlayer(msg, player));
|
||||
}
|
||||
send.player(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void aliasCommand(AliasObject alias, Player player) {
|
||||
for (String cmd : alias.command) {
|
||||
if (alias.bungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), alias.commandAsConsole);
|
||||
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (alias.commandAsConsole) {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void subAliasCommand(SubAliasObject alias, Player player) {
|
||||
for (String cmd : alias.command) {
|
||||
if (alias.bungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), alias.commandAsConsole);
|
||||
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (alias.commandAsConsole) {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void aliasMessage(AliasObject alias, Player player) {
|
||||
for (String msg : alias.messages) {
|
||||
String text;
|
||||
String hover;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(prefix, player, replacePlayer(msg, player));
|
||||
} else {
|
||||
text = Replace.replace(prefix, replacePlayer(msg, player));
|
||||
}
|
||||
send.player(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void subAliasMessage(SubAliasObject alias, Player player) {
|
||||
for (String msg : alias.messages) {
|
||||
String text;
|
||||
String hover;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(prefix, player, replacePlayer(msg, player));
|
||||
} else {
|
||||
text = Replace.replace(prefix, replacePlayer(msg, player));
|
||||
}
|
||||
send.player(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static String replacePlayer(String s, Player player) {
|
||||
return s.replace("[player]", player.getName());
|
||||
}
|
||||
}
|
@@ -1,28 +1,16 @@
|
||||
package net.t2code.alias.Spigot.cmdManagement;
|
||||
|
||||
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.Spigot.objects.AliasObject;
|
||||
import net.t2code.alias.Spigot.objects.SubAliasObject;
|
||||
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.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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class RegisterCommands extends Command implements TabCompleter {
|
||||
public class RegisterCommands extends Command {
|
||||
private String alias;
|
||||
private String prefix = Util.getPrefix();
|
||||
|
||||
@@ -33,7 +21,8 @@ public class RegisterCommands extends Command implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
AliasObjekt alias = Main.aliasHashMap.get(this.alias);
|
||||
send.debugmsg(Main.plugin, "tabevent");
|
||||
AliasObject alias = Main.aliasHashMap.get(this.alias);
|
||||
|
||||
if (!alias.aliasEnable) {
|
||||
send.sender(sender, SelectMessages.aliasDisabled);
|
||||
@@ -41,19 +30,20 @@ public class RegisterCommands extends Command implements TabCompleter {
|
||||
}
|
||||
if (args.length == 0) {
|
||||
if (sender instanceof Player) {
|
||||
exPlayer(sender, alias);
|
||||
ExecuteAlias.aliasPlayer(sender, alias, this.alias);
|
||||
} else {
|
||||
if (alias.consoleEnable) {
|
||||
console(alias, sender, prefix);
|
||||
ExecuteAlias.aliasConsole(alias, sender, prefix);
|
||||
} else send.sender(sender, SelectMessages.onlyForPlayer);
|
||||
}
|
||||
} else {
|
||||
if (!Main.allForSubAliases.contains(this.alias)) return false;
|
||||
for (String sals : Main.allSubAliases) {
|
||||
SubAliasObjekt sal = Main.subAliasHashMap.get(sals);
|
||||
if (args.length == sal.subAliasArg) {
|
||||
SubAliasObject sal = Main.subAliasHashMap.get(sals);
|
||||
if (args.length == sal.subAliasArg + 1) {
|
||||
for (String al : sal.subAliasList) {
|
||||
if (args[sal.subAliasArg].toLowerCase().equals(al)) {
|
||||
RegisterSubAliasCommands.execute(sender, sal, al);
|
||||
ExecuteAlias.subAliasPlayer(sender, sal, al);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,156 +51,5 @@ public class RegisterCommands extends Command implements TabCompleter {
|
||||
}
|
||||
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) {
|
||||
if (SelectConfig.Bungee) {
|
||||
if (alias.adminCommandAsConsole) {
|
||||
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true);
|
||||
} else BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
|
||||
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (alias.adminCommandAsConsole) {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void adminMessage(AliasObjekt alias, Player player, String prefix) {
|
||||
for (String msg : alias.adminMessages) {
|
||||
String text;
|
||||
String hover;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(prefix, player, replacePlayer(msg, player));
|
||||
} else {
|
||||
text = Replace.replace(prefix, replacePlayer(msg, player));
|
||||
}
|
||||
send.player(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void command(AliasObjekt alias, Player player) {
|
||||
for (String cmd : alias.command) {
|
||||
if (alias.bungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
if (alias.commandAsConsole) {
|
||||
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true);
|
||||
} else BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
|
||||
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (alias.commandAsConsole) {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void message(AliasObjekt alias, Player player, String prefix) {
|
||||
for (String msg : alias.messages) {
|
||||
String text;
|
||||
String hover;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(prefix, player, replacePlayer(msg, player));
|
||||
} else {
|
||||
text = Replace.replace(prefix, replacePlayer(msg, player));
|
||||
}
|
||||
send.player(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void console(AliasObjekt alias, CommandSender sender, String prefix) {
|
||||
if (alias.consoleCommandEnable) {
|
||||
for (String cmd : alias.consoleCommands) {
|
||||
if (alias.consoleBungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
BCommandSenderReciver.sendToBungee(sender, cmd, true);
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
Cmd.console(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (alias.consoleMessageEnable) {
|
||||
for (String msg : alias.consoleMessages) {
|
||||
send.console(Replace.replace(prefix, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String replacePlayer(String s, Player player) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,166 +0,0 @@
|
||||
package net.t2code.alias.Spigot.cmdManagement;
|
||||
|
||||
import net.t2code.alias.Spigot.config.config.SelectConfig;
|
||||
import net.t2code.alias.Spigot.config.languages.SelectMessages;
|
||||
import net.t2code.alias.Spigot.objects.SubAliasObjekt;
|
||||
import net.t2code.alias.Spigot.system.BCommandSenderReciver;
|
||||
import net.t2code.alias.Util;
|
||||
import net.t2code.lib.Spigot.Lib.commands.Cmd;
|
||||
import net.t2code.lib.Spigot.Lib.eco.Eco;
|
||||
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.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RegisterSubAliasCommands {
|
||||
private static String prefix = Util.getPrefix();
|
||||
|
||||
|
||||
|
||||
public static void execute(CommandSender sender, SubAliasObjekt alias, String aliasString) {
|
||||
if (!alias.subAliasEnable) {
|
||||
send.sender(sender, SelectMessages.aliasDisabled);
|
||||
return ;
|
||||
}
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
|
||||
if (alias.permNecessary) {
|
||||
if (!(player.hasPermission("t2code.alias.use.subalias." + aliasString.toLowerCase()) || player.hasPermission("t2code.alias.admin"))) {
|
||||
send.player(player, SelectMessages.noPermissionForCommand.replace("[cmd]", "/" +aliasString.toLowerCase())
|
||||
.replace("[perm]", "t2code.alias.subalias.use." + aliasString.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);
|
||||
}
|
||||
} else {
|
||||
if (alias.consoleEnable) {
|
||||
console(alias, sender, prefix);
|
||||
} else send.sender(sender, SelectMessages.onlyForPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void adminCommand(SubAliasObjekt alias, Player player) {
|
||||
for (String cmd : alias.adminCommands) {
|
||||
if (alias.adminBungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
if (alias.adminCommandAsConsole) {
|
||||
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true);
|
||||
} else BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
|
||||
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (alias.adminCommandAsConsole) {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void adminMessage(SubAliasObjekt alias, Player player, String prefix) {
|
||||
for (String msg : alias.adminMessages) {
|
||||
String text;
|
||||
String hover;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(prefix, player, replacePlayer(msg, player));
|
||||
} else {
|
||||
text = Replace.replace(prefix, replacePlayer(msg, player));
|
||||
}
|
||||
send.player(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void command(SubAliasObjekt alias, Player player) {
|
||||
for (String cmd : alias.command) {
|
||||
if (alias.bungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
if (alias.commandAsConsole) {
|
||||
BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), true);
|
||||
} else BCommandSenderReciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
|
||||
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
if (alias.commandAsConsole) {
|
||||
Cmd.console(cmd.replace("[player]", player.getName()));
|
||||
} else {
|
||||
Cmd.player(player, cmd.replace("[player]", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void message(SubAliasObjekt alias, Player player, String prefix) {
|
||||
for (String msg : alias.messages) {
|
||||
String text;
|
||||
String hover;
|
||||
if (PluginCheck.papi()) {
|
||||
text = Replace.replace(prefix, player, replacePlayer(msg, player));
|
||||
} else {
|
||||
text = Replace.replace(prefix, replacePlayer(msg, player));
|
||||
}
|
||||
send.player(player, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void console(SubAliasObjekt alias, CommandSender sender, String prefix) {
|
||||
if (alias.consoleCommandEnable) {
|
||||
for (String cmd : alias.consoleCommands) {
|
||||
if (alias.consoleBungeeCommand) {
|
||||
if (SelectConfig.Bungee) {
|
||||
BCommandSenderReciver.sendToBungee(sender, cmd, true);
|
||||
} else {
|
||||
send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
|
||||
}
|
||||
} else {
|
||||
Cmd.console(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (alias.consoleMessageEnable) {
|
||||
for (String msg : alias.consoleMessages) {
|
||||
send.console(Replace.replace(prefix, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String replacePlayer(String s, Player player) {
|
||||
return s.replace("[player]", player.getName());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,49 @@
|
||||
package net.t2code.alias.Spigot.cmdManagement;
|
||||
|
||||
import net.t2code.alias.Spigot.Main;
|
||||
import net.t2code.alias.Spigot.objects.SubAliasObject;
|
||||
import net.t2code.lib.Spigot.Lib.commands.Tab;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.TabCompleteEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TabEvent implements Listener {
|
||||
|
||||
Plugin plugin = Main.plugin;
|
||||
private static HashMap<String, String> arg1 = new HashMap<String, String>();
|
||||
|
||||
@EventHandler
|
||||
public void onTab(TabCompleteEvent e) {
|
||||
String buffer = e.getBuffer();
|
||||
String[] imp = buffer.replace("/", "").split(" ");
|
||||
if (!Main.allAliases.contains(imp[0])) return;
|
||||
if (!Main.allForSubAliases.contains(imp[0])) return;
|
||||
arg1.clear();
|
||||
List<String> list = new ArrayList<>(Collections.emptyList());
|
||||
for (String sals : Main.allSubAliases) {
|
||||
SubAliasObject sal = Main.subAliasHashMap.get(sals);
|
||||
if (!buffer.contains(sal.subAliasFor)) continue;
|
||||
|
||||
String[] im = sal.subAliasFor.split(" ");
|
||||
String input = buffer.replace("/" + im[0] + " ", "");
|
||||
String[] args = input.split(" ", -1);
|
||||
|
||||
for (String al : sal.subAliasList) {
|
||||
arg1.put(al, "t2code.alias.use.subalias." + al.toLowerCase());
|
||||
}
|
||||
int arg = sal.subAliasArg;
|
||||
if (args.length - 1 == arg) {
|
||||
for (String command : sal.subAliasList) {
|
||||
if (Tab.hasPermission(e.getSender(), arg1.get(command)) && Tab.passend(command, args[arg])) {
|
||||
list.add(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
e.setCompletions(list);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user