Skip to content

Commit

Permalink
Add worldEnvironment setting to floor config; resolves #362
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Mar 1, 2018
1 parent 9589feb commit 8fcb38e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;

Expand Down Expand Up @@ -81,7 +82,12 @@ public void run() {
}.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]));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -126,6 +127,10 @@ public WorldConfig getConfig(boolean generate) {
return config;
}

public Environment getWorldEnvironment() {
return config != null ? config.getWorldEnvironment() : Environment.NORMAL;
}

/**
* @return the DXLData.data file
*/
Expand Down Expand Up @@ -215,7 +220,7 @@ public DInstanceWorld instantiate(final boolean game) {

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);
Expand All @@ -228,7 +233,7 @@ public DInstanceWorld instantiate(final boolean game) {
@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
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;
Expand All @@ -58,6 +59,7 @@ public class WorldConfig extends GameRuleProvider {

private List<String> invitedPlayers = new ArrayList<>();
private GameType forcedGameType;
private Environment worldEnvironment;

public WorldConfig() {
}
Expand Down Expand Up @@ -96,7 +98,11 @@ public void load(ConfigurationSection configFile) {
/* 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 */
Expand Down Expand Up @@ -312,15 +318,13 @@ public void save() {
}

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);
Expand Down Expand Up @@ -376,4 +380,19 @@ public void setForcedGameType(GameType forcedGameType) {
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;
}

}

0 comments on commit 8fcb38e

Please sign in to comment.