mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Fix interval flags (fixes #2302)
This commit is contained in:
parent
14badf8cfc
commit
c450e4aed3
@ -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.events.PlayerLeavePlotEvent;
|
||||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
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.listener.PlotListener;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
@ -130,12 +131,12 @@ import java.util.UUID;
|
|||||||
@EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
|
@EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Plot plot = event.getPlot();
|
Plot plot = event.getPlot();
|
||||||
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
|
Optional<IntervalFlag.Interval> feed = plot.getFlag(Flags.FEED);
|
||||||
feed.ifPresent(
|
feed.ifPresent(
|
||||||
value -> feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20)));
|
value -> feedRunnable.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20)));
|
||||||
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
|
Optional<IntervalFlag.Interval> heal = plot.getFlag(Flags.HEAL);
|
||||||
heal.ifPresent(
|
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) {
|
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.flag;
|
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) {
|
public IntervalFlag(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String valueToString(Object value) {
|
@Override public String valueToString(Object value) {
|
||||||
Integer[] value1 = (Integer[]) value;
|
return value.toString();
|
||||||
return value1[0] + " " + value1[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Integer[] parseValue(String value) {
|
@Override public Interval parseValue(String value) {
|
||||||
int seconds;
|
int seconds;
|
||||||
int amount;
|
int amount;
|
||||||
String[] values = value.split(" ");
|
String[] values = value.split(" ");
|
||||||
@ -32,10 +35,22 @@ public class IntervalFlag extends Flag<Integer[]> {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Integer[] {amount, seconds};
|
return new Interval(amount, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getValueDescription() {
|
@Override public String getValueDescription() {
|
||||||
return "Value(s) must be numeric. /plot set flag <flag> <interval> [amount]";
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user