2021-12-21 05:55:23 +01:00
|
|
|
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;
|
2022-06-07 06:33:57 +02:00
|
|
|
import net.t2code.alias.Spigot.objects.AliasObjekt;
|
2021-12-21 05:55:23 +01:00
|
|
|
import net.t2code.alias.Spigot.system.*;
|
2022-01-29 19:08:14 +01:00
|
|
|
import net.t2code.alias.Util;
|
2021-12-21 05:55:23 +01:00
|
|
|
import net.t2code.lib.Spigot.Lib.commands.Cmd;
|
2022-06-07 06:35:12 +02:00
|
|
|
import net.t2code.lib.Spigot.Lib.eco.Eco;
|
2021-12-21 05:55:23 +01:00
|
|
|
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.entity.Player;
|
|
|
|
|
|
|
|
public class RegisterCommands extends Command {
|
|
|
|
private String alias;
|
2022-01-29 19:08:14 +01:00
|
|
|
private String prefix = Util.getPrefix();
|
2021-12-21 05:55:23 +01:00
|
|
|
|
|
|
|
public RegisterCommands(String alias) {
|
|
|
|
super(alias);
|
|
|
|
this.alias = alias;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
2022-06-07 06:33:57 +02:00
|
|
|
AliasObjekt alias = Main.aliasHashMap.get(this.alias);
|
2021-12-21 05:55:23 +01:00
|
|
|
|
2022-06-07 06:33:57 +02:00
|
|
|
if (!alias.aliasEnable) {
|
|
|
|
send.sender(sender, SelectMessages.aliasDisabled);
|
2021-12-21 05:55:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (sender instanceof Player) {
|
|
|
|
Player player = (Player) sender;
|
|
|
|
|
2022-06-07 06:33:57 +02:00
|
|
|
if (alias.adminEnable) {
|
|
|
|
if (player.hasPermission(alias.adminPermission)) {
|
|
|
|
if (alias.adminCommandEnable) {
|
|
|
|
adminCommand(alias, player);
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
2022-06-07 06:33:57 +02:00
|
|
|
if (alias.adminMessageEnable) {
|
|
|
|
adminMessage(alias, player, prefix);
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 06:33:57 +02:00
|
|
|
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()));
|
2021-12-21 05:55:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2022-06-07 06:33:57 +02:00
|
|
|
if (alias.costEnable) {
|
|
|
|
if (!(alias.costAllowBypass && player.hasPermission("t2code.alias.buy.bypass")) ){
|
2022-06-07 06:35:12 +02:00
|
|
|
if (!Eco.moneyRemove(prefix, player, alias.costPrice)) {
|
2022-06-07 06:33:57 +02:00
|
|
|
send.player(player, SelectMessages.noMoney);
|
|
|
|
return true;
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
2022-06-07 06:33:57 +02:00
|
|
|
if (SelectConfig.buyMessage) send.player(player, SelectMessages.buy.replace("[price]", alias.costPrice.toString()));
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
2022-06-07 06:33:57 +02:00
|
|
|
if (alias.commandEnable) {
|
|
|
|
command(alias, player);
|
|
|
|
}
|
|
|
|
if (alias.messageEnable) {
|
|
|
|
message(alias, player, prefix);
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
2022-06-07 06:33:57 +02:00
|
|
|
if (alias.consoleEnable) {
|
|
|
|
console(alias, sender, prefix);
|
|
|
|
} else send.sender(sender, SelectMessages.onlyForPlayer);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2021-12-21 05:55:23 +01:00
|
|
|
|
2022-06-07 06:33:57 +02:00
|
|
|
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.");
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
2022-06-07 06:33:57 +02:00
|
|
|
} 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));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.replace("[player]", sender.getName()), 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.");
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
2022-06-07 06:33:57 +02:00
|
|
|
} else {
|
|
|
|
Cmd.console(cmd.replace("[player]", sender.getName()));
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
2022-06-07 06:33:57 +02:00
|
|
|
|
|
|
|
}
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
2022-06-07 06:33:57 +02:00
|
|
|
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());
|
2021-12-21 05:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|