Modifications to the generator code

This commit is contained in:
MattBDev 2019-05-17 16:21:03 -04:00
parent 595a68ecba
commit 4e3a927323
16 changed files with 57 additions and 112 deletions

View File

@ -53,6 +53,7 @@ import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File; import java.io.File;
@ -564,7 +565,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
@Override @Nullable @Override @Nullable
public final ChunkGenerator getDefaultWorldGenerator(final String worldName, final String id) { public final ChunkGenerator getDefaultWorldGenerator(@NotNull final String worldName,
final String id) {
final IndependentPlotGenerator result; final IndependentPlotGenerator result;
if (id != null && id.equalsIgnoreCase("single")) { if (id != null && id.equalsIgnoreCase("single")) {
result = new SingleWorldGenerator(); result = new SingleWorldGenerator();
@ -681,7 +683,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
getServer().getPluginManager().registerEvents(new WorldEvents(), this); getServer().getPluginManager().registerEvents(new WorldEvents(), this);
} }
@Override public IndependentPlotGenerator getDefaultGenerator() { @NotNull @Override public IndependentPlotGenerator getDefaultGenerator() {
return new HybridGen(); return new HybridGen();
} }

View File

@ -18,6 +18,7 @@ import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import java.util.Random; import java.util.Random;
@ -73,7 +74,8 @@ import java.util.Random;
Random random = new Random(MathMan.pair((short) chunkX, (short) chunkZ)); Random random = new Random(MathMan.pair((short) chunkX, (short) chunkZ));
try { try {
ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() { ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() {
@Override public void setBiome(int x, int z, Biome biome) { @Override public void setBiome(@Range(from = 0, to = 15) int x,
@Range(from = 0, to = 15) int z, Biome biome) {
result.setBiome(x, z, biome.name()); result.setBiome(x, z, biome.name());
} }

View File

@ -6,7 +6,6 @@ import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock; import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
@ -20,15 +19,10 @@ import org.bukkit.block.Biome;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Locale; import java.util.Locale;
public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> { public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
private Field fieldNeighbors;
private Method chunkGetHandle;
public BukkitLocalQueue(String world) { public BukkitLocalQueue(String world) {
super(world); super(world);
} }
@ -55,7 +49,11 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
@Override public void refreshChunk(int x, int z) { @Override public void refreshChunk(int x, int z) {
World worldObj = Bukkit.getWorld(getWorld()); World worldObj = Bukkit.getWorld(getWorld());
worldObj.refreshChunk(x, z); if (worldObj != null) {
worldObj.refreshChunk(x, z);
} else {
PlotSquared.debug("Error Refreshing Chunk");
}
} }
@Override public void fixChunkLighting(int x, int z) { @Override public void fixChunkLighting(int x, int z) {
@ -64,7 +62,11 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
@Override public final void regenChunk(int x, int z) { @Override public final void regenChunk(int x, int z) {
World worldObj = Bukkit.getWorld(getWorld()); World worldObj = Bukkit.getWorld(getWorld());
worldObj.regenerateChunk(x, z); if (worldObj != null) {
worldObj.regenerateChunk(x, z);
} else {
PlotSquared.debug("Error Regenerating Chunk");
}
} }
@Override public final void setComponents(LocalChunk<T> lc) { @Override public final void setComponents(LocalChunk<T> lc) {
@ -183,14 +185,12 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
World worldObj = Bukkit.getWorld(getWorld()); World worldObj = Bukkit.getWorld(getWorld());
int bx = lc.getX() << 4; int bx = lc.getX() << 4;
int bz = lc.getX() << 4; int bz = lc.getX() << 4;
String last = null;
Biome biome = null;
for (int x = 0; x < lc.biomes.length; x++) { for (int x = 0; x < lc.biomes.length; x++) {
String[] biomes2 = lc.biomes[x]; String[] biomes2 = lc.biomes[x];
if (biomes2 != null) { if (biomes2 != null) {
for (String biomeStr : biomes2) { for (String biomeStr : biomes2) {
if (biomeStr != null) { if (biomeStr != null) {
biome = Biome.valueOf(biomeStr.toUpperCase()); Biome biome = Biome.valueOf(biomeStr.toUpperCase());
worldObj.setBiome(bx, bz, biome); worldObj.setBiome(bx, bz, biome);
} }
} }
@ -199,59 +199,4 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
} }
} }
/**
* Exploiting a bug in the vanilla lighting algorithm for faster block placement
* - Could have been achieved without reflection by force unloading specific chunks
* - Much faster just setting the variable manually though
*
* @param chunk
* @return
*/
protected Object[] disableLighting(Chunk chunk) {
try {
if (chunkGetHandle == null) {
chunkGetHandle = chunk.getClass().getDeclaredMethod("getHandle");
chunkGetHandle.setAccessible(true);
}
Object nmsChunk = chunkGetHandle.invoke(chunk);
if (fieldNeighbors == null) {
fieldNeighbors = nmsChunk.getClass().getDeclaredField("neighbors");
fieldNeighbors.setAccessible(true);
}
Object value = fieldNeighbors.get(nmsChunk);
fieldNeighbors.set(nmsChunk, 0);
return new Object[] {nmsChunk, value};
} catch (Throwable ignore) {
}
return null;
}
protected void disableLighting(Object[] disableResult) {
if (disableResult != null) {
try {
fieldNeighbors.set(disableResult[0], 0);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
protected void resetLighting(Object[] disableResult) {
if (disableResult != null) {
try {
fieldNeighbors.set(disableResult[0], disableResult[1]);
} catch (Exception e) {
e.printStackTrace();
}
}
}
protected void enableLighting(Object[] disableResult) {
if (disableResult != null) {
try {
fieldNeighbors.set(disableResult[0], 0x739C0);
} catch (Throwable ignore) {
}
}
}
} }

View File

@ -8,6 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -246,7 +247,7 @@ public interface IPlotMain extends ILogger {
* *
* @return Default implementation generator * @return Default implementation generator
*/ */
IndependentPlotGenerator getDefaultGenerator(); @NotNull IndependentPlotGenerator getDefaultGenerator();
/** /**
* Gets the class that will manage player titles. * Gets the class that will manage player titles.

View File

@ -1333,8 +1333,8 @@ import java.util.zip.ZipInputStream;
} }
String key = pair[0].toLowerCase(); String key = pair[0].toLowerCase();
String value = pair[1]; String value = pair[1];
String base = "worlds." + world + ".";
try { try {
String base = "worlds." + world + ".";
switch (key) { switch (key) {
case "s": case "s":
case "size": case "size":

View File

@ -36,25 +36,25 @@ import java.util.UUID;
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage()); checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
final Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]); final Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]); checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
Iterator<UUID> iter = uuids.iterator(); Iterator<UUID> iterator = uuids.iterator();
int size = plot.getTrusted().size() + plot.getMembers().size(); int size = plot.getTrusted().size() + plot.getMembers().size();
while (iter.hasNext()) { while (iterator.hasNext()) {
UUID uuid = iter.next(); UUID uuid = iterator.next();
if (uuid == DBFunc.EVERYONE && !( if (uuid == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) { .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
iter.remove(); iterator.remove();
continue; continue;
} }
if (plot.isOwner(uuid)) { if (plot.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_OWNER, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.ALREADY_OWNER, MainUtil.getName(uuid));
iter.remove(); iterator.remove();
continue; continue;
} }
if (plot.getMembers().contains(uuid)) { if (plot.getMembers().contains(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iter.remove(); iterator.remove();
continue; continue;
} }
size += plot.getTrusted().contains(uuid) ? 0 : 1; size += plot.getTrusted().contains(uuid) ? 0 : 1;

View File

@ -143,7 +143,6 @@ import java.util.Set;
return true; return true;
} }
default: // Start creation default: // Start creation
final SetupObject object = new SetupObject();
String[] split = args[1].split(":"); String[] split = args[1].split(":");
String id; String id;
if (split.length == 2) { if (split.length == 2) {
@ -151,6 +150,7 @@ import java.util.Set;
} else { } else {
id = null; id = null;
} }
final SetupObject object = new SetupObject();
object.world = split[0]; object.world = split[0];
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id, final HybridPlotWorld pa = new HybridPlotWorld(object.world, id,
PlotSquared.get().IMP.getDefaultGenerator(), null, null); PlotSquared.get().IMP.getDefaultGenerator(), null, null);

View File

@ -197,11 +197,9 @@ import java.util.Set;
} }
}; };
} else { } else {
regenTask = new Runnable() { regenTask = () -> {
@Override public void run() { Trim.TASK = false;
Trim.TASK = false; player.sendMessage("Trim done!");
player.sendMessage("Trim done!");
}
}; };
} }
ChunkManager.manager.deleteRegionFiles(world, viable, regenTask); ChunkManager.manager.deleteRegionFiles(world, viable, regenTask);

View File

@ -8,6 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -32,7 +33,8 @@ import java.util.Locale;
// PlotBlock.get((short) 155, (byte) 0); // PlotBlock.get((short) 155, (byte) 0);
public boolean PLOT_BEDROCK = true; public boolean PLOT_BEDROCK = true;
public ClassicPlotWorld(String worldName, String id, IndependentPlotGenerator generator, public ClassicPlotWorld(String worldName, String id,
@NotNull IndependentPlotGenerator generator,
PlotId min, PlotId max) { PlotId min, PlotId max) {
super(worldName, id, generator, min, max); super(worldName, id, generator, min, max);
} }

View File

@ -2,12 +2,13 @@ package com.github.intellectualsites.plotsquared.plot.generator;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import org.jetbrains.annotations.NotNull;
public abstract class GridPlotWorld extends PlotArea { public abstract class GridPlotWorld extends PlotArea {
public short SIZE; public short SIZE;
public GridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, public GridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
PlotId min, PlotId max) { PlotId min, PlotId max) {
super(worldName, id, generator, min, max); super(worldName, id, generator, min, max);
} }

View File

@ -21,6 +21,7 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
@ -37,7 +38,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public int SCHEM_Y; public int SCHEM_Y;
private Location SIGN_LOCATION; private Location SIGN_LOCATION;
public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, public HybridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
PlotId min, PlotId max) { PlotId min, PlotId max) {
super(worldName, id, generator, min, max); super(worldName, id, generator, min, max);
} }
@ -119,8 +120,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
try { try {
setupSchematics(); setupSchematics();
} catch (Exception ignored) { } catch (Exception event) {
ignored.printStackTrace(); event.printStackTrace();
PlotSquared.debug("&c - road schematics are disabled for this world."); PlotSquared.debug("&c - road schematics are disabled for this world.");
} }
} }

View File

@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.generator;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import org.jetbrains.annotations.NotNull;
public abstract class SquarePlotWorld extends GridPlotWorld { public abstract class SquarePlotWorld extends GridPlotWorld {
@ -11,7 +12,7 @@ public abstract class SquarePlotWorld extends GridPlotWorld {
public int ROAD_OFFSET_X = 0; public int ROAD_OFFSET_X = 0;
public int ROAD_OFFSET_Z = 0; public int ROAD_OFFSET_Z = 0;
public SquarePlotWorld(String worldName, String id, IndependentPlotGenerator generator, public SquarePlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
PlotId min, PlotId max) { PlotId min, PlotId max) {
super(worldName, id, generator, min, max); super(worldName, id, generator, min, max);
} }

View File

@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -135,7 +136,7 @@ import java.util.Map.Entry;
} }
} }
@Override public Iterator<PlotBlock> iterator() { @NotNull @Override public Iterator<PlotBlock> iterator() {
return this.bucketIterator; return this.bucketIterator;
} }

View File

@ -21,6 +21,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -76,11 +77,11 @@ public abstract class PlotArea {
private QuadMap<PlotCluster> clusters; private QuadMap<PlotCluster> clusters;
public PlotArea(@Nonnull final String worldName, @Nullable final String id, public PlotArea(@Nonnull final String worldName, @Nullable final String id,
@Nullable IndependentPlotGenerator generator, @Nullable final PlotId min, @NotNull IndependentPlotGenerator generator, @Nullable final PlotId min,
@Nullable final PlotId max) { @Nullable final PlotId max) {
this.worldname = worldName; this.worldname = worldName;
this.id = id; this.id = id;
this.manager = generator != null ? generator.getNewPlotManager() : null; this.manager = generator.getNewPlotManager();
this.generator = generator; this.generator = generator;
if (min == null || max == null) { if (min == null || max == null) {
if (min != max) { if (min != max) {
@ -94,28 +95,13 @@ public abstract class PlotArea {
this.max = max; this.max = max;
} }
this.worldhash = worldName.hashCode(); this.worldhash = worldName.hashCode();
if (Settings.Enabled_Components.PLOT_EXPIRY && generator != null) { if (Settings.Enabled_Components.PLOT_EXPIRY) {
blockBucketChunk = generator.generateBlockBucketChunk(this); blockBucketChunk = generator.generateBlockBucketChunk(this);
} else { } else {
blockBucketChunk = null; blockBucketChunk = null;
} }
} }
/**
* Create a new PlotArea object with no functionality/information.
* - Mainly used during startup before worlds are created as a temporary object
*/
public static PlotArea createGeneric(@Nonnull final String world) {
return new PlotArea(world, null, null, null, null) {
@Override public void loadConfiguration(ConfigurationSection config) {
}
@Override public ConfigurationNode[] getSettingNodes() {
return null;
}
};
}
public LocalBlockQueue getQueue(final boolean autoQueue) { public LocalBlockQueue getQueue(final boolean autoQueue) {
return GlobalBlockQueue.IMP.getNewQueue(worldname, autoQueue); return GlobalBlockQueue.IMP.getNewQueue(worldname, autoQueue);
} }

View File

@ -181,16 +181,16 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
} }
public abstract class LocalChunk<T> { public abstract class LocalChunk<B> {
public final BasicLocalBlockQueue parent; public final BasicLocalBlockQueue parent;
public final int z; public final int z;
public final int x; public final int x;
public T[] blocks; public B[] blocks;
public BaseBlock[][] baseblocks; public BaseBlock[][] baseblocks;
public String[][] biomes; public String[][] biomes;
public LocalChunk(BasicLocalBlockQueue<T> parent, int x, int z) { public LocalChunk(BasicLocalBlockQueue<B> parent, int x, int z) {
this.parent = parent; this.parent = parent;
this.x = x; this.x = x;
this.z = z; this.z = z;

View File

@ -1,7 +1,12 @@
package com.github.intellectualsites.plotsquared.plot.util.block; package com.github.intellectualsites.plotsquared.plot.util.block;
import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue { public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue {