mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancydialogs: Fix dialog type parser
This commit is contained in:
@@ -169,6 +169,8 @@ public class FancyDialogsPlugin extends JavaPlugin implements FancyDialogs {
|
||||
builder.addParameterType(Dialog.class, DialogCommandType.INSTANCE);
|
||||
});
|
||||
|
||||
lampBuilder.exceptionHandler(DialogCommandType.INSTANCE);
|
||||
|
||||
Lamp<BukkitCommandActor> lamp = lampBuilder.build();
|
||||
|
||||
lamp.register(FancyDialogsCMD.INSTANCE);
|
||||
|
||||
@@ -6,11 +6,13 @@ import com.fancyinnovations.fancydialogs.registry.DialogRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import revxrsal.commands.autocomplete.SuggestionProvider;
|
||||
import revxrsal.commands.bukkit.actor.BukkitCommandActor;
|
||||
import revxrsal.commands.bukkit.exception.BukkitExceptionHandler;
|
||||
import revxrsal.commands.exception.InvalidValueException;
|
||||
import revxrsal.commands.node.ExecutionContext;
|
||||
import revxrsal.commands.parameter.ParameterType;
|
||||
import revxrsal.commands.stream.MutableStringStream;
|
||||
|
||||
public class DialogCommandType implements ParameterType<BukkitCommandActor, Dialog> {
|
||||
public class DialogCommandType extends BukkitExceptionHandler implements ParameterType<BukkitCommandActor, Dialog> {
|
||||
|
||||
public static final DialogCommandType INSTANCE = new DialogCommandType();
|
||||
private static final DialogRegistry REGISTRY = FancyDialogsPlugin.get().getDialogRegistry();
|
||||
@@ -28,12 +30,15 @@ public class DialogCommandType implements ParameterType<BukkitCommandActor, Dial
|
||||
return dialog;
|
||||
}
|
||||
|
||||
throw new InvalidDialogException(id);
|
||||
}
|
||||
|
||||
@HandleException
|
||||
public void onInvalidDialog(InvalidDialogException e, BukkitCommandActor actor) {
|
||||
FancyDialogsPlugin.get().getTranslator()
|
||||
.translate("dialog.not_found")
|
||||
.replace("id", id)
|
||||
.send(context.actor().sender());
|
||||
|
||||
return null;
|
||||
.replace("id", e.input())
|
||||
.send(actor.sender());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,4 +47,10 @@ public class DialogCommandType implements ParameterType<BukkitCommandActor, Dial
|
||||
.map(Dialog::getId)
|
||||
.toList();
|
||||
}
|
||||
|
||||
static class InvalidDialogException extends InvalidValueException {
|
||||
public InvalidDialogException(@NotNull String input) {
|
||||
super(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user