Make block 36 removsl configurable

This commit is contained in:
Austin Mayes 2019-06-13 17:35:48 -05:00
parent f1661b3918
commit c4b22575f9
No known key found for this signature in database
GPG Key ID: 72C78ABE045D34F6
3 changed files with 21 additions and 8 deletions

View File

@ -19,17 +19,15 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import tc.oc.api.docs.SemanticVersion;
import tc.oc.api.util.Permissions; import tc.oc.api.util.Permissions;
import tc.oc.commons.bukkit.util.BlockVectorSet; import tc.oc.commons.bukkit.util.BlockVectorSet;
import tc.oc.commons.bukkit.util.ChunkPosition; import tc.oc.commons.bukkit.util.ChunkPosition;
import tc.oc.commons.bukkit.util.NMSHacks; import tc.oc.commons.bukkit.util.NMSHacks;
import tc.oc.pgm.events.ListenerScope; import tc.oc.pgm.events.ListenerScope;
import tc.oc.pgm.map.MapProto;
import tc.oc.pgm.map.ProtoVersions;
import tc.oc.pgm.match.Match; import tc.oc.pgm.match.Match;
import tc.oc.pgm.match.MatchModule; import tc.oc.pgm.match.MatchModule;
import tc.oc.pgm.match.MatchScope; import tc.oc.pgm.match.MatchScope;
import tc.oc.pgm.terrain.TerrainOptions;
@ListenerScope(MatchScope.LOADED) @ListenerScope(MatchScope.LOADED)
public class WorldProblemMatchModule extends MatchModule implements Listener { public class WorldProblemMatchModule extends MatchModule implements Listener {
@ -39,7 +37,7 @@ public class WorldProblemMatchModule extends MatchModule implements Listener {
private final Set<ChunkPosition> repairedChunks = new HashSet<>(); private final Set<ChunkPosition> repairedChunks = new HashSet<>();
private final BlockVectorSet block36Locations = new BlockVectorSet(); private final BlockVectorSet block36Locations = new BlockVectorSet();
@Inject private @MapProto SemanticVersion proto; @Inject private TerrainOptions options;
@Inject private World world; @Inject private World world;
@Inject WorldProblemMatchModule(Match match) { @Inject WorldProblemMatchModule(Match match) {
@ -68,6 +66,8 @@ public class WorldProblemMatchModule extends MatchModule implements Listener {
for(Chunk chunk : world.getLoadedChunks()) { for(Chunk chunk : world.getLoadedChunks()) {
checkChunk(chunk); checkChunk(chunk);
} }
if (!options.remove36())
broadcastDeveloperWarning("Block 36 will NOT be removed! This can cause lag.");
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -103,7 +103,7 @@ public class WorldProblemMatchModule extends MatchModule implements Listener {
ironDoor.setType(Material.BARRIER, false); ironDoor.setType(Material.BARRIER, false);
} }
} }
if (proto.isOlderThan(ProtoVersions.ENABLE_BLOCK_36)) { if (options.remove36()) {
// Remove all block 36 and remember the ones at y=0 so VoidFilter can check them // Remove all block 36 and remember the ones at y=0 so VoidFilter can check them
for(Block block36 : chunk.getBlocks(Material.PISTON_MOVING_PIECE)) { for(Block block36 : chunk.getBlocks(Material.PISTON_MOVING_PIECE)) {
if(block36.getY() == 0) { if(block36.getY() == 0) {

View File

@ -11,12 +11,14 @@ public class TerrainOptions implements WorldConfigurator {
private final boolean vanilla; private final boolean vanilla;
private final long seed; private final long seed;
private final boolean initialPhysics; private final boolean initialPhysics;
private final boolean remove36;
public TerrainOptions(Path worldFolder, boolean vanilla, Long seed, boolean initialPhysics) { public TerrainOptions(Path worldFolder, boolean vanilla, Long seed, boolean initialPhysics, boolean remove36) {
this.worldFolder = worldFolder; this.worldFolder = worldFolder;
this.vanilla = vanilla; this.vanilla = vanilla;
this.seed = seed != null ? seed : new Random().nextLong(); this.seed = seed != null ? seed : new Random().nextLong();
this.initialPhysics = initialPhysics; this.initialPhysics = initialPhysics;
this.remove36 = remove36;
} }
public Path worldFolder() { public Path worldFolder() {
@ -27,6 +29,10 @@ public class TerrainOptions implements WorldConfigurator {
return initialPhysics; return initialPhysics;
} }
public boolean remove36() {
return remove36;
}
@Override @Override
public void configureWorld(WorldCreator worldCreator) { public void configureWorld(WorldCreator worldCreator) {
worldCreator.generator(vanilla ? null : new NullChunkGenerator()); worldCreator.generator(vanilla ? null : new NullChunkGenerator());

View File

@ -6,7 +6,10 @@ import javax.inject.Inject;
import org.jdom2.Document; import org.jdom2.Document;
import org.jdom2.Element; import org.jdom2.Element;
import tc.oc.api.docs.SemanticVersion;
import tc.oc.pgm.map.MapFolder; import tc.oc.pgm.map.MapFolder;
import tc.oc.pgm.map.MapProto;
import tc.oc.pgm.map.ProtoVersions;
import tc.oc.pgm.utils.XMLUtils; import tc.oc.pgm.utils.XMLUtils;
import tc.oc.pgm.xml.InvalidXMLException; import tc.oc.pgm.xml.InvalidXMLException;
import tc.oc.pgm.xml.Node; import tc.oc.pgm.xml.Node;
@ -16,10 +19,12 @@ public class TerrainParser implements ElementParser<TerrainOptions> {
private final MapFolder mapFolder; private final MapFolder mapFolder;
private final Document doc; private final Document doc;
private final SemanticVersion proto;
@Inject private TerrainParser(MapFolder mapFolder, Document doc) { @Inject private TerrainParser(MapFolder mapFolder, Document doc, @MapProto SemanticVersion proto) {
this.mapFolder = mapFolder; this.mapFolder = mapFolder;
this.doc = doc; this.doc = doc;
this.proto = proto;
} }
@Override @Override
@ -34,11 +39,13 @@ public class TerrainParser implements ElementParser<TerrainOptions> {
boolean vanilla = false; boolean vanilla = false;
Long seed = null; Long seed = null;
boolean initialPhysics = false; boolean initialPhysics = false;
boolean remove36 = proto.isOlderThan(ProtoVersions.ENABLE_BLOCK_36);
for(Element elTerrain : doc.getRootElement().getChildren("terrain")) { for(Element elTerrain : doc.getRootElement().getChildren("terrain")) {
vanilla = XMLUtils.parseBoolean(elTerrain.getAttribute("vanilla"), vanilla); vanilla = XMLUtils.parseBoolean(elTerrain.getAttribute("vanilla"), vanilla);
worldFolder = XMLUtils.parseRelativeFolder(worldFolder, Node.fromAttr(elTerrain, "world"), worldFolder); worldFolder = XMLUtils.parseRelativeFolder(worldFolder, Node.fromAttr(elTerrain, "world"), worldFolder);
initialPhysics = XMLUtils.parseBoolean(elTerrain.getAttribute("pre-match-physics"), initialPhysics); initialPhysics = XMLUtils.parseBoolean(elTerrain.getAttribute("pre-match-physics"), initialPhysics);
remove36 = XMLUtils.parseBoolean(elTerrain.getAttribute("remove-36"), remove36);
String seedText = elTerrain.getAttributeValue("seed"); String seedText = elTerrain.getAttributeValue("seed");
if(seedText != null) { if(seedText != null) {
@ -50,6 +57,6 @@ public class TerrainParser implements ElementParser<TerrainOptions> {
} }
} }
return new TerrainOptions(worldFolder, vanilla, seed, initialPhysics); return new TerrainOptions(worldFolder, vanilla, seed, initialPhysics, remove36);
} }
} }