Improved teleport event perfomance

This commit is contained in:
Butzlabben 2019-04-23 00:31:37 +02:00
parent a8cd6af9c7
commit 84890fec54
2 changed files with 22 additions and 24 deletions

View File

@ -24,13 +24,15 @@ public class CommandListener implements Listener {
Player p = e.getPlayer();
World from = e.getFrom().getWorld();
World to = e.getTo().getWorld();
boolean fromIsSystemWorld = WorldConfig.exists(from.getName());
boolean toIsSystemWorld = WorldConfig.exists(to.getName());
WorldPlayer wp = new WorldPlayer(p);
if (from != to)
SystemWorld.tryUnloadLater(from);
if (e.getCause() == TeleportCause.SPECTATE) {
if (from != to && WorldConfig.exists(to.getName())) {
if (from != to && toIsSystemWorld) {
if (!p.hasPermission("ws.tp.toother")) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
@ -44,7 +46,7 @@ public class CommandListener implements Listener {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
} else if (e.getCause() == TeleportCause.COMMAND) {
if (from != to && WorldConfig.exists(to.getName())) {
if (from != to && toIsSystemWorld) {
if (!p.hasPermission("ws.tp.toother")) {
e.setCancelled(true);
p.sendMessage(MessageConfig.getNoPermission());
@ -60,17 +62,17 @@ public class CommandListener implements Listener {
}
// Fix for #18
if (from != to || WorldConfig.exists(from.getName())) {
if (from != to || fromIsSystemWorld) {
// Save location for #23
if (WorldConfig.exists(from.getName())) {
if (fromIsSystemWorld) {
WorldConfig config = WorldConfig.getWorldConfig(from.getName());
PlayerPositions.getInstance().saveWorldsPlayerLocation(p, config);
} else {
if (WorldConfig.exists(to.getName()))
if (toIsSystemWorld)
PlayerPositions.getInstance().savePlayerLocation(p);
}
GameMode gameMode = PluginConfig.getSpawnGamemode();
if (WorldConfig.exists(to.getName())) {
if (toIsSystemWorld) {
if (PluginConfig.isSurvival()) {
gameMode = GameMode.SURVIVAL;
} else {

View File

@ -122,11 +122,10 @@ public class SystemWorld {
*/
public void unloadLater(World w) {
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
unloadLater(w);
});
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> unloadLater(w));
return;
}
Preconditions.checkNotNull(w, "world must not be null");
WorldUnloadEvent event = new WorldUnloadEvent(this);
Bukkit.getPluginManager().callEvent(event);
@ -146,21 +145,18 @@ public class SystemWorld {
a.setGameMode(PluginConfig.getSpawnGamemode());
}
Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), new Runnable() {
@Override
public void run() {
// Still in world unloading process?
if (unloading && w.getPlayers().size() == 0) {
if (Bukkit.unloadWorld(w, true)) {
File worldinserver = new File(Bukkit.getWorldContainer(), worldname);
File worlddir = new File(PluginConfig.getWorlddir());
try {
FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false);
Bukkit.getWorlds().remove(w);
unloading = false;
} catch (IOException e) {
e.printStackTrace();
}
Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> {
// Still in world unloading process?
if (unloading && w.getPlayers().size() == 0) {
if (Bukkit.unloadWorld(w, true)) {
File worldinserver = new File(Bukkit.getWorldContainer(), worldname);
File worlddir = new File(PluginConfig.getWorlddir());
try {
FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false);
Bukkit.getWorlds().remove(w);
unloading = false;
} catch (IOException e) {
e.printStackTrace();
}
}
}