mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2025-01-06 18:47:52 +01:00
Improved teleport event perfomance
This commit is contained in:
parent
a8cd6af9c7
commit
84890fec54
@ -24,13 +24,15 @@ public class CommandListener implements Listener {
|
|||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
World from = e.getFrom().getWorld();
|
World from = e.getFrom().getWorld();
|
||||||
World to = e.getTo().getWorld();
|
World to = e.getTo().getWorld();
|
||||||
|
boolean fromIsSystemWorld = WorldConfig.exists(from.getName());
|
||||||
|
boolean toIsSystemWorld = WorldConfig.exists(to.getName());
|
||||||
WorldPlayer wp = new WorldPlayer(p);
|
WorldPlayer wp = new WorldPlayer(p);
|
||||||
|
|
||||||
if (from != to)
|
if (from != to)
|
||||||
SystemWorld.tryUnloadLater(from);
|
SystemWorld.tryUnloadLater(from);
|
||||||
|
|
||||||
if (e.getCause() == TeleportCause.SPECTATE) {
|
if (e.getCause() == TeleportCause.SPECTATE) {
|
||||||
if (from != to && WorldConfig.exists(to.getName())) {
|
if (from != to && toIsSystemWorld) {
|
||||||
if (!p.hasPermission("ws.tp.toother")) {
|
if (!p.hasPermission("ws.tp.toother")) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.sendMessage(MessageConfig.getNoPermission());
|
p.sendMessage(MessageConfig.getNoPermission());
|
||||||
@ -44,7 +46,7 @@ public class CommandListener implements Listener {
|
|||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.sendMessage(MessageConfig.getNoPermission());
|
p.sendMessage(MessageConfig.getNoPermission());
|
||||||
} else if (e.getCause() == TeleportCause.COMMAND) {
|
} else if (e.getCause() == TeleportCause.COMMAND) {
|
||||||
if (from != to && WorldConfig.exists(to.getName())) {
|
if (from != to && toIsSystemWorld) {
|
||||||
if (!p.hasPermission("ws.tp.toother")) {
|
if (!p.hasPermission("ws.tp.toother")) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.sendMessage(MessageConfig.getNoPermission());
|
p.sendMessage(MessageConfig.getNoPermission());
|
||||||
@ -60,17 +62,17 @@ public class CommandListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fix for #18
|
// Fix for #18
|
||||||
if (from != to || WorldConfig.exists(from.getName())) {
|
if (from != to || fromIsSystemWorld) {
|
||||||
// Save location for #23
|
// Save location for #23
|
||||||
if (WorldConfig.exists(from.getName())) {
|
if (fromIsSystemWorld) {
|
||||||
WorldConfig config = WorldConfig.getWorldConfig(from.getName());
|
WorldConfig config = WorldConfig.getWorldConfig(from.getName());
|
||||||
PlayerPositions.getInstance().saveWorldsPlayerLocation(p, config);
|
PlayerPositions.getInstance().saveWorldsPlayerLocation(p, config);
|
||||||
} else {
|
} else {
|
||||||
if (WorldConfig.exists(to.getName()))
|
if (toIsSystemWorld)
|
||||||
PlayerPositions.getInstance().savePlayerLocation(p);
|
PlayerPositions.getInstance().savePlayerLocation(p);
|
||||||
}
|
}
|
||||||
GameMode gameMode = PluginConfig.getSpawnGamemode();
|
GameMode gameMode = PluginConfig.getSpawnGamemode();
|
||||||
if (WorldConfig.exists(to.getName())) {
|
if (toIsSystemWorld) {
|
||||||
if (PluginConfig.isSurvival()) {
|
if (PluginConfig.isSurvival()) {
|
||||||
gameMode = GameMode.SURVIVAL;
|
gameMode = GameMode.SURVIVAL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -122,11 +122,10 @@ public class SystemWorld {
|
|||||||
*/
|
*/
|
||||||
public void unloadLater(World w) {
|
public void unloadLater(World w) {
|
||||||
if (!Bukkit.isPrimaryThread()) {
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> unloadLater(w));
|
||||||
unloadLater(w);
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Preconditions.checkNotNull(w, "world must not be null");
|
Preconditions.checkNotNull(w, "world must not be null");
|
||||||
WorldUnloadEvent event = new WorldUnloadEvent(this);
|
WorldUnloadEvent event = new WorldUnloadEvent(this);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
@ -146,21 +145,18 @@ public class SystemWorld {
|
|||||||
a.setGameMode(PluginConfig.getSpawnGamemode());
|
a.setGameMode(PluginConfig.getSpawnGamemode());
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), new Runnable() {
|
Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> {
|
||||||
@Override
|
// Still in world unloading process?
|
||||||
public void run() {
|
if (unloading && w.getPlayers().size() == 0) {
|
||||||
// Still in world unloading process?
|
if (Bukkit.unloadWorld(w, true)) {
|
||||||
if (unloading && w.getPlayers().size() == 0) {
|
File worldinserver = new File(Bukkit.getWorldContainer(), worldname);
|
||||||
if (Bukkit.unloadWorld(w, true)) {
|
File worlddir = new File(PluginConfig.getWorlddir());
|
||||||
File worldinserver = new File(Bukkit.getWorldContainer(), worldname);
|
try {
|
||||||
File worlddir = new File(PluginConfig.getWorlddir());
|
FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false);
|
||||||
try {
|
Bukkit.getWorlds().remove(w);
|
||||||
FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false);
|
unloading = false;
|
||||||
Bukkit.getWorlds().remove(w);
|
} catch (IOException e) {
|
||||||
unloading = false;
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user