Skip to content

Commit

Permalink
Hello brigadier
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 5, 2024
1 parent 93ad429 commit ed27474
Show file tree
Hide file tree
Showing 40 changed files with 2,146 additions and 1,663 deletions.
11 changes: 8 additions & 3 deletions src/main/java/xyz/nifeather/morph/MorphPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.nifeather.morph;

import com.ticxo.modelengine.api.ModelEngineAPI;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
Expand All @@ -9,7 +10,7 @@
import org.bukkit.scoreboard.Scoreboard;
import org.jetbrains.annotations.ApiStatus;
import xyz.nifeather.morph.abilities.AbilityManager;
import xyz.nifeather.morph.commands.MorphCommandManager;
import xyz.nifeather.morph.commands.*;
import xyz.nifeather.morph.config.MorphConfigManager;
import xyz.nifeather.morph.events.*;
import xyz.nifeather.morph.interfaces.IManagePlayerData;
Expand All @@ -32,7 +33,6 @@
import xyz.nifeather.morph.storage.skill.SkillsConfigurationStoreNew;
import xyz.nifeather.morph.transforms.Transformer;
import xyz.nifeather.morph.updates.UpdateHandler;
import xiamomc.pluginbase.Command.CommandHelper;
import xiamomc.pluginbase.Messages.MessageStore;
import xiamomc.pluginbase.XiaMoJavaPlugin;

Expand Down Expand Up @@ -68,7 +68,7 @@ public String getNameSpace()
return getMorphNameSpace();
}

private CommandHelper<MorphPlugin> cmdHelper;
private MorphCommandManager cmdHelper;

private MorphManager morphManager;

Expand Down Expand Up @@ -234,6 +234,11 @@ public void onEnable()

mirrorProcessor = new InteractionMirrorProcessor();

// Commands
var lifecycleManager = this.getLifecycleManager();
lifecycleManager.registerEventHandler(LifecycleEvents.COMMANDS, event ->
cmdHelper.register(event));

//注册EventProcessor
this.schedule(() ->
{
Expand Down
110 changes: 80 additions & 30 deletions src/main/java/xyz/nifeather/morph/commands/AnimationCommand.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package xyz.nifeather.morph.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import xiamomc.pluginbase.Annotations.Resolved;
import xiamomc.pluginbase.Command.IPluginCommand;
import xiamomc.pluginbase.Messages.FormattableMessage;
import xyz.nifeather.morph.MorphManager;
import xyz.nifeather.morph.MorphPluginObject;
import xyz.nifeather.morph.commands.brigadier.IConvertibleBrigadier;
import xyz.nifeather.morph.messages.CommandStrings;
import xyz.nifeather.morph.messages.EmoteStrings;
import xyz.nifeather.morph.messages.HelpStrings;
import xyz.nifeather.morph.messages.MessageUtils;
import xyz.nifeather.morph.misc.gui.AnimSelectScreenWrapper;

import java.util.List;
import java.util.concurrent.CompletableFuture;

public class AnimationCommand extends MorphPluginObject implements IPluginCommand
public class AnimationCommand extends MorphPluginObject implements IConvertibleBrigadier
{
@Override
public String getCommandName()
public String name()
{
return "play-action";
}
Expand All @@ -31,69 +36,114 @@ public FormattableMessage getHelpMessage()
return HelpStrings.animationDescription();
}

@Override
public boolean register(Commands dispatcher)
{
dispatcher.register(
Commands.literal(name())
.requires(this::checkPermission)
.executes(this::executeOpenGui)
.then(
Commands.argument("action", StringArgumentType.greedyString())
.suggests(this::suggests)
.executes(this::execWithArg)
)
.build()
);

return IConvertibleBrigadier.super.register(dispatcher);
}

@Resolved
private MorphManager morphManager;

@Override
public List<String> onTabComplete(List<String> args, CommandSender source)
public @NotNull CompletableFuture<Suggestions> suggests(CommandContext<CommandSourceStack> context, SuggestionsBuilder suggestionsBuilder)
{
var source = context.getSource().getExecutor();

if (!(source instanceof Player player))
return List.of("nil");
return CompletableFuture.completedFuture(suggestionsBuilder.build());

var state = morphManager.getDisguiseStateFor(player);
if (state == null) return List.of();

if (args.size() >= 2) return List.of();
if (state == null) return CompletableFuture.completedFuture(suggestionsBuilder.build());

var animations = state.getProvider()
.getAnimationProvider()
.getAnimationSetFor(state.getDisguiseIdentifier())
.getAvailableAnimationsForClient();
.getAnimationProvider()
.getAnimationSetFor(state.getDisguiseIdentifier())
.getAvailableAnimationsForClient();

var arg = args.get(0);
return animations.stream().filter(id -> id.startsWith(arg)).toList();
var name = suggestionsBuilder.getRemainingLowerCase();
return CompletableFuture.supplyAsync(() ->
{
animations.stream().filter(id -> id.startsWith(name))
.forEach(suggestionsBuilder::suggest);

return suggestionsBuilder.build();
});
}

@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
public int executeOpenGui(CommandContext<CommandSourceStack> context)
{
var commandSender = context.getSource().getExecutor();

if (!(commandSender instanceof Player player))
return true;
return Command.SINGLE_SUCCESS;

var state = morphManager.getDisguiseStateFor(player);
if (state == null)
{
player.sendMessage(MessageUtils.prefixes(player, CommandStrings.notDisguised()));
return true;
return Command.SINGLE_SUCCESS;
}

var animationSet = state.getProvider()
.getAnimationProvider()
.getAnimationSetFor(state.getDisguiseIdentifier());

if (args.length == 0)
{
var screen = new AnimSelectScreenWrapper(state, animationSet.getAvailableAnimationsForClient());
screen.show();
var screen = new AnimSelectScreenWrapper(state, animationSet.getAvailableAnimationsForClient());
screen.show();

return Command.SINGLE_SUCCESS;
}

//player.sendMessage(MessageUtils.prefixes(player, CommandStrings.listNoEnoughArguments()));
return true;
private int execWithArg(CommandContext<CommandSourceStack> context)
{
var commandSender = context.getSource().getExecutor();

if (!(commandSender instanceof Player player))
return Command.SINGLE_SUCCESS;

var state = morphManager.getDisguiseStateFor(player);
if (state == null)
{
player.sendMessage(MessageUtils.prefixes(player, CommandStrings.notDisguised()));
return Command.SINGLE_SUCCESS;
}

var animationId = args[0];
var animationSet = state.getProvider()
.getAnimationProvider()
.getAnimationSetFor(state.getDisguiseIdentifier());

String animationId = StringArgumentType.getString(context, "action");

var animations = animationSet.getAvailableAnimationsForClient();

if (!animations.contains(animationId))
{
player.sendMessage(MessageUtils.prefixes(player, CommandStrings.noSuchAnimation()));
return true;
return Command.SINGLE_SUCCESS;
}

var sequencePair = animationSet.sequenceOf(animationId);
if (!state.tryScheduleSequence(animationId, sequencePair.left(), sequencePair.right()))
player.sendMessage(MessageUtils.prefixes(player, EmoteStrings.notAvailable()));

return false;
return Command.SINGLE_SUCCESS;
}

@Override
public boolean checkPermission(CommandSourceStack cmdSourceStack)
{
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package xyz.nifeather.morph.commands;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xiamomc.pluginbase.Messages.FormattableMessage;
import xyz.nifeather.morph.MorphPlugin;

import java.util.List;

public interface IHaveFormattableHelp
{
@Nullable
public String permission();

@NotNull
public String name();

public FormattableMessage getHelpMessage();

default public List<FormattableMessage> getNotes()
{
return List.of(new FormattableMessage(MorphPlugin.getMorphNameSpace(), "_", "_"));
}
}
Loading

0 comments on commit ed27474

Please sign in to comment.