45 lines
1.7 KiB
Java
45 lines
1.7 KiB
Java
package com.mythlane.gravityflip.command;
|
|
|
|
import com.hypixel.hytale.server.core.Message;
|
|
import com.hypixel.hytale.server.core.command.system.CommandContext;
|
|
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
|
|
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
|
|
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;
|
|
import com.mythlane.gravityflip.GravityFlipPlugin;
|
|
|
|
import javax.annotation.Nonnull;
|
|
import java.util.logging.Level;
|
|
|
|
/** Deletes a Gravity Flip region and persists the change. */
|
|
public final class GravityFlipDeleteSubCommand extends CommandBase {
|
|
|
|
private final GravityFlipPlugin plugin;
|
|
|
|
private final RequiredArg<String> nameArg =
|
|
this.withRequiredArg("name", "Name of the region to delete", ArgTypes.STRING);
|
|
|
|
public GravityFlipDeleteSubCommand(GravityFlipPlugin plugin) {
|
|
super("delete", "Delete a Gravity Flip region");
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@Override
|
|
protected void executeSync(@Nonnull CommandContext ctx) {
|
|
String name = nameArg.get(ctx);
|
|
if (!plugin.regions().remove(name)) {
|
|
ctx.sendMessage(Message.raw("[gravityflip] Region '" + name + "' not found."));
|
|
return;
|
|
}
|
|
try {
|
|
plugin.configHolder().save().join();
|
|
} catch (Throwable th) {
|
|
plugin.getLogger().at(Level.WARNING).withCause(th)
|
|
.log("[delete] save failed for region '" + name + "'");
|
|
ctx.sendMessage(Message.raw(
|
|
"[gravityflip] Deleted in memory, but persistence failed — see logs."));
|
|
return;
|
|
}
|
|
ctx.sendMessage(Message.raw("[gravityflip] Region '" + name + "' deleted."));
|
|
}
|
|
}
|