Dieser Commit ist enthalten in:
Ursprung
451c47d3ed
Commit
d810d50d22
@ -0,0 +1,81 @@
|
||||
package de.steamwar.bausystem.features.util;
|
||||
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.luaj.vm2.ast.Str;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Linked
|
||||
public class ItemBindCommand extends SWCommand {
|
||||
|
||||
private static final NamespacedKey KEY = SWUtils.getNamespaceKey("command");
|
||||
|
||||
public ItemBindCommand() {
|
||||
super("item");
|
||||
}
|
||||
|
||||
@Register("bind")
|
||||
public void bind(Player player, @Mapper("command") String... command) {
|
||||
player.sendMessage(command);
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.getPersistentDataContainer().set(KEY, PersistentDataType.STRING, "");
|
||||
|
||||
}
|
||||
|
||||
@Mapper(value = "command", local = true)
|
||||
public TypeMapper<String> getCommandMapper() {
|
||||
Map<String, String[]> commandMap = Bukkit.getCommandAliases();
|
||||
Map<String, String> reverseCommandMap = new HashMap<>();
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
commandMap.forEach((command, aliases) -> {
|
||||
commands.add(command);
|
||||
commands.addAll(Arrays.asList(aliases));
|
||||
|
||||
reverseCommandMap.put(command, command);
|
||||
for (String alias : aliases) {
|
||||
reverseCommandMap.put(alias, command);
|
||||
}
|
||||
});
|
||||
|
||||
return new TypeMapper<String>() {
|
||||
@Override
|
||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
List<String> args = previousArguments.getAll(String.class);
|
||||
|
||||
if (args.isEmpty()) return commands;
|
||||
|
||||
String inputCommand = args.remove(0);
|
||||
String command = reverseCommandMap.get(inputCommand);
|
||||
|
||||
if (command == null) return null;
|
||||
|
||||
PluginCommand pluginCommand = Bukkit.getPluginCommand(command);
|
||||
|
||||
if (pluginCommand == null) return null;
|
||||
|
||||
return pluginCommand.tabComplete(sender, inputCommand, args.toArray(new String[0]));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren