From aea5b68ced63511b0e0c13b3a94c5582b9d013e9 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Thu, 30 May 2019 16:07:30 -0400 Subject: [PATCH] Upstream merges and a few code cleanups --- .../fawe/bukkit/v1_13/BukkitChunk_1_13.java | 25 +++++------ .../fawe/bukkit/v1_13/BukkitQueue_1_13.java | 41 ++++++++----------- .../com/boydti/fawe/command/Rollback.java | 11 ++--- .../com/boydti/fawe/example/IntFaweChunk.java | 8 ++-- .../fawe/jnbt/CorruptSchematicStreamer.java | 3 +- .../com/boydti/fawe/jnbt/anvil/MCAChunk.java | 4 +- .../com/boydti/fawe/jnbt/anvil/MCAWriter.java | 3 +- .../fawe/jnbt/anvil/WritableMCAChunk.java | 4 +- .../boydti/fawe/object/FaweOutputStream.java | 4 +- .../object/changeset/DiskStorageHistory.java | 4 +- .../java/com/boydti/fawe/util/MainUtil.java | 15 +++---- .../function/mask/BlockMaskBuilder.java | 4 +- .../com/sk89q/worldedit/registry/Keyed.java | 31 ++++++++++++++ .../sk89q/worldedit/registry/Registry.java | 12 +++--- .../FunctionParametricCallable.java | 6 +-- .../worldedit/world/block/BlockState.java | 2 + .../worldedit/world/block/BlockType.java | 14 ++++--- 17 files changed, 102 insertions(+), 89 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/registry/Keyed.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_13/BukkitChunk_1_13.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_13/BukkitChunk_1_13.java index 2ccfa8b5d..9a67be5a9 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_13/BukkitChunk_1_13.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_13/BukkitChunk_1_13.java @@ -192,11 +192,11 @@ public class BukkitChunk_1_13 extends IntFaweChunk { byte[] newBlockBytes = newBlockLight.asBytes(); byte[] blockLightBytes = blockLight.asBytes(); - for (int i = 0; i < 2048; i++) newBlockBytes[i] = blockLightBytes[i]; + System.arraycopy(blockLightBytes, 0, newBlockBytes, 0, 2048); if (skyLight != null) { byte[] newSkyBytes = newSkyLight.asBytes(); byte[] skyLightBytes = skyLight.asBytes(); - for (int i = 0; i < 2048; i++) newSkyBytes[i] = skyLightBytes[i]; + System.arraycopy(skyLightBytes, 0, newSkyBytes, 0, 2048); } // Copy counters @@ -241,7 +241,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk { Object[] currArray = ((Object[]) BukkitQueue_1_13.fieldLinearBlocks.get(currentPalette)); Object[] newArray = ((Object[]) BukkitQueue_1_13.fieldLinearBlocks.get(newPalette)); BukkitQueue_1_13.fieldLinearIndex.set(newPalette, BukkitQueue_1_13.fieldLinearIndex.get(currentPalette)); - for (int i = 0; i < newArray.length; i++) newArray[i] = currArray[i]; + System.arraycopy(currArray, 0, newArray, 0, newArray.length); } BukkitQueue_1_13.fieldPalette.set(paletteBlock, newPalette); @@ -348,8 +348,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk { // Remove entities HashSet entsToRemove = this.getEntityRemoves(); if (!entsToRemove.isEmpty()) { - for (int i = 0; i < entities.length; i++) { - Collection ents = entities[i]; + for (Collection ents : entities) { if (!ents.isEmpty()) { Iterator iter = ents.iterator(); while (iter.hasNext()) { @@ -445,13 +444,11 @@ public class BukkitChunk_1_13 extends IntFaweChunk { UUID uuid = entity.getUniqueID(); entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits())); entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits())); - if (nativeTag != null) { - NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_13.fromNative(nativeTag); - for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { - tag.remove(name); - } - entity.f(tag); + NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_13.fromNative(nativeTag); + for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { + tag.remove(name); } + entity.f(tag); entity.setLocation(x, y, z, yaw, pitch); synchronized (BukkitQueue_0.class) { nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); @@ -547,9 +544,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk { // Trim tiles HashMap toRemove = null; if (!tiles.isEmpty()) { - Iterator> iterator = tiles.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry tile = iterator.next(); + for (Map.Entry tile : tiles.entrySet()) { BlockPosition pos = tile.getKey(); int lx = pos.getX() & 15; int ly = pos.getY(); @@ -629,4 +624,4 @@ public class BukkitChunk_1_13 extends IntFaweChunk { } return this; } -} \ No newline at end of file +} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_13/BukkitQueue_1_13.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_13/BukkitQueue_1_13.java index 7b9d2bb23..0944fb232 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_13/BukkitQueue_1_13.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_13/BukkitQueue_1_13.java @@ -691,27 +691,24 @@ public class BukkitQueue_1_13 extends BukkitQueue_0() { - @Override - public Object get() { - try { - int dirtyBits = fieldDirtyBits.getInt(playerChunk); - if (dirtyBits == 0) { - ((CraftWorld) getWorld()).getHandle().getPlayerChunkMap().a(playerChunk); - } - if (mask == 0) { - dirtyBits = 65535; - } else { - dirtyBits |= mask; - } - - fieldDirtyBits.set(playerChunk, dirtyBits); - fieldDirtyCount.set(playerChunk, 64); - } catch (IllegalAccessException e) { - e.printStackTrace(); + TaskManager.IMP.sync(() -> { + try { + int dirtyBits = fieldDirtyBits.getInt(playerChunk); + if (dirtyBits == 0) { + ((CraftWorld) getWorld()).getHandle().getPlayerChunkMap().a(playerChunk); } - return null; + if (mask == 0) { + dirtyBits = 65535; + } else { + dirtyBits |= mask; + } + + fieldDirtyBits.set(playerChunk, dirtyBits); + fieldDirtyCount.set(playerChunk, 64); + } catch (IllegalAccessException e) { + e.printStackTrace(); } + return null; }); } // if (mask == 0) { @@ -754,8 +751,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0[] entities = nmsChunk.entitySlices; - for (int i = 0; i < entities.length; i++) { - Collection slice = entities[i]; + for (Collection slice : entities) { if (slice != null && !slice.isEmpty()) { return true; } @@ -781,8 +777,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0 u: r: t: