use of io.github.nucleuspowered.nucleus.api.nucleusdata.Home in project Nucleus by NucleusPowered.
the class HomeCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
int max = this.homeHandler.getMaximumHomes(src);
int current = this.homeHandler.getHomeCount(src);
if (this.isPreventOverhang && max < current) {
// If the player has too many homes, tell them
throw ReturnMessageException.fromKey("command.home.overhang", String.valueOf(max), String.valueOf(current));
}
// Get the home.
Optional<Home> owl = args.getOne(home);
Home wl;
if (owl.isPresent()) {
wl = owl.get();
} else {
wl = homeHandler.getHome(src, NucleusHomeService.DEFAULT_HOME_NAME).orElseThrow(() -> new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("args.home.nohome", "home")));
}
Sponge.getServer().loadWorld(wl.getWorldProperties().orElseThrow(() -> ReturnMessageException.fromKey("command.home.invalid", wl.getName())));
Location<World> targetLocation = wl.getLocation().orElseThrow(() -> ReturnMessageException.fromKey("command.home.invalid", wl.getName()));
UseHomeEvent event = CauseStackHelper.createFrameWithCausesWithReturn(c -> new UseHomeEvent(c, src, wl), src);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("nucleus.eventcancelled")));
}
// Warp to it safely.
if (plugin.getTeleportHandler().teleportPlayer(src, targetLocation, wl.getRotation(), this.isSafeTeleport).isSuccess()) {
if (!wl.getName().equalsIgnoreCase(NucleusHomeService.DEFAULT_HOME_NAME)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.success", wl.getName()));
} else {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.successdefault"));
}
return CommandResult.success();
} else {
throw ReturnMessageException.fromKey("command.home.fail", wl.getName());
}
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Home in project Nucleus by NucleusPowered.
the class SetHomeCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
// Get the home key.
String home = args.<String>getOne(homeKey).orElse(NucleusHomeService.DEFAULT_HOME_NAME).toLowerCase();
if (!NucleusHomeService.HOME_NAME_PATTERN.matcher(home).matches()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.sethome.name"));
}
Optional<Home> currentHome = homeHandler.getHome(src, home);
boolean overwrite = currentHome.isPresent() && args.hasAny("o");
if (currentHome.isPresent() && !overwrite) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.sethome.seterror", home));
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.sethome.tooverwrite", home).toBuilder().onClick(TextActions.runCommand("/sethome " + home + " -o")).build());
return CommandResult.empty();
}
Cause cause = CauseStackHelper.createCause(src);
try {
if (overwrite) {
int max = this.homeHandler.getMaximumHomes(src);
int c = this.homeHandler.getHomeCount(src);
if (this.preventOverhang && max < c) {
// If the player has too many homes, tell them
throw ReturnMessageException.fromKey("command.sethome.overhang", String.valueOf(max), String.valueOf(c));
}
Home current = currentHome.get();
homeHandler.modifyHomeInternal(cause, current, src.getLocation(), src.getRotation());
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.sethome.overwrite", home));
} else {
homeHandler.createHomeInternal(cause, src, home, src.getLocation(), src.getRotation());
}
} catch (NucleusException e) {
throw new ReturnMessageException(e.getText(), e);
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.sethome.set", home));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Home in project Nucleus by NucleusPowered.
the class DeleteHomeCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
Home wl = args.<Home>getOne(homeKey).get();
CauseStackHelper.createFrameWithCausesWithConsumer(c -> homeHandler.removeHomeInternal(c, wl), src);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.delete.success", wl.getName()));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Home in project Nucleus by NucleusPowered.
the class DeleteOtherHomeCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Home wl = args.<Home>getOne(homeKey).get();
CauseStackHelper.createFrameWithCausesWithConsumer(c -> homeHandler.removeHomeInternal(c, wl), src);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.delete.other.success", wl.getUser().getName(), wl.getName()));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Home in project Nucleus by NucleusPowered.
the class HomeOtherCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
// Get the home.
Home wl = args.<Home>getOne(home).get();
Sponge.getServer().loadWorld(wl.getWorldProperties().orElseThrow(() -> ReturnMessageException.fromKey("command.home.invalid", wl.getName())));
Location<World> targetLocation = wl.getLocation().orElseThrow(() -> ReturnMessageException.fromKey("command.home.invalid", wl.getName()));
UseHomeEvent event = CauseStackHelper.createFrameWithCausesWithReturn(c -> new UseHomeEvent(c, src, wl), src);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("nucleus.eventcancelled")));
}
// Warp to it safely.
if (plugin.getTeleportHandler().teleportPlayer(src, targetLocation, wl.getRotation(), this.isSafeTeleport).isSuccess()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.homeother.success", wl.getUser().getName(), wl.getName()));
return CommandResult.success();
} else {
throw ReturnMessageException.fromKey("command.homeother.fail", wl.getUser().getName(), wl.getName());
}
}
Aggregations