Clean up plot grants and plot auto

- Correct maths for calculating granted plots, etc etc
- Don't check if the player has the correct number of plots AGAIN on AutoClaimFinishTask. That's dumb.
This commit is contained in:
dordsor21 2020-05-06 11:39:34 +01:00
parent df5feff9ec
commit 179e9e1e74
4 changed files with 20 additions and 42 deletions

View File

@ -76,19 +76,18 @@ public class Auto extends SubCommand {
} else {
currentPlots = player.getPlotCount(plotarea.getWorldName());
}
int diff = currentPlots - allowedPlots;
if (diff + sizeX * sizeZ > 0) {
if (diff < 0) {
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS_NUM, -diff + "");
return false;
} else if (player.hasPersistentMeta("grantedPlots")) {
int diff = allowedPlots - currentPlots;
if (diff - sizeX * sizeZ < 0) {
if (player.hasPersistentMeta("grantedPlots")) {
int grantedPlots = Ints.fromByteArray(player.getPersistentMeta("grantedPlots"));
if (grantedPlots - diff < sizeX * sizeZ) {
player.removePersistentMeta("grantedPlots");
if (diff < 0 && grantedPlots < sizeX * sizeZ) {
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
return false;
} else if (diff >= 0 && grantedPlots + diff < sizeX * sizeZ) {
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
return false;
} else {
int left = grantedPlots - diff - sizeX * sizeZ;
int left = grantedPlots + diff < 0 ? 0 : diff - sizeX * sizeZ;
if (left == 0) {
player.removePersistentMeta("grantedPlots");
} else {
@ -134,24 +133,10 @@ public class Auto extends SubCommand {
*/
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start,
final String schematic) {
autoClaimSafe(player, area, start, schematic, null);
}
/**
* Claim a new plot for a player
*
* @param player
* @param area
* @param start
* @param schematic
*/
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start,
final String schematic, @Nullable final Integer allowedPlots) {
player.setMeta(Auto.class.getName(), true);
autoClaimFromDatabase(player, area, start, new RunnableVal<Plot>() {
@Override public void run(final Plot plot) {
TaskManager.IMP
.sync(new AutoClaimFinishTask(player, plot, area, allowedPlots, schematic));
TaskManager.IMP.sync(new AutoClaimFinishTask(player, plot, area, schematic));
}
});
}
@ -282,7 +267,7 @@ public class Auto extends SubCommand {
}
// TODO handle type 2 (partial) the same as normal worlds!
if (size_x == 1 && size_z == 1) {
autoClaimSafe(player, plotarea, null, schematic, allowed_plots);
autoClaimSafe(player, plotarea, null, schematic);
return true;
} else {
if (plotarea.getType() == PlotAreaType.PARTIAL) {

View File

@ -122,7 +122,7 @@ public class Claim extends SubCommand {
} else {
player.setPersistentMeta("grantedPlots", Ints.toByteArray(grants - 1));
}
sendMessage(player, Captions.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1));
sendMessage(player, Captions.REMOVED_GRANTED_PLOT, "1", (grants - 1));
}
int border = area.getBorder();
if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) {

View File

@ -322,7 +322,7 @@ public enum Captions implements Caption {
CANNOT_AFFORD_MERGE("$2You cannot afford to merge the plots. It costs $1%s","Economy"),
ADDED_BALANCE("$1%s $2has been added to your balance", "Economy"),
REMOVED_BALANCE("$1%s $2has been taken from your balance", "Economy"),
REMOVED_GRANTED_PLOT("$2You used %s plot grant(s), you've got $1%s $2left", "Economy"),
REMOVED_GRANTED_PLOT("$2You used %s0 plot grant(s), you've got $1%s1 $2left", "Economy"),
//</editor-fold>
//<editor-fold desc="Setup">
SETUP_INIT("$1Usage: $2/plot setup <value>", "Setup"),

View File

@ -45,7 +45,6 @@ public final class AutoClaimFinishTask extends RunnableVal<Object> {
private final PlotPlayer player;
private final Plot plot;
private final PlotArea area;
private final int allowedPlots;
private final String schematic;
@Override public void run(Object value) {
@ -54,21 +53,15 @@ public final class AutoClaimFinishTask extends RunnableVal<Object> {
sendMessage(player, Captions.NO_FREE_PLOTS);
return;
}
if (Auto.checkAllowedPlots(player, area, allowedPlots, 1, 1)) {
plot.claim(player, true, schematic, false);
if (area.isAutoMerge()) {
PlotMergeEvent event = PlotSquared.get().getEventDispatcher()
.callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player);
if (event.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Auto merge");
} else {
plot.autoMerge(event.getDir(), event.getMax(), player.getUUID(), true);
}
plot.claim(player, true, schematic, false);
if (area.isAutoMerge()) {
PlotMergeEvent event = PlotSquared.get().getEventDispatcher()
.callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player);
if (event.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Auto merge");
} else {
plot.autoMerge(event.getDir(), event.getMax(), player.getUUID(), true);
}
} else {
DBFunc.delete(plot);
}
}
}