use of io.github.nucleuspowered.nucleus.modules.warp.event.CreateWarpEvent in project Nucleus by NucleusPowered.
the class SetWarpCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
String warp = args.<String>getOne(WarpCommand.warpNameArg).get();
// Needs to match the name...
if (!warpRegex.matcher(warp).matches()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.invalidname"));
return CommandResult.empty();
}
// Get the service, does the warp exist?
if (qs.getWarp(warp).isPresent()) {
// You have to delete to set the same name
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.nooverwrite"));
return CommandResult.empty();
}
CreateWarpEvent event = CauseStackHelper.createFrameWithCausesWithReturn(c -> new CreateWarpEvent(c, warp, src.getLocation()), src);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("nucleus.eventcancelled")));
}
// OK! Set it.
if (qs.setWarp(warp, src.getLocation(), src.getRotation())) {
// Worked. Tell them.
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.set", warp));
return CommandResult.success();
}
// Didn't work. Tell them.
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.seterror"));
}
Aggregations