diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java index dbfd37768..f74e6ce27 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java @@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands; import com.github.intellectualsites.plotsquared.commands.Command; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; @@ -12,7 +12,6 @@ import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -41,11 +40,10 @@ import java.util.concurrent.CompletableFuture; Set plots = plot.getConnectedPlots(); checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(), Captions.CANT_CLAIM_MORE_PLOTS); - Optional flag = plot.getFlag(Flags.PRICE); - if (!flag.isPresent()) { + double price = plot.getFlag(PriceFlag.class); + if (price <= 0) { throw new CommandException(Captions.NOT_FOR_SALE); } - final double price = flag.get(); checkTrue(player.getMoney() >= price, Captions.CANNOT_AFFORD_PLOT); player.withdraw(price); // Failure @@ -58,7 +56,7 @@ import java.util.concurrent.CompletableFuture; if (owner != null) { Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price); } - plot.removeFlag(Flags.PRICE); + plot.removeFlag(PriceFlag.class); plot.setOwner(player.getUUID()); Captions.CLAIMED.send(player); whenDone.run(Buy.this, CommandResult.SUCCESS); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java index 6fc1b7c5e..cecb42d56 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java @@ -4,8 +4,8 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared.SortType; import com.github.intellectualsites.plotsquared.plot.config.Captions; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; -import java.util.Optional; import java.util.UUID; @CommandDeclaration(command = "list", aliases = {"l", "find", "search"}, description = "List plots", @@ -248,8 +247,7 @@ public class ListCmd extends SubCommand { } plots = new ArrayList<>(); for (Plot plot : PlotSquared.get().getPlots()) { - Optional price = plot.getFlag(Flags.PRICE); - if (price.isPresent()) { + if (plot.getFlag(PriceFlag.class) > 0) { plots.add(plot); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index 36d8593e7..e393bad70 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -609,6 +609,7 @@ public enum Captions implements Caption { FLAG_DESCRIPTION_NOTIFY_LEAVE("Set to `true` to notify the plot owners when someone leaves the plot.", "Flags"), FLAG_DESCRIPTION_NO_WORLDEDIT("Set to `true` to disable WorldEdit usage within the plot.", "Flags"), FLAG_DESCRIPTION_PLAYER_INTERACT("Set to `true` to allow guests to interact with players in the plot.", "Flags"), + FLAG_DESCRIPTION_PRICE("Set a price for a plot. Must be a positive decimal number.", "Flags"), FLAG_DESCRIPTION_PVE("Set to `true` to enable PVE inside the plot.", "Flags"), FLAG_DESCRIPTION_PVP("Set to `true` to enable PVP inside the plot.", "Flags"), FLAG_DESCRIPTION_REDSTONE("Set to `false` to disable redstone in the plot.", "Flags"), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index 0d060d815..c25aa8436 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -6,21 +6,9 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; public final class Flags { - public static final IntervalFlag FEED = new IntervalFlag("feed"); - public static final IntervalFlag HEAL = new IntervalFlag("heal"); public static final GameModeFlag GAMEMODE = new GameModeFlag("gamemode"); public static final GameModeFlag GUEST_GAMEMODE = new GameModeFlag("guest-gamemode"); public static final LongFlag TIME = new LongFlag("time"); - public static final DoubleFlag PRICE = new DoubleFlag("price") { - @Override public Double parseValue(String input) { - Double value = super.parseValue(input); - return value != null && value > 0 ? value : null; - } - - @Override public String getValueDescription() { - return Captions.FLAG_ERROR_DOUBLE.getTranslated(); - } - }; public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds"); public static final BlockStateListFlag USE = new BlockStateListFlag("use"); public static final BlockStateListFlag BREAK = new BlockStateListFlag("break"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java index 1c81cdbb4..a2b98b396 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java @@ -46,6 +46,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Notif import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyLeaveFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlayerInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlotWeatherFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PveFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PvpFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.RedstoneFlag; @@ -148,6 +149,9 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(FeedFlag.FEED_NOTHING); this.addFlag(HealFlag.HEAL_NOTHING); + // Double flags + this.addFlag(PriceFlag.PRICE_NOT_BUYABLE); + // Internal flags this.addFlag(new AnalysisFlag(Collections.emptyList())); this.addFlag(new DoneFlag("")); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/PriceFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/PriceFlag.java new file mode 100644 index 000000000..fd77fd3eb --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/PriceFlag.java @@ -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.DoubleFlag; +import org.jetbrains.annotations.NotNull; + +public class PriceFlag extends DoubleFlag { + public static final PriceFlag PRICE_NOT_BUYABLE = new PriceFlag(0D); + + protected PriceFlag(@NotNull Double value) { + super(value, Double.MIN_NORMAL, Double.MAX_VALUE, Captions.FLAG_DESCRIPTION_PRICE); + } + + @Override protected PriceFlag flagOf(@NotNull Double value) { + return new PriceFlag(value); + } +}