mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Update Flag command to current API state
This commit is contained in:
parent
ff554560d9
commit
06c6628274
@ -3,12 +3,13 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.IntervalFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DropProtectionFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FeedFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HealFlag;
|
||||
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.types.TimedFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
@ -32,7 +33,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
|
||||
@ -135,12 +135,14 @@ import java.util.UUID;
|
||||
@EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Plot plot = event.getPlot();
|
||||
Optional<IntervalFlag.Interval> feed = plot.getFlag(Flags.FEED);
|
||||
feed.ifPresent(value -> feedRunnable
|
||||
.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20)));
|
||||
Optional<IntervalFlag.Interval> heal = plot.getFlag(Flags.HEAL);
|
||||
heal.ifPresent(value -> healRunnable
|
||||
.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20)));
|
||||
TimedFlag.Timed<Integer> feed = plot.getFlag(FeedFlag.class);
|
||||
if (feed.getInterval() != 0 && feed.getValue() != 0) {
|
||||
feedRunnable.put(player.getUniqueId(), new Interval(feed.getInterval(), feed.getValue(), 20));
|
||||
}
|
||||
TimedFlag.Timed<Integer> heal = plot.getFlag(HealFlag.class);
|
||||
if (heal.getInterval() != 0 && heal.getValue() != 0) {
|
||||
healRunnable.put(player.getUniqueId(), new Interval(heal.getInterval(), heal.getValue(), 20));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
|
@ -444,6 +444,9 @@ public enum Captions implements Caption {
|
||||
NOT_VALID_NUMBER("$2That's not a valid number within the range: %s", "Invalid"),
|
||||
NOT_VALID_PLOT_ID("$2That's not a valid plot id.", "Invalid"),
|
||||
FOUND_NO_PLOTS("$2Found no plots with your search query", "Invalid"),
|
||||
NUMBER_NOT_IN_RANGE("That's not a valid number within the range: (%s, %s)", "Invalid"),
|
||||
NUMBER_NOT_POSITIVE("That's not a positive number: %s", "Invalid"),
|
||||
NOT_A_NUMBER("%s is not a valid number.", "Invalid"),
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Need">
|
||||
NEED_BLOCK("$2You've got to specify a block", "Need"),
|
||||
@ -577,10 +580,12 @@ public enum Captions implements Caption {
|
||||
FLAG_DESCRIPTION_DEVICE_INTERACT("Set to `true` to allow devices to be interacted with in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_DISABLE_PHYSICS("Set to `true` to disable block physics in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_DROP_PROTECTION("Set to `true` to prevent dropped items from being picked up by non-members of the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_FEED("Specify an interval in seconds and an optional amount by which the players will be fed (amount is 1 by default).", "Flags"),
|
||||
FLAG_DESCRIPTION_FORCEFIELD("Set to `true` to enable member forcefield in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_GRASS_GROW("Set to `false` to disable grass to grow within the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_HANGING_BREAK("Set to `true` to allow guests to break hanging objects in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_HANGING_PLACE("Set to `true` to allow guests to hang objects in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_HEAL("Specify an interval in seconds and an optional amount by which the players will be healed (amount is 1 by default).", "Flags"),
|
||||
FLAG_DESCRIPTION_HIDE_INFO("Set to `true` to hide plot information.", "Flags"),
|
||||
FLAG_DESCRIPTION_HOSTILE_ATTACK("Set to `true` to enable players to attack hostile mobs in the plot.", "Flags"),
|
||||
FLAG_DESCRIPTION_HOSTILE_CAP("Set to an integer value to limit the amount of hostile entities on the plot.", "Flags"),
|
||||
|
@ -15,12 +15,14 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.DropP
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.EntityCapFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FarewellFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FeedFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ForcefieldFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingBreakFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingPlaceFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HealFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HideInfoFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileAttackFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileCapFlag;
|
||||
@ -134,7 +136,7 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
this.addFlag(InstabreakFlag.INSTABREAK_FALSE);
|
||||
this.addFlag(InvincibleFlag.INVINCIBLE_FALSE);
|
||||
|
||||
//Integer flags
|
||||
// Integer flags
|
||||
this.addFlag(AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
||||
this.addFlag(EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
||||
this.addFlag(HostileCapFlag.HOSTILE_CAP_UNLIMITED);
|
||||
@ -142,6 +144,10 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
this.addFlag(MobCapFlag.MOB_CAP_UNLIMITED);
|
||||
this.addFlag(VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
|
||||
|
||||
// Timed flags
|
||||
this.addFlag(FeedFlag.FEED_NOTHING);
|
||||
this.addFlag(HealFlag.HEAL_NOTHING);
|
||||
|
||||
// Internal flags
|
||||
this.addFlag(new AnalysisFlag(Collections.emptyList()));
|
||||
this.addFlag(new DoneFlag(""));
|
||||
|
@ -0,0 +1,39 @@
|
||||
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.types.TimedFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FeedFlag extends TimedFlag<Integer, FeedFlag> {
|
||||
public static final FeedFlag FEED_NOTHING = new FeedFlag(new Timed<>(0, 0));
|
||||
|
||||
public FeedFlag(@NotNull Timed<Integer> value) {
|
||||
super(value, 1, Captions.FLAG_DESCRIPTION_FEED);
|
||||
}
|
||||
|
||||
@Override protected Integer parseValue(String input) throws FlagParseException {
|
||||
int parsed;
|
||||
try {
|
||||
parsed = Integer.parseInt(input);
|
||||
} catch (Throwable throwable) {
|
||||
throw new FlagParseException(this, input, Captions.NOT_A_NUMBER, input);
|
||||
}
|
||||
if (parsed < 1) {
|
||||
throw new FlagParseException(this, input, Captions.NUMBER_NOT_POSITIVE, parsed);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
@Override protected Integer mergeValue(Integer other) {
|
||||
return this.getValue().getValue() + other;
|
||||
}
|
||||
|
||||
@Override public String getExample() {
|
||||
return "10 5";
|
||||
}
|
||||
|
||||
@Override protected FeedFlag flagOf(@NotNull Timed<Integer> value) {
|
||||
return new FeedFlag(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
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.types.TimedFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HealFlag extends TimedFlag<Integer, HealFlag> {
|
||||
public static final HealFlag HEAL_NOTHING = new HealFlag(new Timed<>(0, 0));
|
||||
protected HealFlag(@NotNull Timed<Integer> value) {
|
||||
super(value, 1, Captions.FLAG_DESCRIPTION_HEAL);
|
||||
}
|
||||
|
||||
@Override protected Integer parseValue(String input) throws FlagParseException {
|
||||
int parsed;
|
||||
try {
|
||||
parsed = Integer.parseInt(input);
|
||||
} catch (Throwable throwable) {
|
||||
throw new FlagParseException(this, input, Captions.NOT_A_NUMBER, input);
|
||||
}
|
||||
if (parsed < 1) {
|
||||
throw new FlagParseException(this, input, Captions.NUMBER_NOT_POSITIVE, parsed);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
@Override protected Integer mergeValue(Integer other) {
|
||||
return this.getValue().getValue() + other;
|
||||
}
|
||||
|
||||
@Override public String getExample() {
|
||||
return "20 2";
|
||||
}
|
||||
|
||||
@Override protected HealFlag flagOf(@NotNull Timed<Integer> value) {
|
||||
return new HealFlag(value);
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ public abstract class NumberFlag<N extends Number & Comparable<N>, F extends Plo
|
||||
final N parsed = parseNumber(input);
|
||||
if (parsed.compareTo(minimum) < 0 || parsed.compareTo(maximum) > 0) {
|
||||
throw new FlagParseException(this, input,
|
||||
Captions.NOT_VALID_NUMBER); // TODO format Caption, provide valid range
|
||||
Captions.NUMBER_NOT_IN_RANGE, minimum, maximum);
|
||||
}
|
||||
return flagOf(parsed);
|
||||
|
||||
|
@ -0,0 +1,68 @@
|
||||
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 com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class TimedFlag<T, F extends PlotFlag<TimedFlag.Timed<T>, F>> extends PlotFlag<TimedFlag.Timed<T>, F> {
|
||||
private final T defaultValue;
|
||||
|
||||
protected TimedFlag(@NotNull Timed<T> value, T defaultValue, @NotNull Caption flagDescription) {
|
||||
super(value, Captions.FLAG_CATEGORY_INTERVALS, flagDescription);
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
@Override public F parse(@NotNull String input) throws FlagParseException {
|
||||
String[] split = input.split(" ", 2);
|
||||
int interval;
|
||||
try {
|
||||
interval = Integer.parseInt(split[0]);
|
||||
} catch (Throwable throwable) {
|
||||
throw new FlagParseException(this, input, Captions.NOT_A_NUMBER, split[0]);
|
||||
}
|
||||
if (interval < 1) {
|
||||
throw new FlagParseException(this, input, Captions.NUMBER_NOT_POSITIVE, split[0]);
|
||||
}
|
||||
if (split.length == 1) {
|
||||
return flagOf(new Timed<>(interval, defaultValue));
|
||||
}
|
||||
final T parsedValue = parseValue(split[1]);
|
||||
return flagOf(new Timed<>(interval, parsedValue));
|
||||
}
|
||||
|
||||
@Override public F merge(@NotNull Timed<T> newValue) {
|
||||
return flagOf(new Timed<>(getValue().interval + newValue.interval, mergeValue(newValue.value)));
|
||||
}
|
||||
|
||||
protected abstract T parseValue(String input) throws FlagParseException;
|
||||
|
||||
protected abstract T mergeValue(T other);
|
||||
|
||||
@Override public String toString() {
|
||||
return getValue().toString();
|
||||
}
|
||||
|
||||
public static final class Timed<T> {
|
||||
private final int interval;
|
||||
private final T value;
|
||||
|
||||
public Timed(int interval, T value) {
|
||||
this.interval = interval;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return String.format("%d %s", interval, value);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user