diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/SingleWorldListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/SingleWorldListener.java index 14567a9b4..88d25cd11 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/SingleWorldListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/SingleWorldListener.java @@ -22,7 +22,7 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils @SuppressWarnings("unused") public class SingleWorldListener implements Listener { private Method methodGetHandleChunk; - private Field mustSave, done, lit, s; + private Field mustSave; public SingleWorldListener(Plugin plugin) throws Exception { ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk"); @@ -30,9 +30,6 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod(); this.mustSave = classChunk.getField("mustSave").getRealField(); try { - this.done = classChunk.getField("done").getRealField(); - this.lit = classChunk.getField("lit").getRealField(); - this.s = classChunk.getField("s").getRealField(); } catch (Exception e) { e.printStackTrace(); } @@ -42,18 +39,9 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils public void markChunkAsClean(Chunk chunk) { try { Object nmsChunk = methodGetHandleChunk.invoke(chunk); - if (done != null) { - this.done.set(nmsChunk, true); - } if (mustSave != null) { this.mustSave.set(nmsChunk, false); } - if (lit != null) { - this.lit.set(nmsChunk, false); - } - if (s != null) { - this.s.set(nmsChunk, false); - } } catch (Throwable e) { e.printStackTrace(); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java index 8c4b78445..7c21df8fc 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java @@ -33,12 +33,24 @@ public class PlotId { * @throws IllegalArgumentException if the string does not contain a valid PlotId */ @Nonnull public static PlotId fromString(@Nonnull String string) { + PlotId plot = fromStringOrNull(string); + if (plot == null) throw new IllegalArgumentException("Cannot create PlotID. String invalid."); + return plot; + } + + @Nullable public static PlotId fromStringOrNull(@Nonnull String string) { String[] parts = string.split("[;|,]"); if (parts.length < 2) { - throw new IllegalArgumentException("Cannot create PlotID. String invalid."); + return null; + } + int x; + int y; + try { + x = Integer.parseInt(parts[0]); + y = Integer.parseInt(parts[1]); + } catch (NumberFormatException ignored) { + return null; } - int x = Integer.parseInt(parts[0]); - int y = Integer.parseInt(parts[1]); return new PlotId(x, y); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DelegatePlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DelegatePlotAreaManager.java new file mode 100644 index 000000000..52da1ade0 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/DelegatePlotAreaManager.java @@ -0,0 +1,63 @@ +package com.github.intellectualsites.plotsquared.plot.object.worlds; + +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; + +public class DelegatePlotAreaManager implements PlotAreaManager { + @Override + public PlotArea getApplicablePlotArea(Location location) { + return parent.getApplicablePlotArea(location); + } + + @Override + public PlotArea getPlotArea(Location location) { + return parent.getPlotArea(location); + } + + @Override + public PlotArea getPlotArea(String world, String id) { + return parent.getPlotArea(world, id); + } + + @Override + public PlotArea[] getPlotAreas(String world, RegionWrapper region) { + return parent.getPlotAreas(world, region); + } + + @Override + public PlotArea[] getAllPlotAreas() { + return parent.getAllPlotAreas(); + } + + @Override + public String[] getAllWorlds() { + return parent.getAllWorlds(); + } + + @Override + public void addPlotArea(PlotArea area) { + parent.addPlotArea(area); + } + + @Override + public void removePlotArea(PlotArea area) { + parent.removePlotArea(area); + } + + @Override + public void addWorld(String worldName) { + parent.addWorld(worldName); + } + + @Override + public void removeWorld(String worldName) { + parent.removeWorld(worldName); + } + + private final PlotAreaManager parent; + + public DelegatePlotAreaManager(PlotAreaManager parent) { + this.parent = parent; + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java index ad3210094..101941391 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java @@ -63,24 +63,24 @@ public class SinglePlotArea extends GridPlotWorld { } @Nullable @Override public Plot getOwnedPlot(@Nonnull final Location location) { - PlotId pid = PlotId.fromString(location.getWorld()); - Plot plot = this.plots.get(pid); + PlotId pid = PlotId.fromStringOrNull(location.getWorld()); + Plot plot = pid == null ? null : this.plots.get(pid); return plot == null ? null : plot.getBasePlot(false); } @Nullable @Override public Plot getOwnedPlotAbs(@Nonnull Location location) { - PlotId pid = PlotId.fromString(location.getWorld()); - return plots.get(pid); + PlotId pid = PlotId.fromStringOrNull(location.getWorld()); + return pid == null ? null : plots.get(pid); } @Nullable @Override public Plot getPlot(@Nonnull final Location location) { - PlotId pid = PlotId.fromString(location.getWorld()); - return getPlot(pid); + PlotId pid = PlotId.fromStringOrNull(location.getWorld()); + return pid == null ? null : getPlot(pid); } @Nullable @Override public Plot getPlotAbs(@Nonnull final Location location) { - final PlotId pid = PlotId.fromString(location.getWorld()); - return getPlotAbs(pid); + final PlotId pid = PlotId.fromStringOrNull(location.getWorld()); + return pid == null ? null : getPlotAbs(pid); } public boolean addPlot(@Nonnull Plot plot) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java index afd5f9f5f..7c9f16d70 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java @@ -30,11 +30,11 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { } public boolean isWorld(String id) { - int mode = 0; char[] chars = id.toCharArray(); if (chars.length == 1 && chars[0] == '*') { return true; } + int mode = 0; for (int i = 0; i < chars.length; i++) { char c = chars[i]; switch (mode) { @@ -65,7 +65,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { continue; } } - return true; + return mode == 3; } @Override public PlotArea getApplicablePlotArea(Location location) { @@ -74,9 +74,9 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { return found; } String world = location.getWorld(); - return isWorld(world) || world.equals("*") || super.getAllPlotAreas().length == 0 ? + return isWorld(world) || world.equals("*") ? area : - null; + super.getApplicablePlotArea(location); } @Override public PlotArea getPlotArea(String world, String id) { @@ -84,7 +84,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { if (found != null) { return found; } - return isWorld(world) || world.equals("*") ? area : null; + return isWorld(world) || world.equals("*") ? area : super.getPlotArea(world, id); } @Override public PlotArea getPlotArea(Location location) { @@ -100,7 +100,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { if (found != null && found.length != 0) { return found; } - return isWorld(world) || world.equals("*") ? array : noPlotAreas; + return isWorld(world) || world.equals("*") ? array : all.length == 0 ? noPlotAreas : super.getPlotAreas(world, region); } @Override public PlotArea[] getAllPlotAreas() {