mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 04:55:37 +01:00
Added time-lock flag.
Valid values are 0 to 24000 for absolute time, or +- any number for relative time. Closes WORLDGUARD-3379.
This commit is contained in:
parent
c9d6166fcb
commit
99d042d260
@ -117,6 +117,7 @@ public final class DefaultFlag {
|
|||||||
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave");
|
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave");
|
||||||
public static final SetFlag<EntityType> DENY_SPAWN = new SetFlag<EntityType>("deny-spawn", new EntityTypeFlag(null));
|
public static final SetFlag<EntityType> DENY_SPAWN = new SetFlag<EntityType>("deny-spawn", new EntityTypeFlag(null));
|
||||||
public static final EnumFlag<GameMode> GAME_MODE = new EnumFlag<GameMode>("game-mode", GameMode.class);
|
public static final EnumFlag<GameMode> GAME_MODE = new EnumFlag<GameMode>("game-mode", GameMode.class);
|
||||||
|
public static final StringFlag TIME_LOCK = new StringFlag("time-lock");
|
||||||
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
|
public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay");
|
||||||
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount");
|
public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount");
|
||||||
public static final DoubleFlag MIN_HEAL = new DoubleFlag("heal-min-health");
|
public static final DoubleFlag MIN_HEAL = new DoubleFlag("heal-min-health");
|
||||||
@ -149,7 +150,7 @@ public final class DefaultFlag {
|
|||||||
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, SOIL_DRY, GAME_MODE,
|
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, SOIL_DRY, GAME_MODE,
|
||||||
MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, MYCELIUM_SPREAD, VINE_GROWTH,
|
MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, MYCELIUM_SPREAD, VINE_GROWTH,
|
||||||
SEND_CHAT, RECEIVE_CHAT, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW,
|
SEND_CHAT, RECEIVE_CHAT, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW,
|
||||||
TELE_LOC, SPAWN_LOC, POTION_SPLASH,
|
TELE_LOC, SPAWN_LOC, POTION_SPLASH, TIME_LOCK,
|
||||||
BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE, ENABLE_SHOP
|
BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE, ENABLE_SHOP
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -147,6 +147,7 @@ private Session createSession(Player player) {
|
|||||||
session.register(new FarewellFlag(session));
|
session.register(new FarewellFlag(session));
|
||||||
session.register(new GameModeFlag(session));
|
session.register(new GameModeFlag(session));
|
||||||
session.register(new InvincibilityFlag(session));
|
session.register(new InvincibilityFlag(session));
|
||||||
|
session.register(new TimeLockFlag(session));
|
||||||
session.register(new GodMode(session));
|
session.register(new GodMode(session));
|
||||||
session.register(new WaterBreathing(session));
|
session.register(new WaterBreathing(session));
|
||||||
session.initialize(player);
|
session.initialize(player);
|
||||||
|
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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.entity.Player;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class TimeLockFlag extends FlagValueChangeHandler<String> {
|
||||||
|
|
||||||
|
private Long time;
|
||||||
|
private boolean relative;
|
||||||
|
private Long initialTime;
|
||||||
|
private boolean initialRelative;
|
||||||
|
|
||||||
|
Pattern timePattern = Pattern.compile("(\\+|-)?\\d+");
|
||||||
|
|
||||||
|
public TimeLockFlag(Session session) {
|
||||||
|
super(session, DefaultFlag.TIME_LOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePlayerTime(Player player, @Nullable String value) {
|
||||||
|
// store settings, regardless of if we change anything
|
||||||
|
initialRelative = player.isPlayerTimeRelative();
|
||||||
|
initialTime = player.getPlayerTime();
|
||||||
|
if (value == null || !timePattern.matcher(value).matches()) {
|
||||||
|
// invalid input
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (value.startsWith("+") || value.startsWith("-")) {
|
||||||
|
relative = true;
|
||||||
|
} else {
|
||||||
|
relative = false;
|
||||||
|
}
|
||||||
|
time = Long.valueOf(value);
|
||||||
|
if (!relative && (time < 0L || time > 24000L)) { // invalid time, reset to 0
|
||||||
|
time = 0L;
|
||||||
|
}
|
||||||
|
player.setPlayerTime(time, relative);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInitialValue(Player player, ApplicableRegionSet set, String value) {
|
||||||
|
initialTime = player.getPlayerTime();
|
||||||
|
initialRelative = player.isPlayerTimeRelative();
|
||||||
|
updatePlayerTime(player, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean onSetValue(Player player, Location from, Location to, ApplicableRegionSet toSet, String currentValue, String lastValue, MoveType moveType) {
|
||||||
|
updatePlayerTime(player, currentValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean onAbsentValue(Player player, Location from, Location to, ApplicableRegionSet toSet, String lastValue, MoveType moveType) {
|
||||||
|
player.setPlayerTime(initialTime, initialRelative);
|
||||||
|
initialRelative = true;
|
||||||
|
initialTime = 0L;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user