mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 21:48:43 +01:00
Add worlds automatically on object initialization
This commit is contained in:
parent
24fae9da05
commit
e2f4a8fe84
@ -135,6 +135,8 @@ public class EditWorld extends InstanceWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileUtil.removeDirectory(getFolder());
|
FileUtil.removeDirectory(getFolder());
|
||||||
|
|
||||||
|
worlds.removeInstance(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Statics */
|
/* Statics */
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
package io.github.dre2n.dungeonsxl.world;
|
package io.github.dre2n.dungeonsxl.world;
|
||||||
|
|
||||||
import io.github.dre2n.commons.util.FileUtil;
|
import io.github.dre2n.commons.util.FileUtil;
|
||||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
|
||||||
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
|
|
||||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||||
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent;
|
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent;
|
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent;
|
||||||
@ -56,8 +54,6 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
*/
|
*/
|
||||||
public class GameWorld extends InstanceWorld {
|
public class GameWorld extends InstanceWorld {
|
||||||
|
|
||||||
static DungeonsXL plugin = DungeonsXL.getInstance();
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
private boolean tutorial;
|
private boolean tutorial;
|
||||||
private boolean isPlaying = false;
|
private boolean isPlaying = false;
|
||||||
@ -343,8 +339,7 @@ public class GameWorld extends InstanceWorld {
|
|||||||
*/
|
*/
|
||||||
public Dungeon getDungeon() {
|
public Dungeon getDungeon() {
|
||||||
for (Dungeon dungeon : plugin.getDungeons().getDungeons()) {
|
for (Dungeon dungeon : plugin.getDungeons().getDungeons()) {
|
||||||
DungeonConfig dungeonConfig = dungeon.getConfig();
|
if (dungeon.getConfig().containsFloor(getResource())) {
|
||||||
if (dungeonConfig.getFloors().contains(getName()) || dungeonConfig.getStartFloor().equals(getName()) || dungeonConfig.getEndFloor().equals(getName())) {
|
|
||||||
return dungeon;
|
return dungeon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -401,6 +396,8 @@ public class GameWorld extends InstanceWorld {
|
|||||||
plugin.getWorlds().getInstances().remove(this);
|
plugin.getWorlds().getInstances().remove(this);
|
||||||
plugin.getServer().unloadWorld(getWorld(), true);
|
plugin.getServer().unloadWorld(getWorld(), true);
|
||||||
FileUtil.removeDirectory(getFolder());
|
FileUtil.removeDirectory(getFolder());
|
||||||
|
|
||||||
|
worlds.removeInstance(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,7 @@ import org.bukkit.World;
|
|||||||
public abstract class InstanceWorld {
|
public abstract class InstanceWorld {
|
||||||
|
|
||||||
protected static DungeonsXL plugin = DungeonsXL.getInstance();
|
protected static DungeonsXL plugin = DungeonsXL.getInstance();
|
||||||
|
protected static Worlds worlds = plugin.getWorlds();
|
||||||
|
|
||||||
public static String ID_FILE_PREFIX = ".id_";
|
public static String ID_FILE_PREFIX = ".id_";
|
||||||
|
|
||||||
@ -46,6 +47,8 @@ public abstract class InstanceWorld {
|
|||||||
this.folder = folder;
|
this.folder = folder;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
worlds.addInstance(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Getters and setters */
|
/* Getters and setters */
|
||||||
|
@ -60,6 +60,8 @@ public class ResourceWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
signData = new SignData(signDataFile);
|
signData = new SignData(signDataFile);
|
||||||
|
|
||||||
|
worlds.addResource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceWorld(File folder) {
|
public ResourceWorld(File folder) {
|
||||||
@ -74,6 +76,8 @@ public class ResourceWorld {
|
|||||||
if (signData.exists()) {
|
if (signData.exists()) {
|
||||||
this.signData = new SignData(signData);
|
this.signData = new SignData(signData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
worlds.addResource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Getters and setters */
|
/* Getters and setters */
|
||||||
|
@ -35,7 +35,7 @@ public class Worlds {
|
|||||||
public Worlds(File folder) {
|
public Worlds(File folder) {
|
||||||
for (File file : folder.listFiles()) {
|
for (File file : folder.listFiles()) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
resources.add(new ResourceWorld(file));
|
new ResourceWorld(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,6 +86,22 @@ public class Worlds {
|
|||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param resource
|
||||||
|
* the ResourceWorld to add
|
||||||
|
*/
|
||||||
|
public void addResource(ResourceWorld resource) {
|
||||||
|
resources.add(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param resource
|
||||||
|
* the ResourceWorld to remove
|
||||||
|
*/
|
||||||
|
public void removeResource(ResourceWorld resource) {
|
||||||
|
resources.remove(resource);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the loaded InstanceWorlds in the world container
|
* @return the loaded InstanceWorlds in the world container
|
||||||
*/
|
*/
|
||||||
@ -93,6 +109,22 @@ public class Worlds {
|
|||||||
return instances;
|
return instances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param instance
|
||||||
|
* the InstanceWorld to add
|
||||||
|
*/
|
||||||
|
public void addInstance(InstanceWorld instance) {
|
||||||
|
instances.add(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param instance
|
||||||
|
* the InstanceWorld to remove
|
||||||
|
*/
|
||||||
|
public void removeInstance(InstanceWorld instance) {
|
||||||
|
instances.remove(instance);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the loaded GameWorlds
|
* @return the loaded GameWorlds
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user