Create RegisterSubAliasCommands.java
This commit is contained in:
parent
f90ed13bda
commit
156e5c0585
@ -0,0 +1,166 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user