mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-30 00:56:45 +01:00
Port TimeFlag
This commit is contained in:
parent
4c18214da1
commit
baeb9aa2af
@ -621,6 +621,7 @@ public enum Captions implements Caption {
|
||||
FLAG_DESCRIPTION_SOIL_DRY("Set to `true` to allow soil to dry within the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_TAMED_ATTACK("Set to `true` to allow guests to attack tamed animals in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_TAMED_INTERACT("Set to `true` to allow guests to interact with tamed animals in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_TIME("Set the time in the plot to a fixed value.", "Flags"),
|
||||
FLAG_DESCRIPTION_TITLES("Set to `false` to disable plot titles.", "Flags"),
|
||||
FLAG_DESCRIPTION_USE("Define a list of materials players should be able to interact with in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_VEHICLE_BREAK("Set to `true` to allow guests to break vehicles in the plot.", "Flags"),
|
||||
|
@ -6,7 +6,6 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
|
||||
public final class Flags {
|
||||
|
||||
public static final LongFlag TIME = new LongFlag("time");
|
||||
public static final Flag<?> KEEP = new Flag(Captions.FLAG_CATEGORY_MIXED, "keep") {
|
||||
@Override public String valueToString(Object value) {
|
||||
return value.toString();
|
||||
|
@ -62,6 +62,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.SnowM
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.SoilDryFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedAttackFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedInteractFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TimeFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TitlesFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.UseFlag;
|
||||
@ -153,6 +154,7 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
this.addFlag(HostileCapFlag.HOSTILE_CAP_UNLIMITED);
|
||||
this.addFlag(MiscCapFlag.MISC_CAP_UNLIMITED);
|
||||
this.addFlag(MobCapFlag.MOB_CAP_UNLIMITED);
|
||||
this.addFlag(TimeFlag.TIME_DISABLED);
|
||||
this.addFlag(VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
|
||||
|
||||
// Timed flags
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.types.LongFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TimeFlag extends LongFlag<TimeFlag> {
|
||||
public static final TimeFlag TIME_DISABLED = new TimeFlag(Long.MIN_VALUE);
|
||||
|
||||
protected TimeFlag(@NotNull Long value) {
|
||||
super(value, Captions.FLAG_DESCRIPTION_TIME);
|
||||
}
|
||||
|
||||
@Override protected TimeFlag flagOf(@NotNull Long value) {
|
||||
return new TimeFlag(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.flags.types;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Caption;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class LongFlag<F extends NumberFlag<Long, F>> extends NumberFlag<Long, F> {
|
||||
|
||||
protected LongFlag(@NotNull Long value, Long minimum, Long maximum, @NotNull Caption flagDescription) {
|
||||
super(value, minimum, maximum, Captions.FLAG_CATEGORY_INTEGERS, flagDescription);
|
||||
}
|
||||
|
||||
protected LongFlag(@NotNull Long value,@NotNull Caption flagDescription) {
|
||||
this(value, Long.MIN_VALUE, Long.MAX_VALUE, flagDescription);
|
||||
}
|
||||
|
||||
@Override public F merge(@NotNull Long newValue) {
|
||||
return flagOf(getValue() + newValue);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return getValue().toString();
|
||||
}
|
||||
|
||||
@Override public String getExample() {
|
||||
return "123456789";
|
||||
}
|
||||
|
||||
@NotNull @Override protected Long parseNumber(String input) throws FlagParseException {
|
||||
try {
|
||||
return Long.parseLong(input);
|
||||
} catch (Throwable throwable) {
|
||||
throw new FlagParseException(this, input, Captions.NOT_A_NUMBER, input);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Music
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyEnterFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyLeaveFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlotWeatherFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TimeFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TitlesFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
@ -142,13 +143,12 @@ public class PlotListener {
|
||||
}
|
||||
}
|
||||
|
||||
Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
|
||||
if (timeFlag.isPresent() && !player.getAttribute("disabletime")) {
|
||||
long time = plot.getFlag(TimeFlag.class);
|
||||
if (time != TimeFlag.TIME_DISABLED.getValue() && !player.getAttribute("disabletime")) {
|
||||
try {
|
||||
long time = timeFlag.get();
|
||||
player.setTime(time);
|
||||
} catch (Exception ignored) {
|
||||
FlagManager.removePlotFlag(plot, Flags.TIME);
|
||||
plot.removeFlag(TimeFlag.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ public class PlotListener {
|
||||
}
|
||||
}
|
||||
|
||||
if (plot.getFlag(Flags.TIME).isPresent()) {
|
||||
if (plot.getFlag(TimeFlag.class) != TimeFlag.TIME_DISABLED.getValue().longValue()) {
|
||||
player.setTime(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user