Fix interval flags (fixes #2302)

This commit is contained in:
Sauilitired 2019-04-01 10:17:50 +02:00
parent 14badf8cfc
commit c450e4aed3
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
2 changed files with 25 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.bukkit.events.PlayerEnterPlotEve
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.listener.PlotListener;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -130,12 +131,12 @@ import java.util.UUID;
@EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
Player player = event.getPlayer();
Plot plot = event.getPlot();
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
Optional<IntervalFlag.Interval> feed = plot.getFlag(Flags.FEED);
feed.ifPresent(
value -> feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20)));
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
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[0], value[1], 20)));
value -> healRunnable.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20)));
}
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) {

View File

@ -1,17 +1,20 @@
package com.github.intellectualsites.plotsquared.plot.flag;
public class IntervalFlag extends Flag<Integer[]> {
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
public class IntervalFlag extends Flag<IntervalFlag.Interval> {
public IntervalFlag(String name) {
super(name);
}
@Override public String valueToString(Object value) {
Integer[] value1 = (Integer[]) value;
return value1[0] + " " + value1[1];
return value.toString();
}
@Override public Integer[] parseValue(String value) {
@Override public Interval parseValue(String value) {
int seconds;
int amount;
String[] values = value.split(" ");
@ -32,10 +35,22 @@ public class IntervalFlag extends Flag<Integer[]> {
} else {
return null;
}
return new Integer[] {amount, seconds};
return new Interval(amount, seconds);
}
@Override public String getValueDescription() {
return "Value(s) must be numeric. /plot set flag <flag> <interval> [amount]";
}
@EqualsAndHashCode @RequiredArgsConstructor @Getter public static final class Interval {
private final int val1;
private final int val2;
public String toString() {
return String.format("%d %d", this.val1, this.val2);
}
}
}