diff --git a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java index bf7f3c15..265fd8d5 100644 --- a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -21,6 +21,7 @@ import org.bukkit.ChatColor; import org.bukkit.GameMode; +import org.bukkit.WeatherType; import org.bukkit.entity.EntityType; /** @@ -118,6 +119,7 @@ public final class DefaultFlag { public static final SetFlag DENY_SPAWN = new SetFlag("deny-spawn", new EntityTypeFlag(null)); public static final EnumFlag GAME_MODE = new EnumFlag("game-mode", GameMode.class); public static final StringFlag TIME_LOCK = new StringFlag("time-lock"); + public static final EnumFlag WEATHER_LOCK = new EnumFlag("weather-lock", WeatherType.class); public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay"); public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount"); public static final DoubleFlag MIN_HEAL = new DoubleFlag("heal-min-health"); @@ -150,7 +152,7 @@ public final class DefaultFlag { SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, SOIL_DRY, GAME_MODE, MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, MYCELIUM_SPREAD, VINE_GROWTH, SEND_CHAT, RECEIVE_CHAT, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW, - TELE_LOC, SPAWN_LOC, POTION_SPLASH, TIME_LOCK, + TELE_LOC, SPAWN_LOC, POTION_SPLASH, TIME_LOCK, WEATHER_LOCK, BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE, ENABLE_SHOP }; diff --git a/src/main/java/com/sk89q/worldguard/session/SessionManager.java b/src/main/java/com/sk89q/worldguard/session/SessionManager.java index 29ac56a1..e8a508d0 100644 --- a/src/main/java/com/sk89q/worldguard/session/SessionManager.java +++ b/src/main/java/com/sk89q/worldguard/session/SessionManager.java @@ -148,6 +148,7 @@ private Session createSession(Player player) { session.register(new GameModeFlag(session)); session.register(new InvincibilityFlag(session)); session.register(new TimeLockFlag(session)); + session.register(new WeatherLockFlag(session)); session.register(new GodMode(session)); session.register(new WaterBreathing(session)); session.initialize(player); diff --git a/src/main/java/com/sk89q/worldguard/session/handler/WeatherLockFlag.java b/src/main/java/com/sk89q/worldguard/session/handler/WeatherLockFlag.java new file mode 100644 index 00000000..f7c5c112 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/session/handler/WeatherLockFlag.java @@ -0,0 +1,68 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.session.handler; + +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.DefaultFlag; +import com.sk89q.worldguard.session.MoveType; +import com.sk89q.worldguard.session.Session; +import org.bukkit.Location; +import org.bukkit.WeatherType; +import org.bukkit.entity.Player; + +import javax.annotation.Nullable; + +public class WeatherLockFlag extends FlagValueChangeHandler { + + private WeatherType initialWeather; + + public WeatherLockFlag(Session session) { + super(session, DefaultFlag.WEATHER_LOCK); + } + + private void updatePlayerWeather(Player player, @Nullable WeatherType value) { + initialWeather = player.getPlayerWeather(); + player.setPlayerWeather(value); + } + + @Override + protected void onInitialValue(Player player, ApplicableRegionSet set, WeatherType value) { + initialWeather = player.getPlayerWeather(); + updatePlayerWeather(player, value); + } + + @Override + protected boolean onSetValue(Player player, Location from, Location to, ApplicableRegionSet toSet, WeatherType currentValue, WeatherType lastValue, MoveType moveType) { + updatePlayerWeather(player, currentValue); + return true; + } + + @Override + protected boolean onAbsentValue(Player player, Location from, Location to, ApplicableRegionSet toSet, WeatherType lastValue, MoveType moveType) { + if (initialWeather != null) { + player.setPlayerWeather(initialWeather); + } else { + player.resetPlayerWeather(); + } + initialWeather = null; + return true; + } + +}