Add worldEnvironment setting to floor config; resolves #362

This commit is contained in:
Daniel Saukel 2018-03-01 21:33:41 +01:00
parent 9589feb0f5
commit 8fcb38ef66
3 changed files with 36 additions and 6 deletions

View File

@ -26,6 +26,7 @@ import io.github.dre2n.dungeonsxl.world.DResourceWorld;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
@ -81,7 +82,12 @@ public class ImportCommand extends DRECommand {
}.runTaskAsynchronously(plugin);
}
plugin.getDWorlds().addResource(new DResourceWorld(plugin.getDWorlds(), args[1]));
DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), args[1]);
if (world.getEnvironment() != Environment.NORMAL) {
resource.getConfig(true).setWorldEnvironment(world.getEnvironment());
resource.getConfig().save();
}
plugin.getDWorlds().addResource(resource);
MessageUtil.sendMessage(sender, DMessage.CMD_IMPORT_SUCCESS.getMessage(args[1]));
}

View File

@ -25,6 +25,7 @@ import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.scheduler.BukkitRunnable;
@ -126,6 +127,10 @@ public class DResourceWorld {
return config;
}
public Environment getWorldEnvironment() {
return config != null ? config.getWorldEnvironment() : Environment.NORMAL;
}
/**
* @return the DXLData.data file
*/
@ -215,7 +220,7 @@ public class DResourceWorld {
if (!plugin.getMainConfig().areTweaksEnabled()) {
FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES);
instance.world = Bukkit.createWorld(WorldCreator.name(name));
instance.world = Bukkit.createWorld(WorldCreator.name(name).environment(getWorldEnvironment()));
if (game) {
signData.deserializeSigns((DGameWorld) instance);
@ -228,7 +233,7 @@ public class DResourceWorld {
@Override
public void run() {
FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES);
instance.world = WorldLoader.createWorld(WorldCreator.name(instanceFolder.getName()));
instance.world = WorldLoader.createWorld(WorldCreator.name(instanceFolder.getName()).environment(getWorldEnvironment()));
new BukkitRunnable() {
@Override

View File

@ -38,6 +38,7 @@ import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.World.Environment;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -58,6 +59,7 @@ public class WorldConfig extends GameRuleProvider {
private List<String> invitedPlayers = new ArrayList<>();
private GameType forcedGameType;
private Environment worldEnvironment;
public WorldConfig() {
}
@ -96,7 +98,11 @@ public class WorldConfig extends GameRuleProvider {
/* Invited Players */
if (configFile.contains("invitedPlayers")) {
invitedPlayers = configFile.getStringList("invitedPlayers");
}
if (configFile.contains("worldEnvironment")) {
Environment env = EnumUtil.getEnum(Environment.class, configFile.getString("worldEnvironment"));
worldEnvironment = env != null ? env : Environment.NORMAL;
}
/* Keep Inventory */
@ -312,15 +318,13 @@ public class WorldConfig extends GameRuleProvider {
}
List<String> secureObjectIds = new ArrayList<>();
for (ItemStack item : getSecureObjects()) {
secureObjectIds.add(CaliburnAPI.getInstance().getItems().getCustomItemId(item));
}
configFile.set("secureObjects", secureObjects);
// Invited Players
configFile.set("invitedPlayers", invitedPlayers);
configFile.set("worldEnvironment", worldEnvironment.name());
try {
configFile.save(file);
@ -376,4 +380,19 @@ public class WorldConfig extends GameRuleProvider {
this.forcedGameType = forcedGameType;
}
/**
* @return the world environment
*/
public Environment getWorldEnvironment() {
return worldEnvironment;
}
/**
* @param worldEnvironment
* the world environment to set
*/
public void setWorldEnvironment(Environment worldEnvironment) {
this.worldEnvironment = worldEnvironment;
}
}