Javadoc and Formatting fixes. (#619)

Javadoc and Formatting fixes.

Also, extremely minor code changes which have been tested.
This commit is only part one of two commits that aim to fix problems with formatting in our project. In part two I will modify the Google Java Style Guide (since it closely matches our code style) for our project so there is guidance on how to format and document. 

* Updated PlotSquared URL
* Removed plugin acronyms
* Fixed a typo
* Fixed grammar
* Use modern block id's
* Update YouTube video URL
This commit is contained in:
Matt
2020-10-05 13:41:41 -04:00
committed by GitHub
parent b06d943f7c
commit 96dcb95b7c
393 changed files with 6537 additions and 4700 deletions

View File

@ -2,7 +2,14 @@ package com.boydti.fawe.bukkit.adapter.mc1_16_1;
import com.sk89q.util.ReflectionUtil;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_16_R1.*;
import net.minecraft.server.v1_16_R1.Block;
import net.minecraft.server.v1_16_R1.BlockAccessAir;
import net.minecraft.server.v1_16_R1.BlockBase;
import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.EnumPistonReaction;
import net.minecraft.server.v1_16_R1.IBlockData;
import net.minecraft.server.v1_16_R1.ITileEntity;
import net.minecraft.server.v1_16_R1.Material;
import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData;
public class BlockMaterial_1_16_1 implements BlockMaterial {

View File

@ -14,7 +14,23 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import net.jpountz.util.UnsafeUtils;
import net.minecraft.server.v1_16_R1.*;
import net.minecraft.server.v1_16_R1.BiomeBase;
import net.minecraft.server.v1_16_R1.BiomeStorage;
import net.minecraft.server.v1_16_R1.Block;
import net.minecraft.server.v1_16_R1.Chunk;
import net.minecraft.server.v1_16_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_16_R1.ChunkSection;
import net.minecraft.server.v1_16_R1.DataBits;
import net.minecraft.server.v1_16_R1.DataPalette;
import net.minecraft.server.v1_16_R1.DataPaletteBlock;
import net.minecraft.server.v1_16_R1.DataPaletteLinear;
import net.minecraft.server.v1_16_R1.GameProfileSerializer;
import net.minecraft.server.v1_16_R1.IBlockData;
import net.minecraft.server.v1_16_R1.PacketPlayOutLightUpdate;
import net.minecraft.server.v1_16_R1.PlayerChunk;
import net.minecraft.server.v1_16_R1.PlayerChunkMap;
import net.minecraft.server.v1_16_R1.World;
import net.minecraft.server.v1_16_R1.WorldServer;
import org.bukkit.craftbukkit.v1_16_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import sun.misc.Unsafe;
@ -34,18 +50,18 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
/*
NMS fields
*/
public final static Field fieldBits;
public final static Field fieldPalette;
public final static Field fieldSize;
public static final Field fieldBits;
public static final Field fieldPalette;
public static final Field fieldSize;
public final static Field fieldBitsPerEntry;
public static final Field fieldBitsPerEntry;
public final static Field fieldFluidCount;
public final static Field fieldTickingBlockCount;
public final static Field fieldNonEmptyBlockCount;
public static final Field fieldFluidCount;
public static final Field fieldTickingBlockCount;
public static final Field fieldNonEmptyBlockCount;
private final static Field fieldDirtyCount;
private final static Field fieldDirtyBits;
private static final Field fieldDirtyCount;
private static final Field fieldDirtyBits;
private static final Field fieldBiomeArray;
@ -95,8 +111,9 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
Unsafe unsafe = UnsafeUtils.getUNSAFE();
CHUNKSECTION_BASE = unsafe.arrayBaseOffset(ChunkSection[].class);
int scale = unsafe.arrayIndexScale(ChunkSection[].class);
if ((scale & (scale - 1)) != 0)
if ((scale & (scale - 1)) != 0) {
throw new Error("data type scale not a power of two");
}
CHUNKSECTION_SHIFT = 31 - Integer.numberOfLeadingZeros(scale);
} catch (RuntimeException e) {
throw e;
@ -133,17 +150,17 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
}
}
public static Chunk ensureLoaded(World nmsWorld, int X, int Z) {
Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(X, Z, false);
public static Chunk ensureLoaded(World nmsWorld, int chunkX, int chunkZ) {
Chunk nmsChunk = nmsWorld.getChunkProvider().getChunkAt(chunkX, chunkZ, false);
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(X, Z);
return nmsWorld.getChunkAt(chunkX, chunkZ);
}
if (PaperLib.isPaper()) {
CraftWorld craftWorld = nmsWorld.getWorld();
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(X, Z, true);
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(chunkX, chunkZ, true);
try {
CraftChunk chunk = (CraftChunk) future.get();
return chunk.getHandle();
@ -152,20 +169,20 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
}
}
// TODO optimize
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(X, Z));
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(chunkX, chunkZ));
}
public static PlayerChunk getPlayerChunk(WorldServer nmsWorld, final int cx, final int cz) {
PlayerChunkMap chunkMap = nmsWorld.getChunkProvider().playerChunkMap;
try {
return (PlayerChunk)methodGetVisibleChunk.invoke(chunkMap, ChunkCoordIntPair.pair(cx, cz));
return (PlayerChunk) methodGetVisibleChunk.invoke(chunkMap, ChunkCoordIntPair.pair(cx, cz));
} catch (Throwable thr) {
throw new RuntimeException(thr);
}
}
public static void sendChunk(WorldServer nmsWorld, int X, int Z, int mask, boolean lighting) {
PlayerChunk playerChunk = getPlayerChunk(nmsWorld, X, Z);
public static void sendChunk(WorldServer nmsWorld, int chunkX, int chunkZ, int mask, boolean lighting) {
PlayerChunk playerChunk = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (playerChunk == null) {
return;
}
@ -186,7 +203,7 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
fieldDirtyCount.set(playerChunk, 64);
if (lighting) {
ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(X, Z);
ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ);
boolean trustEdges = false; //Added in 1.16.1 Not sure what it does.
PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(chunkCoordIntPair, nmsWorld.getChunkProvider().getLightEngine(), trustEdges);
playerChunk.players.a(chunkCoordIntPair, false).forEach(p -> {
@ -241,7 +258,9 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
final int blockBitArrayEnd = MathMan.ceilZero((float) 4096 / blocksPerLong);
if (num_palette == 1) {
for (int i = 0; i < blockBitArrayEnd; i++) blockStates[i] = 0;
for (int i = 0; i < blockBitArrayEnd; i++) {
blockStates[i] = 0;
}
} else {
final BitArrayUnstretched bitArray = new BitArrayUnstretched(bitsPerEntry, 4096, blockStates);
bitArray.fromRaw(blocksCopy);
@ -255,7 +274,6 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
final long[] bits = Arrays.copyOfRange(blockStates, 0, blockBitArrayEnd);
final DataBits nmsBits = new DataBits(bitsPerEntry, 4096, bits);
final DataPalette<IBlockData> palette;
// palette = new DataPaletteHash<>(Block.REGISTRY_ID, bitsPerEntry, dataPaletteBlocks, GameProfileSerializer::d, GameProfileSerializer::a);
palette = new DataPaletteLinear<>(Block.REGISTRY_ID, bitsPerEntry, dataPaletteBlocks, GameProfileSerializer::c);
// set palette

View File

@ -15,8 +15,10 @@ import com.boydti.fawe.object.collection.AdaptedMap;
import com.boydti.fawe.object.collection.BitArrayUnstretched;
import com.google.common.base.Suppliers;
import com.google.common.collect.Iterables;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
@ -25,7 +27,28 @@ import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes;
import net.minecraft.server.v1_16_R1.*;
import net.minecraft.server.v1_16_R1.BiomeBase;
import net.minecraft.server.v1_16_R1.BiomeStorage;
import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.Chunk;
import net.minecraft.server.v1_16_R1.ChunkSection;
import net.minecraft.server.v1_16_R1.DataBits;
import net.minecraft.server.v1_16_R1.DataPalette;
import net.minecraft.server.v1_16_R1.DataPaletteBlock;
import net.minecraft.server.v1_16_R1.DataPaletteHash;
import net.minecraft.server.v1_16_R1.DataPaletteLinear;
import net.minecraft.server.v1_16_R1.Entity;
import net.minecraft.server.v1_16_R1.EntityTypes;
import net.minecraft.server.v1_16_R1.EnumSkyBlock;
import net.minecraft.server.v1_16_R1.HeightMap;
import net.minecraft.server.v1_16_R1.IBlockData;
import net.minecraft.server.v1_16_R1.LightEngine;
import net.minecraft.server.v1_16_R1.NBTTagCompound;
import net.minecraft.server.v1_16_R1.NBTTagInt;
import net.minecraft.server.v1_16_R1.NibbleArray;
import net.minecraft.server.v1_16_R1.SectionPosition;
import net.minecraft.server.v1_16_R1.TileEntity;
import net.minecraft.server.v1_16_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
@ -35,11 +58,20 @@ import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.util.*;
import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.function.Function;
import javax.annotation.Nullable;
import static org.slf4j.LoggerFactory.getLogger;
@ -48,24 +80,30 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
private static final Logger log = LoggerFactory.getLogger(BukkitGetBlocks_1_16_1.class);
private static final Function<BlockPosition, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ());
private final static Function<TileEntity, CompoundTag> nmsTile2We = tileEntity -> new LazyCompoundTag_1_16_1(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound())));
private static final Function<TileEntity, CompoundTag> nmsTile2We = tileEntity -> new LazyCompoundTag_1_16_1(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound())));
public ChunkSection[] sections;
public Chunk nmsChunk;
public WorldServer world;
public int X, Z;
public int chunkX;
public int chunkZ;
public NibbleArray[] blockLight = new NibbleArray[16];
public NibbleArray[] skyLight = new NibbleArray[16];
private boolean createCopy = false;
private BukkitGetBlocks_1_16_1_Copy copy = null;
public BukkitGetBlocks_1_16_1(World world, int X, int Z) {
this(((CraftWorld) world).getHandle(), X, Z);
public BukkitGetBlocks_1_16_1(World world, int chunkX, int chunkZ) {
this(((CraftWorld) world).getHandle(), chunkX, chunkZ);
}
public BukkitGetBlocks_1_16_1(WorldServer world, int X, int Z) {
public BukkitGetBlocks_1_16_1(WorldServer world, int chunkX, int chunkZ) {
this.world = world;
this.X = X;
this.Z = Z;
this.chunkX = chunkX;
this.chunkZ = chunkZ;
}
public int getChunkX() {
return chunkX;
}
@Override
@ -83,12 +121,8 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
return copy;
}
public int getX() {
return X;
}
public int getZ() {
return Z;
public int getChunkZ() {
return chunkZ;
}
@Override
@ -98,7 +132,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
if (y == -1) {
for (y = 0; y < FaweCache.IMP.WORLD_HEIGHT; y++) {
base = index.getBiome(x >> 2, y >> 2, z >> 2);
if (base != null) break;
if (base != null) {
break;
}
}
} else {
base = index.getBiome(x >> 2, y >> 2, z >> 2);
@ -108,7 +144,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
@Override
public CompoundTag getTile(int x, int y, int z) {
TileEntity tileEntity = getChunk().getTileEntity(new BlockPosition((x & 15) + (X << 4), y, (z & 15) + (Z << 4)));
TileEntity tileEntity = getChunk().getTileEntity(new BlockPosition((x & 15) + (
chunkX << 4), y, (z & 15) + (
chunkZ << 4)));
if (tileEntity == null) {
return null;
}
@ -193,7 +231,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
List<Entity>[] slices = getChunk().getEntitySlices();
int size = 0;
for (List<Entity> slice : slices) {
if (slice != null) size += slice.size();
if (slice != null) {
size += slice.size();
}
}
if (slices.length == 0) {
return Collections.emptySet();
@ -270,16 +310,16 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
entity.die();
}
public Chunk ensureLoaded(net.minecraft.server.v1_16_R1.World nmsWorld, int X, int Z) {
return BukkitAdapter_1_16_1.ensureLoaded(nmsWorld, X, Z);
public Chunk ensureLoaded(net.minecraft.server.v1_16_R1.World nmsWorld, int chunkX, int chunkZ) {
return BukkitAdapter_1_16_1.ensureLoaded(nmsWorld, chunkX, chunkZ);
}
@Override
public <T extends Future<T>> T call(IChunkSet set, Runnable finalizer) {
copy = createCopy ? new BukkitGetBlocks_1_16_1_Copy(world, getX(), getZ()) : null;
copy = createCopy ? new BukkitGetBlocks_1_16_1_Copy(world, getChunkX(), getChunkZ()) : null;
try {
WorldServer nmsWorld = world;
Chunk nmsChunk = ensureLoaded(nmsWorld, X, Z);
Chunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ);
boolean fastmode = set.isFastMode() && Settings.IMP.QUEUE.NO_TICK_FASTMODE;
// Remove existing tiles
@ -314,7 +354,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
ChunkSection[] sections = nmsChunk.getSections();
for (int layer = 0; layer < 16; layer++) {
if (!set.hasSection(layer)){
if (!set.hasSection(layer)) {
continue;
}
if (createCopy) {
@ -334,7 +374,8 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
} else {
existingSection = sections[layer];
if (existingSection == null) {
log.error("Skipping invalid null section. chunk:" + X + "," + Z + " layer: " + layer);
log.error("Skipping invalid null section. chunk:" + chunkX + "," +
chunkZ + " layer: " + layer);
continue;
}
}
@ -363,7 +404,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
.newChunkSection(layer, this::load, setArr, fastmode);
if (!BukkitAdapter_1_16_1
.setSectionAtomic(sections, existingSection, newSection, layer)) {
log.error("Failed to set chunk section:" + X + "," + Z + " layer: " + layer);
log.error("Failed to set chunk section:" + chunkX + "," + chunkZ + " layer: " + layer);
continue;
} else {
updateGet(this, nmsChunk, sections, newSection, setArr, layer);
@ -426,12 +467,14 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
Runnable[] syncTasks = null;
int bx = X << 4;
int bz = Z << 4;
int bx = chunkX << 4;
int bz = chunkZ << 4;
Set<UUID> entityRemoves = set.getEntityRemoves();
if (entityRemoves != null && !entityRemoves.isEmpty()) {
if (syncTasks == null) syncTasks = new Runnable[3];
if (syncTasks == null) {
syncTasks = new Runnable[3];
}
syncTasks[2] = () -> {
final List<Entity>[] entities = nmsChunk.getEntitySlices();
@ -456,7 +499,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
Set<CompoundTag> entities = set.getEntities();
if (entities != null && !entities.isEmpty()) {
if (syncTasks == null) syncTasks = new Runnable[2];
if (syncTasks == null) {
syncTasks = new Runnable[2];
}
syncTasks[1] = () -> {
for (final CompoundTag nativeTag : entities) {
@ -498,7 +543,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
// set tiles
Map<BlockVector3, CompoundTag> tiles = set.getTiles();
if (tiles != null && !tiles.isEmpty()) {
if (syncTasks == null) syncTasks = new Runnable[1];
if (syncTasks == null) {
syncTasks = new Runnable[1];
}
syncTasks[0] = () -> {
for (final Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) {
@ -540,8 +587,10 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
nmsChunk.mustNotSave = false;
nmsChunk.markDirty();
// send to player
BukkitAdapter_1_16_1.sendChunk(nmsWorld, X, Z, finalMask, finalLightUpdate);
if (finalizer != null) finalizer.run();
BukkitAdapter_1_16_1.sendChunk(nmsWorld, chunkX, chunkZ, finalMask, finalLightUpdate);
if (finalizer != null) {
finalizer.run();
}
};
}
if (syncTasks != null) {
@ -558,7 +607,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
}
}
if (callback == null) {
if (finalizer != null) finalizer.run();
if (finalizer != null) {
finalizer.run();
}
return null;
} else {
return queueHandler.async(callback, null);
@ -571,7 +622,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
return (T) (Future) queueHandler.sync(chain);
} else {
if (callback == null) {
if (finalizer != null) finalizer.run();
if (finalizer != null) {
finalizer.run();
}
} else {
callback.run();
}
@ -721,7 +774,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
synchronized (this) {
tmp = nmsChunk;
if (tmp == null) {
nmsChunk = tmp = ensureLoaded(this.world, X, Z);
nmsChunk = tmp = ensureLoaded(this.world, chunkX, chunkZ);
}
}
}

View File

@ -26,12 +26,13 @@ import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.Objects;
import javax.annotation.Nullable;
public class FAWEWorldNativeAccess_1_16 implements WorldNativeAccess<Chunk, IBlockData, BlockPosition> {
private static final int UPDATE = 1, NOTIFY = 2;
private static final int UPDATE = 1;
private static final int NOTIFY = 2;
private final FAWE_Spigot_v1_16_R1 adapter;
private final WeakReference<World> world;
@ -171,4 +172,4 @@ public class FAWEWorldNativeAccess_1_16 implements WorldNativeAccess<Chunk, IBlo
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, SideEffectSet sideEffects) throws WorldEditException {
return this.adapter.setBlock(this.getChunk(position.getBlockX() >> 4, position.getBlockZ() >> 4).bukkitChunk, position.getBlockX(), position.getBlockY(), position.getBlockZ(), block, sideEffectSet.shouldApply(SideEffect.LIGHTING));
}
}
}