mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Port keep flag
This commit is contained in:
parent
8df1248929
commit
824f4935ea
@ -7,8 +7,6 @@ import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.TeleportDenyFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalAttackFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalInteractFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag;
|
||||
@ -178,7 +176,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -5,7 +5,6 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Caption;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
|
@ -3,7 +3,6 @@ package com.github.intellectualsites.plotsquared.plot.commands;
|
||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
|
@ -4,7 +4,6 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HideInfoFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
|
||||
|
@ -2,7 +2,6 @@ package com.github.intellectualsites.plotsquared.plot.commands;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
|
||||
|
@ -6,7 +6,6 @@ import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
|
@ -634,6 +634,7 @@ public enum Captions implements Caption {
|
||||
FLAG_DESCRIPTION_GAMEMODE("Determines the gamemode in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_GUEST_GAMEMODE("Determines the guest gamemode in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_BLOCKED_CMDS("A list of commands that are blocked in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_KEEP("Prevents the plot from expiring. Can be set to: true, false, the number of milliseconds to keep the plot for or a timestamp (3w 2d 5h).", "Flags"),
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Flag category errors">
|
||||
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
|
||||
|
@ -1,33 +0,0 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.flag;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
|
||||
public final class Flags {
|
||||
|
||||
public static final Flag<?> KEEP = new Flag(Captions.FLAG_CATEGORY_MIXED, "keep") {
|
||||
@Override public String valueToString(Object value) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
@Override public Object parseValue(String value) {
|
||||
if (MathMan.isInteger(value)) {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
switch (value.toLowerCase()) {
|
||||
case "true":
|
||||
return true;
|
||||
case "false":
|
||||
return false;
|
||||
default:
|
||||
return MainUtil.timeToSec(value) * 1000 + System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String getValueDescription() {
|
||||
return Captions.FLAG_ERROR_KEEP.getTranslated();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -37,6 +37,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.IceMe
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.InstabreakFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.InvincibleFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ItemDropFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.KeepFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.KelpGrowFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.LiquidFlowFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscBreakFlag;
|
||||
@ -173,6 +174,7 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
this.addFlag(GamemodeFlag.GAMEMODE_FLAG_DEFAULT);
|
||||
this.addFlag(GuestGamemodeFlag.GUEST_GAMEMODE_FLAG_DEFAULT);
|
||||
this.addFlag(BlockedCmdsFlag.BLOCKED_CMDS_FLAG_NONE);
|
||||
this.addFlag(KeepFlag.KEEP_FLAG_FALSE);
|
||||
|
||||
// Internal flags
|
||||
this.addFlag(new AnalysisFlag(Collections.emptyList()));
|
||||
|
@ -0,0 +1,75 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class KeepFlag extends PlotFlag<Object, KeepFlag> {
|
||||
|
||||
public static final KeepFlag KEEP_FLAG_FALSE = new KeepFlag(false);
|
||||
|
||||
/**
|
||||
* Construct a new flag instance.
|
||||
*
|
||||
* @param value Flag value
|
||||
*/
|
||||
protected KeepFlag(@NotNull Object value) {
|
||||
super(value, Captions.FLAG_CATEGORY_MIXED, Captions.FLAG_DESCRIPTION_KEEP);
|
||||
}
|
||||
|
||||
@Override public KeepFlag parse(@NotNull String input) throws FlagParseException {
|
||||
if (MathMan.isInteger(input)) {
|
||||
final long value = Long.parseLong(input);
|
||||
if (value < 0) {
|
||||
throw new FlagParseException(this, input, Captions.FLAG_ERROR_KEEP);
|
||||
} else {
|
||||
return flagOf(value);
|
||||
}
|
||||
}
|
||||
switch (input.toLowerCase()) {
|
||||
case "true":
|
||||
return flagOf(true);
|
||||
case "false":
|
||||
return flagOf(false);
|
||||
default:
|
||||
return flagOf(MainUtil.timeToSec(input) * 1000 + System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@Override public KeepFlag merge(@NotNull Object newValue) {
|
||||
if (newValue.equals(true)) {
|
||||
return flagOf(true);
|
||||
} else if (newValue.equals(false)) {
|
||||
if (getValue().equals(true) || getValue().equals(false)) {
|
||||
return this;
|
||||
} else {
|
||||
return flagOf(newValue);
|
||||
}
|
||||
} else {
|
||||
if (getValue().equals(true)) {
|
||||
return this;
|
||||
} else if (getValue().equals(false)) {
|
||||
return flagOf(newValue);
|
||||
} else {
|
||||
long currentValue = (long) getValue();
|
||||
return flagOf((long) newValue + currentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return getValue().toString();
|
||||
}
|
||||
|
||||
@Override public String getExample() {
|
||||
return "3w 4d 2h";
|
||||
}
|
||||
|
||||
@Override protected KeepFlag flagOf(@NotNull Object value) {
|
||||
return new KeepFlag(value);
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,6 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FarewellFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
|
||||
@ -39,7 +38,6 @@ import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlotListener {
|
||||
|
@ -7,10 +7,10 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.KeepFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.SquarePlotWorld;
|
||||
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
|
||||
@ -40,7 +40,6 @@ import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -59,7 +58,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -1091,7 +1089,7 @@ public class Plot {
|
||||
* @param value Flag value
|
||||
*/
|
||||
public <V> boolean setFlag(PlotFlag<V, ?> flag, V value) {
|
||||
if (flag == Flags.KEEP && ExpireManager.IMP != null) {
|
||||
if (flag instanceof KeepFlag && ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.updateExpired(this);
|
||||
}
|
||||
return FlagManager.addPlotFlag(this, flag, value);
|
||||
|
@ -7,7 +7,6 @@ import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
|
||||
|
@ -11,7 +11,6 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.DoubleFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ServerPlotFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer;
|
||||
@ -52,7 +51,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -5,7 +5,6 @@ import com.github.intellectualsites.plotsquared.json.JSONException;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.ClassicPlotWorld;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
|
@ -4,10 +4,9 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnalysisFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.KeepFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
@ -28,7 +27,6 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -445,9 +443,9 @@ public class ExpireManager {
|
||||
|| UUIDHandler.getPlayer(plot.getOwner()) != null || plot.getRunning() > 0) {
|
||||
return 0;
|
||||
}
|
||||
Optional<?> keep = plot.getFlag(Flags.KEEP);
|
||||
if (keep.isPresent()) {
|
||||
Object value = keep.get();
|
||||
|
||||
final Object value = plot.getFlag(KeepFlag.class);
|
||||
if (!value.equals(false)) {
|
||||
if (value instanceof Boolean) {
|
||||
if (Boolean.TRUE.equals(value)) {
|
||||
return 0;
|
||||
|
@ -2,23 +2,10 @@ package com.github.intellectualsites.plotsquared.plot;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.database.AbstractDBTest;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EventUtilTest;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user