Compare commits
No commits in common. "76ae3103de2f8566486907004952713ca818a8f4" and "4dba5f3c41566dd11c5061fb23f564cd88a5f7a7" have entirely different histories.
76ae3103de
...
4dba5f3c41
|
|
@ -58,7 +58,7 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||
}
|
||||
|
||||
void loadCommands() {
|
||||
Reflections reflections = new Reflections("com.alttd.essentia.commands");
|
||||
Reflections reflections = new Reflections("com.alttd.essentia.commands.list");
|
||||
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(EssentiaCommand.class).asClass());
|
||||
|
||||
LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
package com.alttd.essentia.commands;
|
||||
|
||||
import com.alttd.essentia.util.Pair;
|
||||
import com.mojang.brigadier.Message;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface EssentiaArgument {
|
||||
|
||||
default <S> CompletableFuture<Suggestions> completedFuture(SuggestionsBuilder builder, Collection<String> possibleValues) {
|
||||
String remaining = builder.getRemaining().toLowerCase();
|
||||
for (String str : possibleValues) {
|
||||
if (str.toLowerCase().startsWith(remaining)) {
|
||||
builder.suggest(StringArgumentType.escapeIfRequired(str));
|
||||
}
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(
|
||||
builder.build()
|
||||
);
|
||||
}
|
||||
|
||||
default <S> CompletableFuture<Suggestions> completedFuturePair(SuggestionsBuilder builder, Collection<Pair<String, Message>> possibleValues) {
|
||||
String remaining = builder.getRemaining().toLowerCase();
|
||||
for (Pair<String, Message> pair : possibleValues) {
|
||||
String str = pair.x();
|
||||
if (str.toLowerCase().startsWith(remaining)) {
|
||||
builder.suggest(StringArgumentType.escapeIfRequired(str), pair.y());
|
||||
}
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(
|
||||
builder.build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.commands.argumement.EnchantmentArgument;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
|
|
@ -8,7 +9,6 @@ import io.papermc.paper.command.brigadier.CommandSourceStack;
|
|||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Material;
|
||||
|
|
@ -33,7 +33,7 @@ public class EnchantCommand implements EssentiaCommand {
|
|||
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||
)
|
||||
.then(
|
||||
Commands.argument("enchantment", ArgumentTypes.resource(RegistryKey.ENCHANTMENT))
|
||||
Commands.argument("enchantment", new EnchantmentArgument())
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
// TODO -- FINISH ME - messages and options?
|
||||
public class SpawnMobCommand implements EssentiaCommand {
|
||||
|
||||
@Override
|
||||
public String commandName() {
|
||||
return "spawnmob";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName())
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||
)
|
||||
.then(
|
||||
Commands.argument("entity", ArgumentTypes.resource(RegistryKey.ENTITY_TYPE))
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||
.executes((source) -> {
|
||||
EntityType entityType = source.getArgument("entity", EntityType.class);
|
||||
execute(source.getSource().getSender(), (Player) source.getSource().getSender(), entityType);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target, EntityType entityType) { // TODO - implement player info
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
target.getWorld().spawn(target.getLocation(), entityType.getEntityClass(), CreatureSpawnEvent.SpawnReason.COMMAND);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.alttd.essentia.commands.argumement;
|
||||
|
||||
import com.mojang.brigadier.Message;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
|
||||
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class EnchantmentArgument implements CustomArgumentType.Converted<Enchantment, String> {
|
||||
|
||||
@Override
|
||||
public @NotNull Enchantment convert(String nativeType) throws CommandSyntaxException {
|
||||
try {
|
||||
return Enchantment.getByKey(NamespacedKey.minecraft(nativeType));
|
||||
} catch (Exception e) {
|
||||
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid enchantment %s!".formatted(nativeType), NamedTextColor.RED));
|
||||
|
||||
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArgumentType<String> getNativeType() {
|
||||
return StringArgumentType.word();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
for (Enchantment enchantment : RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT)) {
|
||||
builder.suggest(enchantment.getKey().value());
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(
|
||||
builder.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.alttd.essentia.commands.argumement;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaArgument;
|
||||
import com.mojang.brigadier.Message;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
|
@ -16,11 +15,9 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class EquipmentArgumentType implements CustomArgumentType.Converted<EquipmentSlot, String>, EssentiaArgument {
|
||||
public class EquipmentArgumentType implements CustomArgumentType.Converted<EquipmentSlot, String> {
|
||||
|
||||
@Override
|
||||
public @NotNull EquipmentSlot convert(String nativeType) throws CommandSyntaxException {
|
||||
|
|
@ -40,12 +37,13 @@ public class EquipmentArgumentType implements CustomArgumentType.Converted<Equip
|
|||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
Collection<String> possibleValues = new ArrayList<>();
|
||||
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
|
||||
possibleValues.add(equipmentSlot.name().toLowerCase());
|
||||
builder.suggest(equipmentSlot.name().toLowerCase());
|
||||
}
|
||||
|
||||
return completedFuture(builder, possibleValues);
|
||||
return CompletableFuture.completedFuture(
|
||||
builder.build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
package com.alttd.essentia.commands.argumement;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaArgument;
|
||||
import com.alttd.essentia.util.Pair;
|
||||
import com.mojang.brigadier.Message;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
|
||||
|
|
@ -20,11 +17,9 @@ import org.bukkit.OfflinePlayer;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class OfflinePlayerCompletingArgument implements CustomArgumentType.Converted<OfflinePlayer, String>, EssentiaArgument {
|
||||
public class OfflinePlayerCompletingArgument implements CustomArgumentType.Converted<OfflinePlayer, String> {
|
||||
|
||||
@Override
|
||||
public @NotNull OfflinePlayer convert(String nativeType) throws CommandSyntaxException {
|
||||
|
|
@ -44,11 +39,12 @@ public class OfflinePlayerCompletingArgument implements CustomArgumentType.Conve
|
|||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
Collection<Pair<String, Message>> possibleValues = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
possibleValues.add(new Pair<>(player.getName(), MessageComponentSerializer.message().serialize(player.displayName())));
|
||||
builder.suggest(player.getName(), MessageComponentSerializer.message().serialize(player.displayName()));
|
||||
}
|
||||
|
||||
return completedFuturePair(builder, possibleValues);
|
||||
return CompletableFuture.completedFuture(
|
||||
builder.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.alttd.essentia.commands.argumement;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaArgument;
|
||||
import com.mojang.brigadier.Message;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
|
@ -16,11 +15,9 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||
import org.bukkit.WeatherType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class WeatherArgument implements CustomArgumentType.Converted<WeatherType, String>, EssentiaArgument {
|
||||
public class WeatherArgument implements CustomArgumentType.Converted<WeatherType, String> {
|
||||
|
||||
@Override
|
||||
public @NotNull WeatherType convert(String nativeType) throws CommandSyntaxException {
|
||||
|
|
@ -40,11 +37,12 @@ public class WeatherArgument implements CustomArgumentType.Converted<WeatherType
|
|||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
Collection<String> possibleValues = new ArrayList<>();
|
||||
for (WeatherType weatherType : WeatherType.values()) {
|
||||
possibleValues.add(weatherType.name().toLowerCase());
|
||||
builder.suggest(weatherType.name().toLowerCase());
|
||||
}
|
||||
|
||||
return completedFuture(builder, possibleValues);
|
||||
return CompletableFuture.completedFuture(
|
||||
builder.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package com.alttd.essentia.util;
|
||||
|
||||
public record Pair<X, Y>(X x, Y y) {
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user