diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRuleProvider.java b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRuleProvider.java index b5c8c172..258f6988 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/GameRuleProvider.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/GameRuleProvider.java @@ -46,13 +46,16 @@ public class GameRuleProvider { DEFAULT_VALUES.keepInventoryOnDeath = true; DEFAULT_VALUES.lobbyDisabled = false; - /* World interaction */ + /* World */ DEFAULT_VALUES.gameMode = GameMode.SURVIVAL; DEFAULT_VALUES.breakBlocks = false; DEFAULT_VALUES.breakPlacedBlocks = false; DEFAULT_VALUES.breakWhitelist = null; DEFAULT_VALUES.placeBlocks = false; DEFAULT_VALUES.placeWhitelist = null; + DEFAULT_VALUES.rain = null; + DEFAULT_VALUES.thunder = null; + DEFAULT_VALUES.time = null; /* Fighting */ DEFAULT_VALUES.playerVersusPlayer = false; @@ -98,13 +101,16 @@ public class GameRuleProvider { protected Boolean keepInventoryOnDeath; protected Boolean lobbyDisabled; - /* World interaction */ + /* World */ protected GameMode gameMode; protected Boolean breakBlocks; protected Boolean breakPlacedBlocks; protected Map> breakWhitelist; protected Boolean placeBlocks; protected Set placeWhitelist; + protected Boolean rain; + protected Boolean thunder; + protected Long time; /* Fighting */ protected Boolean playerVersusPlayer; @@ -183,7 +189,7 @@ public class GameRuleProvider { return lobbyDisabled; } - // World interaction + // World /** * @return the gameMode */ @@ -226,6 +232,56 @@ public class GameRuleProvider { return placeWhitelist; } + /** + * @return + * if it's raining permanently in this dungeon, + * null if random + */ + public Boolean isRaining() { + return rain; + } + + /** + * @param rain + * set if it's raining permanently in this dungeon + */ + public void setRaining(Boolean rain) { + this.rain = rain; + } + + /** + * @return + * You've been... THUNDERSTRUCK! + */ + public Boolean isThundering() { + return thunder; + } + + /** + * @param thunder + * You've been... THUNDERSTRUCK! + */ + public void setThundering(Boolean thunder) { + this.thunder = thunder; + } + + /** + * @return + * the locked day time in this dungeon, + * null if not locked + */ + public Long getTime() { + return time; + } + + /** + * @param time + * the locked day time to set + */ + public void setTime(Long time) { + this.time = time; + } + // Fight /** * @return if players may attack each other @@ -609,7 +665,7 @@ public class GameRuleProvider { lobbyDisabled = defaultValues.lobbyDisabled; } - /* World interaction */ + /* World */ if (gameMode == null) { gameMode = defaultValues.gameMode; } @@ -634,6 +690,18 @@ public class GameRuleProvider { placeWhitelist = defaultValues.placeWhitelist; } + if (rain == null) { + rain = defaultValues.rain; + } + + if (thunder == null) { + thunder = defaultValues.thunder; + } + + if (time == null) { + time = defaultValues.time; + } + /* Fighting */ if (playerVersusPlayer == null) { playerVersusPlayer = defaultValues.playerVersusPlayer; @@ -755,7 +823,7 @@ public class GameRuleProvider { } else if (defaultValues.secureObjects != null) { secureObjects.addAll(defaultValues.secureObjects); } - + if (groupTagEnabled == null) { groupTagEnabled = defaultValues.groupTagEnabled; } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 169f1f26..6758026e 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -767,6 +767,7 @@ public class DGroup { } game.fetchRules(); GameRuleProvider rules = game.getRules(); + gameWorld.setWeather(rules); color = plugin.getMainConfig().getGroupColorPriority().get(game.getDGroups().indexOf(this)); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java index dd678209..72e5cfb5 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/DInstanceWorld.java @@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.world; import de.erethon.commons.chat.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.game.GameRuleProvider; import io.github.dre2n.dungeonsxl.player.DGamePlayer; import java.io.File; import org.bukkit.Location; @@ -126,6 +127,31 @@ public abstract class DInstanceWorld { } } + /** + * @param rules + * sets up the time and weather to match the rules + */ + public void setWeather(GameRuleProvider rules) { + if (world == null) { + return; + } + + if (rules.isThundering() != null) { + if (rules.isThundering()) { + world.setThundering(true); + world.setStorm(true); + world.setThunderDuration(Integer.MAX_VALUE); + } else { + world.setThundering(false); + world.setStorm(false); + } + } + + if (rules.getTime() != null) { + world.setTime(rules.getTime()); + } + } + /* Abstracts */ /** * Deletes this instance. diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java b/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java index 0c48a380..a7d62b51 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java @@ -16,6 +16,7 @@ */ package io.github.dre2n.dungeonsxl.world; +import io.github.dre2n.dungeonsxl.game.Game; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.LivingEntity; @@ -141,8 +142,16 @@ public class DWorldListener implements Listener { @EventHandler public void onWeatherChange(WeatherChangeEvent event) { - if (dWorlds.getInstanceByWorld(event.getWorld()) != null) { - if (event.toWeatherState()) { + DInstanceWorld dWorld = dWorlds.getInstanceByWorld(event.getWorld()); + if (dWorld instanceof DEditWorld && event.toWeatherState()) { + event.setCancelled(true); + } else if (dWorld instanceof DGameWorld) { + Game game = Game.getByGameWorld((DGameWorld) dWorld); + Boolean raining = game.getRules().isRaining(); + if (raining == null) { + return; + } + if ((raining && !event.toWeatherState()) || (!raining && event.toWeatherState())) { event.setCancelled(true); } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java b/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java index b415cbf4..9d6e8085 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java @@ -134,7 +134,7 @@ public class WorldConfig extends GameRuleProvider { keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath"); } - /* World interaction */ + /* World */ if (configFile.contains("gameMode")) { if (EnumUtil.isValidEnum(GameMode.class, configFile.getString("gameMode").toUpperCase())) { gameMode = GameMode.valueOf(configFile.getString("gameMode")); @@ -184,6 +184,18 @@ public class WorldConfig extends GameRuleProvider { } } + if (configFile.contains("rain")) { + rain = configFile.getBoolean("rain"); + } + + if (configFile.contains("thunder")) { + thunder = configFile.getBoolean("thunder"); + } + + if (configFile.contains("time")) { + time = configFile.getLong("time"); + } + /* PvP */ if (configFile.contains("playerVersusPlayer")) { playerVersusPlayer = configFile.getBoolean("playerVersusPlayer");