55 lines
1.8 KiB
Java
55 lines
1.8 KiB
Java
package xyz.etztech.mixtape.commands;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import xyz.etztech.mixtape.Database;
|
|
import xyz.etztech.mixtape.Mixtape;
|
|
import xyz.etztech.mixtape.MixtapeUtil;
|
|
|
|
import java.util.Arrays;
|
|
|
|
public class CommandSlashAlias implements CommandExecutor {
|
|
|
|
Mixtape plugin;
|
|
|
|
public CommandSlashAlias(Mixtape plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
if (!(sender instanceof Player)) {
|
|
sender.sendMessage(ChatColor.RED + "This command is not supported in Console.");
|
|
return true;
|
|
}
|
|
Player player = (Player) sender;
|
|
if (!player.hasPermission("mixtape.alias.command")) {
|
|
player.sendMessage(ChatColor.RED + "You do not have permission to create command aliases.");
|
|
return true;
|
|
}
|
|
|
|
if (args.length < 2) {
|
|
player.sendMessage(ChatColor.RED + "//alias <alias> <command>");
|
|
return true;
|
|
}
|
|
|
|
if (MixtapeUtil.isLimited(player)) {
|
|
player.sendMessage(ChatColor.RED + "You have hit your limit of allowed aliases. Delete one and try again.");
|
|
return true;
|
|
}
|
|
|
|
String alias = MixtapeUtil.stripSlash(args[0]);
|
|
|
|
String command = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
|
|
|
Mixtape.getDatabase().insert(player.getUniqueId().toString(), alias, command, Database.AliasType.COMMAND);
|
|
player.sendMessage(ChatColor.GREEN + "Command alias created.");
|
|
|
|
return true;
|
|
}
|
|
}
|