diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java index b4dafdfc2..78b3dc269 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlotPlusListener.java @@ -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 feed = plot.getFlag(Flags.FEED); + Optional feed = plot.getFlag(Flags.FEED); feed.ifPresent( - value -> feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20))); - Optional heal = plot.getFlag(Flags.HEAL); + value -> feedRunnable.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20))); + Optional 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) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntervalFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntervalFlag.java index ab7100cb6..c8f490591 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntervalFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntervalFlag.java @@ -1,17 +1,20 @@ package com.github.intellectualsites.plotsquared.plot.flag; -public class IntervalFlag extends Flag { +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +public class IntervalFlag extends Flag { 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 { } 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 [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); + } + + } + }