Add plot grants for /plot auto

This commit is contained in:
Sauilitired 2016-01-16 17:48:49 +01:00
parent cf6ca67ce7
commit 830a5111f4
3 changed files with 25 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ByteArrayUtilities;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
@ -122,16 +123,31 @@ public class Auto extends SubCommand {
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
return false; return false;
} }
int removeGrants = 0;
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr); final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
final int diff = currentPlots - MainUtil.getAllowedPlots(plr); final int diff = currentPlots - MainUtil.getAllowedPlots(plr);
if ((diff + (size_x * size_z)) > 0) { if ((diff + (size_x * size_z)) > 0) {
if (diff < 0) { if (diff < 0) {
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + ""); MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
} else {
if (plr.hasPersistentMeta("grantedPlots")) {
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
if (grantedPlots < size_x * size_z) {
plr.removePersistentMeta("grantedPlots");
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
} else {
removeGrants = size_x * size_z;
}
} else { } else {
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
} }
}
if (removeGrants == 0) {
return false; return false;
} }
}
final PlotWorld pWorld = PS.get().getPlotWorld(world); final PlotWorld pWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) { if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
double cost = pWorld.PLOT_PRICE; double cost = pWorld.PLOT_PRICE;
@ -145,6 +161,11 @@ public class Auto extends SubCommand {
sendMessage(plr, C.REMOVED_BALANCE, cost + ""); sendMessage(plr, C.REMOVED_BALANCE, cost + "");
} }
} }
if (removeGrants > 0) {
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - removeGrants));
sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + removeGrants, "" + (grantedPlots - removeGrants));
}
if (!schematic.equals("")) { if (!schematic.equals("")) {
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { // if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) { if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {

View File

@ -133,7 +133,7 @@ public class Claim extends SubCommand {
if (removeGrantedPlot) { if (removeGrantedPlot) {
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - 1)); plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - 1));
sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + (grantedPlots - 1)); sendMessage(plr, C.REMOVED_GRANTED_PLOT, "1", "" + (grantedPlots - 1));
} }
if (!schematic.equals("")) { if (!schematic.equals("")) {
if (world.SCHEMATIC_CLAIM_SPECIFY) { if (world.SCHEMATIC_CLAIM_SPECIFY) {

View File

@ -258,7 +258,7 @@ public enum C {
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 a plot grant, you've got $1%s $2left", "Economy"), REMOVED_GRANTED_PLOT("$2You used %s plot grant(s), you've got $1%s $2left", "Economy"),
/* /*
* Setup Stuff * Setup Stuff
*/ */