TF-EssentialsX/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworld.java

89 lines
3.2 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
2011-06-13 13:05:11 +00:00
import com.earth2me.essentials.Trade;
2011-11-18 17:42:26 +00:00
import com.earth2me.essentials.User;
import com.google.common.collect.Lists;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
2015-04-15 04:06:16 +00:00
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
public class Commandworld extends EssentialsCommand {
public Commandworld() {
super("world");
}
2015-04-15 04:06:16 +00:00
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
2020-10-03 17:46:05 +00:00
final World world;
2015-04-15 04:06:16 +00:00
if (args.length < 1) {
World nether = null;
2015-04-15 04:06:16 +00:00
final List<World> worlds = server.getWorlds();
2020-10-03 17:46:05 +00:00
for (final World world2 : worlds) {
2015-04-15 04:06:16 +00:00
if (world2.getEnvironment() == World.Environment.NETHER) {
nether = world2;
break;
}
}
if (nether == null) {
return;
}
world = user.getWorld() == nether ? worlds.get(0) : nether;
} else {
world = ess.getWorld(getFinalArg(args, 0));
if (world == null) {
user.sendMessage(tl("invalidWorld"));
user.sendMessage(tl("possibleWorlds", server.getWorlds().size() - 1));
user.sendMessage(tl("typeWorldName"));
throw new NoChargeException();
}
}
2015-04-15 04:06:16 +00:00
if (ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + world.getName())) {
throw new Exception(tl("noPerm", "essentials.worlds." + world.getName()));
}
2011-12-03 17:13:42 +00:00
2020-10-03 17:46:05 +00:00
final double factor;
2015-04-15 04:06:16 +00:00
if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) {
factor = 8.0;
} else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) {
factor = 1.0 / 8.0;
} else {
factor = 1.0;
}
2015-04-15 04:06:16 +00:00
final Location loc = user.getLocation();
final Location target = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
2015-04-15 04:06:16 +00:00
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
Reduce sync loads for teleporting (#3102) This PR reduces the number of sync loads occurring on any teleport caused by essentials. Fixes #2861 Fixes #2287 Fixes #3274 Fixes #3201 Fixes #2120 Before this PR, essentials would get a block multiple times causing sync loads to check if it was safe to teleport to. Now, the target block's chunk if fetched async with PaperLib and passed along to `LocationUtil#isBlockUnsafeForUser` (which internally calls other LocationUtil methods what that chunk object) resulting in the chunk only loading once, off the main thread. The only operations remaining on the main thread is `LocationUtil#getSafeDestination`. This is due to the method's recursion which would be a pain to move async. **However:** since the chunk was already loaded async, `LocationUtil#getSafeDestination` most of the time won't cause sync chunk loads. The only time it would cause sync chunk loads is with an unsafe location near a chunk border. ----------------------------------------- * Reduce sync teleporting loads * Avoid argument re-assigning * Remove async teleports when unnecessary * Make exceptions cleaner * Async all the things Made an async version of every method with fallbacks for deprecated methods. * Remove old now fallback method * Migrate everything to the new async teleport API * Update ITeleport javadocs * Fix invoking via async context * Fix /jail using deprecated method * Fix jail join handler using deprecated method * Rename all teleport classes to indicate async * Remove deprecated methods * Add (and deprecate) old teleport api * Revert TimedTeleport.java * Reduce Diff * Add legacy sendToJail method * Reduce Diff Further * Use getNewExceptionFuture in Commandtpo * Use getNewExceptionFuture everywhere * Fix even more usages * Revert LocationUtil.java * Fix issue causing unsafe locations to not work properly * Add deprecated notice in IUser implementation * Use CompletableFuture#completeExceptionally for exceptions * Use Essentials' logger in EssentialsCommand#showError * Return implementation rather than interface * Avoid possible deadlocks with entity ejections * Nuke some sync loads with homes Took 7 hours and 2 PRs to paper but it's here! * Fix ABI and make the codestyle worse * Make the codestyle worse because muh diff * Further ruin the codestyle * Fix error messages not showing in TimedTeleports * Improve messages around beds for /home * Fix #3274 Allow unsafe locations for different worlds + spectator mode * Fix fly safety operators
2020-06-24 08:52:25 +00:00
user.getAsyncTeleport().teleport(target, charge, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel));
throw new NoChargeException();
2015-04-15 04:06:16 +00:00
}
@Override
2020-10-03 17:46:05 +00:00
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
2020-10-03 17:46:05 +00:00
final List<String> worlds = Lists.newArrayList();
for (final World world : server.getWorlds()) {
if (ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + world.getName())) {
continue;
}
worlds.add(world.getName());
}
return worlds;
} else {
return Collections.emptyList();
}
}
}