mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
More command refactoring
This commit is contained in:
1 parent
3bde5305d7
commit
34eb2c1f54
17 files changed
+382
-540
No files matched your search
@@ -2,45 +2,21 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.position.PositionMeta;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import net.william278.huskhomes.util.ValidationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SetWarpCommand extends Command {
|
||||
public class SetWarpCommand extends SetPositionCommand {
|
||||
|
||||
protected SetWarpCommand(@NotNull HuskHomes implementor) {
|
||||
super("setwarp", Permission.COMMAND_SET_WARP, implementor);
|
||||
protected SetWarpCommand(@NotNull HuskHomes plugin) {
|
||||
super("setwarp", plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
setWarp(onlineUser, args[0]);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/setwarp <name>")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
protected void execute(@NotNull OnlineUser setter, @NotNull String name) {
|
||||
try {
|
||||
plugin.getManager().warps().createWarp(name, setter.getPosition());
|
||||
} catch (ValidationException e) {
|
||||
e.dispatchWarpError(setter, plugin, name);
|
||||
}
|
||||
}
|
||||
|
||||
private void setWarp(@NotNull OnlineUser onlineUser, @NotNull String warpName) {
|
||||
plugin.getManager().setWarp(
|
||||
new PositionMeta(warpName, ""), onlineUser.getPosition()).thenAccept(setResult ->
|
||||
(switch (setResult.resultType()) {
|
||||
case SUCCESS -> {
|
||||
assert setResult.savedPosition().isPresent();
|
||||
yield plugin.getLocales().getLocale("set_warp_success",
|
||||
setResult.savedPosition().get().meta.name);
|
||||
}
|
||||
case SUCCESS_OVERWRITTEN -> {
|
||||
assert setResult.savedPosition().isPresent();
|
||||
yield plugin.getLocales().getLocale("edit_warp_update_location",
|
||||
setResult.savedPosition().get().meta.name);
|
||||
}
|
||||
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken");
|
||||
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length");
|
||||
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters");
|
||||
default -> plugin.getLocales().getLocale("error_warp_description_characters");
|
||||
}).ifPresent(onlineUser::sendMessage));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user