diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java index 98b830dfb..813a3d457 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/NbtFactory.java @@ -15,27 +15,12 @@ import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; -import java.io.BufferedInputStream; -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.io.*; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.AbstractList; -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.*; import java.util.concurrent.ConcurrentMap; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -175,7 +160,8 @@ public class NbtFactory { suppress = false; return result; - } finally { + } + finally { if (data != null) { Closeables.close(data, suppress); } else if (input != null) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java index 4170c9207..de4792ca7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java @@ -173,6 +173,9 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { for (UUID uuid : uuids) { try { 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 NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION); final NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index a96f7cebe..e44c9cbbc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -111,27 +111,28 @@ public class Auto extends SubCommand { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); return false; } - int removeGrants = 0; final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(plotarea.worldname); final int diff = currentPlots - plr.getAllowedPlots(); if ((diff + (size_x * size_z)) > 0) { if (diff < 0) { 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 if (plr.hasPersistentMeta("grantedPlots")) { + int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); + if (grantedPlots - diff < size_x * size_z) { + plr.removePersistentMeta("grantedPlots"); + return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } 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)); } - } - if (removeGrants == 0) { - return false; + } else { + MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } } if ((EconHandler.manager != null) && plotarea.USE_ECONOMY) { @@ -146,11 +147,6 @@ public class Auto extends SubCommand { 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 (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 4c150201c..748718555 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -93,14 +93,13 @@ public class Claim extends SubCommand { } final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(loc.getWorld()); boolean removeGrantedPlot = false; + int grants = 0; if (currentPlots >= plr.getAllowedPlots()) { if (plr.hasPersistentMeta("grantedPlots")) { - int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); - if (grantedPlots < 1) { + grants = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); + if (grants <= 0) { plr.removePersistentMeta("grantedPlots"); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); - } else { - removeGrantedPlot = true; } } else { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); @@ -120,10 +119,14 @@ public class Claim extends SubCommand { sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } - if (removeGrantedPlot) { - int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); - plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - 1)); - sendMessage(plr, C.REMOVED_GRANTED_PLOT, "1", "" + (grantedPlots - 1)); + if (grants > 0) { + if (grants == 1) { + plr.removePersistentMeta("grantedPlots"); + } + else { + plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grants - 1)); + } + sendMessage(plr, C.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1)); } if (!schematic.equals("")) { if (world.SCHEMATIC_CLAIM_SPECIFY) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java index 9f1e182e2..38538919f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java @@ -20,18 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// 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.plot.PS; 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.generator.GridPlotWorld; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; -import com.intellectualcrafters.plot.util.EconHandler; -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.*; import com.intellectualcrafters.plot.util.area.QuadMap; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + /** * @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())); } - public Set getPlotsAbs(UUID uuid) { - HashSet plots = new HashSet<>(); - for (Plot plot : plots) { - if (plot.owner.equals(uuid)) { - plots.add(plot); + public Set getPlotsAbs(final UUID uuid) { + final HashSet plots = new HashSet<>(); + foreachPlotAbs(new RunnableVal() { + @Override + public void run(Plot value) { + if (value.owner.equals(uuid)) { + plots.add(value); + } } - } + }); return plots; } @@ -575,6 +565,13 @@ public abstract class PlotArea { } return plots; } + + public void foreachPlotAbs(RunnableVal run) { + for (Entry entry : plots.entrySet()) { + run.run(entry.getValue()); + } + + } public void foreachBasePlot(RunnableVal run) { for (Plot plot : getPlots()) { diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar index a5fe0cf14..ea1a4c834 100644 Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ