mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
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:
parent
df5feff9ec
commit
179e9e1e74
@ -76,19 +76,18 @@ public class Auto extends SubCommand {
|
|||||||
} else {
|
} else {
|
||||||
currentPlots = player.getPlotCount(plotarea.getWorldName());
|
currentPlots = player.getPlotCount(plotarea.getWorldName());
|
||||||
}
|
}
|
||||||
int diff = currentPlots - allowedPlots;
|
int diff = allowedPlots - currentPlots;
|
||||||
if (diff + sizeX * sizeZ > 0) {
|
if (diff - sizeX * sizeZ < 0) {
|
||||||
if (diff < 0) {
|
if (player.hasPersistentMeta("grantedPlots")) {
|
||||||
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS_NUM, -diff + "");
|
|
||||||
return false;
|
|
||||||
} else if (player.hasPersistentMeta("grantedPlots")) {
|
|
||||||
int grantedPlots = Ints.fromByteArray(player.getPersistentMeta("grantedPlots"));
|
int grantedPlots = Ints.fromByteArray(player.getPersistentMeta("grantedPlots"));
|
||||||
if (grantedPlots - diff < sizeX * sizeZ) {
|
if (diff < 0 && grantedPlots < sizeX * sizeZ) {
|
||||||
player.removePersistentMeta("grantedPlots");
|
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);
|
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
int left = grantedPlots - diff - sizeX * sizeZ;
|
int left = grantedPlots + diff < 0 ? 0 : diff - sizeX * sizeZ;
|
||||||
if (left == 0) {
|
if (left == 0) {
|
||||||
player.removePersistentMeta("grantedPlots");
|
player.removePersistentMeta("grantedPlots");
|
||||||
} else {
|
} else {
|
||||||
@ -134,24 +133,10 @@ public class Auto extends SubCommand {
|
|||||||
*/
|
*/
|
||||||
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start,
|
public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start,
|
||||||
final String schematic) {
|
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);
|
player.setMeta(Auto.class.getName(), true);
|
||||||
autoClaimFromDatabase(player, area, start, new RunnableVal<Plot>() {
|
autoClaimFromDatabase(player, area, start, new RunnableVal<Plot>() {
|
||||||
@Override public void run(final Plot plot) {
|
@Override public void run(final Plot plot) {
|
||||||
TaskManager.IMP
|
TaskManager.IMP.sync(new AutoClaimFinishTask(player, plot, area, schematic));
|
||||||
.sync(new AutoClaimFinishTask(player, plot, area, allowedPlots, schematic));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -282,7 +267,7 @@ public class Auto extends SubCommand {
|
|||||||
}
|
}
|
||||||
// TODO handle type 2 (partial) the same as normal worlds!
|
// TODO handle type 2 (partial) the same as normal worlds!
|
||||||
if (size_x == 1 && size_z == 1) {
|
if (size_x == 1 && size_z == 1) {
|
||||||
autoClaimSafe(player, plotarea, null, schematic, allowed_plots);
|
autoClaimSafe(player, plotarea, null, schematic);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (plotarea.getType() == PlotAreaType.PARTIAL) {
|
if (plotarea.getType() == PlotAreaType.PARTIAL) {
|
||||||
|
@ -122,7 +122,7 @@ public class Claim extends SubCommand {
|
|||||||
} else {
|
} else {
|
||||||
player.setPersistentMeta("grantedPlots", Ints.toByteArray(grants - 1));
|
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();
|
int border = area.getBorder();
|
||||||
if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) {
|
if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) {
|
||||||
|
@ -322,7 +322,7 @@ public enum Captions implements Caption {
|
|||||||
CANNOT_AFFORD_MERGE("$2You cannot afford to merge the plots. It costs $1%s","Economy"),
|
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"),
|
ADDED_BALANCE("$1%s $2has been added to your balance", "Economy"),
|
||||||
REMOVED_BALANCE("$1%s $2has been taken from 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>
|
||||||
//<editor-fold desc="Setup">
|
//<editor-fold desc="Setup">
|
||||||
SETUP_INIT("$1Usage: $2/plot setup <value>", "Setup"),
|
SETUP_INIT("$1Usage: $2/plot setup <value>", "Setup"),
|
||||||
|
@ -45,7 +45,6 @@ public final class AutoClaimFinishTask extends RunnableVal<Object> {
|
|||||||
private final PlotPlayer player;
|
private final PlotPlayer player;
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
private final PlotArea area;
|
private final PlotArea area;
|
||||||
private final int allowedPlots;
|
|
||||||
private final String schematic;
|
private final String schematic;
|
||||||
|
|
||||||
@Override public void run(Object value) {
|
@Override public void run(Object value) {
|
||||||
@ -54,8 +53,6 @@ public final class AutoClaimFinishTask extends RunnableVal<Object> {
|
|||||||
sendMessage(player, Captions.NO_FREE_PLOTS);
|
sendMessage(player, Captions.NO_FREE_PLOTS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Auto.checkAllowedPlots(player, area, allowedPlots, 1, 1)) {
|
|
||||||
plot.claim(player, true, schematic, false);
|
plot.claim(player, true, schematic, false);
|
||||||
if (area.isAutoMerge()) {
|
if (area.isAutoMerge()) {
|
||||||
PlotMergeEvent event = PlotSquared.get().getEventDispatcher()
|
PlotMergeEvent event = PlotSquared.get().getEventDispatcher()
|
||||||
@ -66,9 +63,5 @@ public final class AutoClaimFinishTask extends RunnableVal<Object> {
|
|||||||
plot.autoMerge(event.getDir(), event.getMax(), player.getUUID(), true);
|
plot.autoMerge(event.getDir(), event.getMax(), player.getUUID(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
DBFunc.delete(plot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user