use of io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler in project Nucleus by NucleusPowered.
the class TeleportPositionCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Player pl = this.getUserFromArgs(Player.class, src, key, args);
WorldProperties wp = args.<WorldProperties>getOne(location).orElse(pl.getWorld().getProperties());
World world = Sponge.getServer().loadWorld(wp.getUniqueId()).get();
int xx = args.<Integer>getOne(x).get();
int zz = args.<Integer>getOne(z).get();
int yy = args.<Integer>getOne(y).get();
if (yy < 0) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.ysmall"));
return CommandResult.empty();
}
// Chunks are 16 in size, chunk 0 is from 0 - 15, -1 from -1 to -16.
if (args.hasAny("c")) {
xx = xx * 16 + 8;
yy = yy * 16 + 8;
zz = zz * 16 + 8;
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.fromchunk", String.valueOf(xx), String.valueOf(yy), String.valueOf(zz)));
}
Vector3i max = world.getBlockMax();
Vector3i min = world.getBlockMin();
if (!(isBetween(xx, max.getX(), min.getX()) && isBetween(yy, max.getY(), min.getY()) && isBetween(zz, max.getZ(), min.getZ()))) {
throw ReturnMessageException.fromKey("command.tppos.invalid");
}
// Create the location
Location<World> loc = new Location<>(world, xx, yy, zz);
if (!args.hasAny("b") && !Util.isLocationInWorldBorder(loc)) {
throw ReturnMessageException.fromKey("command.tppos.worldborder");
}
NucleusTeleportHandler teleportHandler = Nucleus.getNucleus().getTeleportHandler();
Cause cause = CauseStackHelper.createCause(src);
// Don't bother with the safety if the flag is set.
if (args.<Boolean>getOne("f").orElse(false)) {
if (teleportHandler.teleportPlayer(pl, loc, NucleusTeleportHandler.StandardTeleportMode.NO_CHECK, cause).isSuccess()) {
pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.self"));
if (!src.equals(pl)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.other", pl.getName()));
}
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.tppos.cancelledevent");
}
// If we have a chunk, scan the whole chunk.
NucleusTeleportHandler.StandardTeleportMode mode = teleportHandler.getTeleportModeForPlayer(pl);
if (args.hasAny("c") && mode == NucleusTeleportHandler.StandardTeleportMode.FLYING_THEN_SAFE) {
mode = NucleusTeleportHandler.StandardTeleportMode.FLYING_THEN_SAFE_CHUNK;
}
NucleusTeleportHandler.TeleportResult result = teleportHandler.teleportPlayer(pl, loc, mode, cause, true);
if (result.isSuccess()) {
pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.self"));
if (!src.equals(pl)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.other", pl.getName()));
}
return CommandResult.success();
} else if (result == NucleusTeleportHandler.TeleportResult.FAILED_NO_LOCATION) {
throw ReturnMessageException.fromKey("command.tppos.nosafe");
}
throw ReturnMessageException.fromKey("command.tppos.cancelledevent");
}
Aggregations