From 550cf87adf8269fe2b29d097debbda00c9fb8d35 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sun, 12 Apr 2015 15:41:14 +1000 Subject: [PATCH] Added optional WorldEdit processing to reduce likelyhood of server crashes --- .../worldedit/ProcessedWEExtent.java | 105 ++++++++++++++++++ .../plot/listeners/worldedit/WEListener.java | 7 +- 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/ProcessedWEExtent.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/ProcessedWEExtent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/ProcessedWEExtent.java new file mode 100644 index 000000000..0c7087a68 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/ProcessedWEExtent.java @@ -0,0 +1,105 @@ +package com.intellectualcrafters.plot.listeners.worldedit; + +import java.util.HashSet; + +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.biome.BaseBiome; + +public class ProcessedWEExtent extends AbstractDelegateExtent { + private final HashSet mask; + int BScount = 0; + int Ecount = 0; + boolean BSblocked = false; + boolean Eblocked = false; + + public ProcessedWEExtent(HashSet mask, Extent extent) { + super(extent); + this.mask = mask; + } + + @Override + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { + switch (block.getType()) { + case 54: + case 130: + case 142: + case 27: + case 137: + case 52: + case 154: + case 84: + case 25: + case 144: + case 138: + case 176: + case 177: + case 63: + case 68: + case 323: + case 117: + case 116: + case 28: + case 66: + case 157: + case 61: + case 62: + case 140: + case 146: + case 149: + case 150: + case 158: + case 23: + case 123: + case 124: + case 29: + case 33: + case 151: + case 178: { + if (BSblocked) { + return false; + } + BScount++; + if (BScount > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) { + BSblocked = true; + } + } + } + if (WEListener.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + return super.setBlock(location, block); + } + return false; + } + + @Override + public Entity createEntity(Location location, BaseEntity entity) { + if (Eblocked) { + return null; + } + Ecount++; + if (Ecount > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { + Eblocked = true; + } + if (WEListener.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + return super.createEntity(location, entity); + } + return null; + } + + @Override + public boolean setBiome(Vector2D position, BaseBiome biome) { + if (WEListener.maskContains(mask, position.getBlockX(), position.getBlockZ())) { + return super.setBiome(position, biome); + } + return false; + } +} \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java index 5f52965d1..78c6a20f0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java @@ -72,7 +72,12 @@ public class WEListener implements Listener { return; } } catch (IncompleteRegionException e) {} - event.setExtent(new WEExtent(mask, event.getExtent())); + if (Settings.CHUNK_PROCESSOR) { + event.setExtent(new ProcessedWEExtent(mask, event.getExtent())); + } + else { + event.setExtent(new WEExtent(mask, event.getExtent())); + } } }