mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Fix some logic
This commit is contained in:
parent
01710e3ddb
commit
ce8775414a
@ -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) {
|
||||
|
@ -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");
|
||||
|
@ -111,29 +111,30 @@ 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")) {
|
||||
} else if (plr.hasPersistentMeta("grantedPlots")) {
|
||||
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
|
||||
if (grantedPlots < size_x * size_z) {
|
||||
if (grantedPlots - diff < size_x * size_z) {
|
||||
plr.removePersistentMeta("grantedPlots");
|
||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
} else {
|
||||
removeGrants = size_x * size_z;
|
||||
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 {
|
||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
}
|
||||
}
|
||||
if (removeGrants == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((EconHandler.manager != null) && plotarea.USE_ECONOMY) {
|
||||
double cost = plotarea.PLOT_PRICE;
|
||||
cost = (size_x * size_z) * cost;
|
||||
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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<Plot> getPlotsAbs(UUID uuid) {
|
||||
HashSet<Plot> plots = new HashSet<>();
|
||||
for (Plot plot : plots) {
|
||||
if (plot.owner.equals(uuid)) {
|
||||
plots.add(plot);
|
||||
public Set<Plot> getPlotsAbs(final UUID uuid) {
|
||||
final HashSet<Plot> plots = new HashSet<>();
|
||||
foreachPlotAbs(new RunnableVal<Plot>() {
|
||||
@Override
|
||||
public void run(Plot value) {
|
||||
if (value.owner.equals(uuid)) {
|
||||
plots.add(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
return plots;
|
||||
}
|
||||
|
||||
@ -576,6 +566,13 @@ public abstract class PlotArea {
|
||||
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) {
|
||||
for (Plot plot : getPlots()) {
|
||||
if (plot.isBasePlot()) {
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user