mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-24 01:01:51 +01:00
Refactor, Now we safely move players from a world to be unlaoded, unload actually unloads from memory
This commit is contained in:
parent
a3e27da978
commit
1a16636c7a
@ -388,9 +388,12 @@ public class MultiverseCore extends JavaPlugin {
|
||||
* @param name The name of the world to remove
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
public boolean unloadWorld(String name) {
|
||||
public boolean removeWorldFromList(String name) {
|
||||
|
||||
if (this.worlds.containsKey(name)) {
|
||||
this.worlds.remove(name);
|
||||
this.log(Level.INFO, "World " + name + " was unloaded from memory.");
|
||||
this.unloadWorld(name, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -402,10 +405,14 @@ public class MultiverseCore extends JavaPlugin {
|
||||
* @param name The name of the world to remove
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
public boolean removeWorld(String name) {
|
||||
unloadWorld(name);
|
||||
this.configWorlds.removeProperty("worlds." + name);
|
||||
this.configWorlds.save();
|
||||
public boolean removeWorldFromConfig(String name) {
|
||||
if(this.configWorlds.getProperty("worlds." + name) != null) {
|
||||
removeWorldFromList(name);
|
||||
this.log(Level.INFO, "World " + name + " was removed from config.yml");
|
||||
this.configWorlds.removeProperty("worlds." + name);
|
||||
this.configWorlds.save();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -416,14 +423,32 @@ public class MultiverseCore extends JavaPlugin {
|
||||
* @return True if success, false if failure.
|
||||
*/
|
||||
public boolean deleteWorld(String name) {
|
||||
unloadWorld(name);
|
||||
removeWorld(name);
|
||||
if (getServer().unloadWorld(name, false)) {
|
||||
return deleteFolder(new File(name));
|
||||
removeWorldFromConfig(name);
|
||||
if (unloadWorld(name, false)) {
|
||||
boolean deletedWorld = deleteFolder(new File(name));
|
||||
if (deletedWorld)
|
||||
{
|
||||
this.log(Level.INFO, "World " + name + " was DELETED.");
|
||||
}
|
||||
return deletedWorld;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean unloadWorld(String name, boolean safely) {
|
||||
this.removePlayersFromWorld(name);
|
||||
return getServer().unloadWorld(name, safely);
|
||||
}
|
||||
|
||||
private void removePlayersFromWorld(String name) {
|
||||
World w = this.getServer().getWorld(name);
|
||||
World safeWorld = this.getServer().getWorlds().get(0);
|
||||
List<Player> ps = w.getPlayers();
|
||||
for(Player p : ps) {
|
||||
p.teleport(safeWorld.getSpawnLocation());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a folder Courtesy of: lithium3141
|
||||
*
|
||||
|
@ -21,7 +21,7 @@ public class RemoveCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (this.plugin.removeWorld(args.get(0))) {
|
||||
if (this.plugin.removeWorldFromConfig(args.get(0))) {
|
||||
sender.sendMessage("World removed from config!");
|
||||
} else {
|
||||
sender.sendMessage("Error trying to remove world from config!");
|
||||
|
@ -22,7 +22,7 @@ public class UnloadCommand extends MultiverseCommand {
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
if (this.plugin.unloadWorld(args.get(0))) {
|
||||
if (this.plugin.removeWorldFromList(args.get(0))) {
|
||||
sender.sendMessage("World Unloaded!");
|
||||
} else {
|
||||
sender.sendMessage("Error trying to unload world!");
|
||||
|
Loading…
Reference in New Issue
Block a user