ultimate-example/src/main/java/me/map/example/command/TestCommand.java
2022-07-20 18:18:45 +02:00

72 lines
2.2 KiB
Java

package me.map.example.command;
import me.map.example.Example;
import me.map.ultimatekingdom.API.KingdomSettings;
import me.map.ultimatekingdom.API.UltimateKingdom;
import me.map.ultimatekingdom.API.objects.KingdomPlayer;
import me.map.ultimatekingdom.API.objects.PluginCommands;
import me.map.ultimatekingdom.API.settings.BooleanSetting;
import me.map.ultimatekingdom.API.settings.Setting;
import me.map.ultimatekingdom.UltimateKingdomPlugin;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class TestCommand extends PluginCommands {
private final Example main;
public TestCommand(Example main) {
super("testcommand", "kingdom.admin", false, "<player>");
this.main = main;
this.setDescription(UltimateKingdom.translate(false, "test_command"));
//this.setDescription("test commando");
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length != 1) {
return false;
}
final String username = args[0];
UUID uuid = UltimateKingdom.findUUID(username);
// result uuid with username or null
if (uuid == null) {
UltimateKingdom.send(sender, UltimateKingdom.translate("noPlayer"));
return true;
}
final KingdomPlayer user = UltimateKingdom.Players().getPlayer(uuid);
BooleanSetting setting = KingdomSettings.kingdomplayer_is_mod;
setting.setBoolean(Boolean.TRUE);
user.setSetting(setting);
return true;
}
@Override
public List<String> tabcomplete(CommandSender sender, String[] args) {
if (!sender.hasPermission(this.getPermission())) return new ArrayList<>();
if (args.length == 2) {
return Bukkit.getOnlinePlayers().stream().filter(p -> p != sender).filter(p -> p.getName().regionMatches(true, 0, args[1], 0, args[1].length())).map(HumanEntity::getName).collect(Collectors.toList());
}
return new ArrayList<>();
}
}