Search in sources :

Example 1 with DeleteWarpEvent

use of io.github.nucleuspowered.nucleus.modules.warp.event.DeleteWarpEvent in project Nucleus by NucleusPowered.

the class DeleteWarpCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Warp warp = args.<Warp>getOne(WarpCommand.warpNameArg).get();
    NucleusWarpService qs = Sponge.getServiceManager().provideUnchecked(NucleusWarpService.class);
    DeleteWarpEvent event = new DeleteWarpEvent(CauseStackHelper.createCause(src), warp);
    if (Sponge.getEventManager().post(event)) {
        throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("nucleus.eventcancelled")));
    }
    if (qs.removeWarp(warp.getName())) {
        // Worked. Tell them.
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.del", warp.getName()));
        return CommandResult.success();
    }
    // Didn't work. Tell them.
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.delerror"));
    return CommandResult.empty();
}
Also used : Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) DeleteWarpEvent(io.github.nucleuspowered.nucleus.modules.warp.event.DeleteWarpEvent) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) NucleusWarpService(io.github.nucleuspowered.nucleus.api.service.NucleusWarpService)

Aggregations

Warp (io.github.nucleuspowered.nucleus.api.nucleusdata.Warp)1 NucleusWarpService (io.github.nucleuspowered.nucleus.api.service.NucleusWarpService)1 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)1 DeleteWarpEvent (io.github.nucleuspowered.nucleus.modules.warp.event.DeleteWarpEvent)1