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);
|
builder.addParameterType(Dialog.class, DialogCommandType.INSTANCE);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
lampBuilder.exceptionHandler(DialogCommandType.INSTANCE);
|
||||||
|
|
||||||
Lamp<BukkitCommandActor> lamp = lampBuilder.build();
|
Lamp<BukkitCommandActor> lamp = lampBuilder.build();
|
||||||
|
|
||||||
lamp.register(FancyDialogsCMD.INSTANCE);
|
lamp.register(FancyDialogsCMD.INSTANCE);
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ import com.fancyinnovations.fancydialogs.registry.DialogRegistry;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import revxrsal.commands.autocomplete.SuggestionProvider;
|
import revxrsal.commands.autocomplete.SuggestionProvider;
|
||||||
import revxrsal.commands.bukkit.actor.BukkitCommandActor;
|
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.node.ExecutionContext;
|
||||||
import revxrsal.commands.parameter.ParameterType;
|
import revxrsal.commands.parameter.ParameterType;
|
||||||
import revxrsal.commands.stream.MutableStringStream;
|
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();
|
public static final DialogCommandType INSTANCE = new DialogCommandType();
|
||||||
private static final DialogRegistry REGISTRY = FancyDialogsPlugin.get().getDialogRegistry();
|
private static final DialogRegistry REGISTRY = FancyDialogsPlugin.get().getDialogRegistry();
|
||||||
@@ -28,12 +30,15 @@ public class DialogCommandType implements ParameterType<BukkitCommandActor, Dial
|
|||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new InvalidDialogException(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@HandleException
|
||||||
|
public void onInvalidDialog(InvalidDialogException e, BukkitCommandActor actor) {
|
||||||
FancyDialogsPlugin.get().getTranslator()
|
FancyDialogsPlugin.get().getTranslator()
|
||||||
.translate("dialog.not_found")
|
.translate("dialog.not_found")
|
||||||
.replace("id", id)
|
.replace("id", e.input())
|
||||||
.send(context.actor().sender());
|
.send(actor.sender());
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,4 +47,10 @@ public class DialogCommandType implements ParameterType<BukkitCommandActor, Dial
|
|||||||
.map(Dialog::getId)
|
.map(Dialog::getId)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class InvalidDialogException extends InvalidValueException {
|
||||||
|
public InvalidDialogException(@NotNull String input) {
|
||||||
|
super(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user