mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-30 13:14:06 +01:00
Implement PriceFlag
This commit is contained in:
parent
06c6628274
commit
085dfbf735
@ -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<Plot> plots = plot.getConnectedPlots();
|
||||
checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(),
|
||||
Captions.CANT_CLAIM_MORE_PLOTS);
|
||||
Optional<Double> 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);
|
||||
|
@ -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<Double> price = plot.getFlag(Flags.PRICE);
|
||||
if (price.isPresent()) {
|
||||
if (plot.getFlag(PriceFlag.class) > 0) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
|
@ -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"),
|
||||
|
@ -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");
|
||||
|
@ -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(""));
|
||||
|
@ -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<PriceFlag> {
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user