Fix some logic

This commit is contained in:
Jesse Boyd 2016-02-28 07:04:57 +11:00
parent 01710e3ddb
commit ce8775414a
6 changed files with 54 additions and 69 deletions

View file

@ -15,27 +15,12 @@ import org.bukkit.Material;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.BufferedInputStream; import java.io.*;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.AbstractList; import java.util.*;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -175,7 +160,8 @@ public class NbtFactory {
suppress = false; suppress = false;
return result; return result;
} finally { }
finally {
if (data != null) { if (data != null) {
Closeables.close(data, suppress); Closeables.close(data, suppress);
} else if (input != null) { } else if (input != null) {

View file

@ -173,6 +173,9 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
for (UUID uuid : uuids) { for (UUID uuid : uuids) {
try { try {
final File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat"); final File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat");
if (!file.exists()) {
continue;
}
final ByteSource is = com.google.common.io.Files.asByteSource(file); final ByteSource is = com.google.common.io.Files.asByteSource(file);
final NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION); final NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
final NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit"); final NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");

View file

@ -111,27 +111,28 @@ 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 ? plr.getPlotCount() : plr.getPlotCount(plotarea.worldname); final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(plotarea.worldname);
final int diff = currentPlots - plr.getAllowedPlots(); final int diff = currentPlots - plr.getAllowedPlots();
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 { } else if (plr.hasPersistentMeta("grantedPlots")) {
if (plr.hasPersistentMeta("grantedPlots")) { int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); if (grantedPlots - diff < size_x * size_z) {
if (grantedPlots < size_x * size_z) { plr.removePersistentMeta("grantedPlots");
plr.removePersistentMeta("grantedPlots"); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
} else {
removeGrants = size_x * size_z;
}
} else { } else {
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); int left = grantedPlots - diff - (size_x * size_z);
if (left == 0) {
plr.removePersistentMeta("grantedPlots");
}
else {
plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(left));
}
sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + left, "" + (grantedPlots - left));
} }
} } else {
if (removeGrants == 0) { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return false;
} }
} }
if ((EconHandler.manager != null) && plotarea.USE_ECONOMY) { if ((EconHandler.manager != null) && plotarea.USE_ECONOMY) {
@ -146,11 +147,6 @@ 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 != null && !schematic.equals("")) { if (schematic != null && !schematic.equals("")) {
if (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) { if (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);

View file

@ -93,14 +93,13 @@ public class Claim extends SubCommand {
} }
final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(loc.getWorld()); final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(loc.getWorld());
boolean removeGrantedPlot = false; boolean removeGrantedPlot = false;
int grants = 0;
if (currentPlots >= plr.getAllowedPlots()) { if (currentPlots >= plr.getAllowedPlots()) {
if (plr.hasPersistentMeta("grantedPlots")) { if (plr.hasPersistentMeta("grantedPlots")) {
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); grants = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
if (grantedPlots < 1) { if (grants <= 0) {
plr.removePersistentMeta("grantedPlots"); plr.removePersistentMeta("grantedPlots");
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
} else {
removeGrantedPlot = true;
} }
} else { } else {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
@ -120,10 +119,14 @@ public class Claim extends SubCommand {
sendMessage(plr, C.REMOVED_BALANCE, cost + ""); sendMessage(plr, C.REMOVED_BALANCE, cost + "");
} }
} }
if (removeGrantedPlot) { if (grants > 0) {
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); if (grants == 1) {
plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - 1)); plr.removePersistentMeta("grantedPlots");
sendMessage(plr, C.REMOVED_GRANTED_PLOT, "1", "" + (grantedPlots - 1)); }
else {
plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grants - 1));
}
sendMessage(plr, C.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1));
} }
if (!schematic.equals("")) { if (!schematic.equals("")) {
if (world.SCHEMATIC_CLAIM_SPECIFY) { if (world.SCHEMATIC_CLAIM_SPECIFY) {

View file

@ -20,18 +20,6 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
@ -42,14 +30,13 @@ import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.GridPlotWorld; import com.intellectualcrafters.plot.generator.GridPlotWorld;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.util.area.QuadMap; import com.intellectualcrafters.plot.util.area.QuadMap;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* @author Jesse Boyd * @author Jesse Boyd
*/ */
@ -424,13 +411,16 @@ public abstract class PlotArea {
return StringMan.isEqual(loc.getWorld(), worldname) && (getRegionAbs() == null || region.isIn(loc.getX(), loc.getZ())); return StringMan.isEqual(loc.getWorld(), worldname) && (getRegionAbs() == null || region.isIn(loc.getX(), loc.getZ()));
} }
public Set<Plot> getPlotsAbs(UUID uuid) { public Set<Plot> getPlotsAbs(final UUID uuid) {
HashSet<Plot> plots = new HashSet<>(); final HashSet<Plot> plots = new HashSet<>();
for (Plot plot : plots) { foreachPlotAbs(new RunnableVal<Plot>() {
if (plot.owner.equals(uuid)) { @Override
plots.add(plot); public void run(Plot value) {
if (value.owner.equals(uuid)) {
plots.add(value);
}
} }
} });
return plots; return plots;
} }
@ -575,6 +565,13 @@ public abstract class PlotArea {
} }
return plots; return plots;
} }
public void foreachPlotAbs(RunnableVal<Plot> run) {
for (Entry<PlotId, Plot> entry : plots.entrySet()) {
run.run(entry.getValue());
}
}
public void foreachBasePlot(RunnableVal<Plot> run) { public void foreachBasePlot(RunnableVal<Plot> run) {
for (Plot plot : getPlots()) { for (Plot plot : getPlots()) {

Binary file not shown.