From 1df5853f33c6005c6dc081a91bc00a1a3bf7f562 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 17 Mar 2020 22:27:41 -0400 Subject: [PATCH] Remove unnecessary reflection --- .../adapter/mc1_14/BukkitGetBlocks_1_14.java | 4 +--- .../adapter/mc1_15/BukkitGetBlocks_1_15.java | 4 +--- .../mc1_15_2/BukkitGetBlocks_1_15_2.java | 4 +--- .../wrapper/state/AsyncDataContainer.java | 5 ++--- .../fawe/bukkit/wrapper/state/AsyncSign.java | 5 ++--- .../object/changeset/BlockBagChangeSet.java | 3 +-- .../clipboard/CPUOptimizedClipboard.java | 9 ++------- .../clipboard/DiskOptimizedClipboard.java | 3 +-- .../clipboard/MemoryOptimizedClipboard.java | 6 ++---- .../object/schematic/MinecraftStructure.java | 3 +-- .../java/com/boydti/fawe/util/BrushCache.java | 4 +--- .../java/com/boydti/fawe/util/MainUtil.java | 4 ++-- .../com/boydti/fawe/util/ReflectionUtils.java | 19 ------------------- .../transform/BlockTransformExtent.java | 4 +--- 14 files changed, 18 insertions(+), 59 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java index 52f7d90e8..b48a3e771 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java @@ -11,7 +11,6 @@ import com.boydti.fawe.bukkit.adapter.DelegateLock; import com.boydti.fawe.bukkit.adapter.mc1_14.nbt.LazyCompoundTag_1_14; import com.boydti.fawe.object.collection.AdaptedMap; import com.boydti.fawe.object.collection.BitArray4096; -import com.boydti.fawe.util.ReflectionUtils; import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; import com.sk89q.jnbt.CompoundTag; @@ -41,7 +40,6 @@ import java.util.concurrent.Future; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import javax.annotation.Nullable; import net.minecraft.server.v1_14_R1.BiomeBase; import net.minecraft.server.v1_14_R1.BlockPosition; import net.minecraft.server.v1_14_R1.Chunk; @@ -352,7 +350,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { syncTasks[1] = () -> { for (final CompoundTag nativeTag : entities) { - final Map entityTagMap = ReflectionUtils.getMap(nativeTag.getValue()); + final Map entityTagMap = nativeTag.getValue(); final StringTag idTag = (StringTag) entityTagMap.get("Id"); final ListTag posTag = (ListTag) entityTagMap.get("Pos"); final ListTag rotTag = (ListTag) entityTagMap.get("Rotation"); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java index ae9cb0535..2be4055d8 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java @@ -11,7 +11,6 @@ import com.boydti.fawe.bukkit.adapter.DelegateLock; import com.boydti.fawe.bukkit.adapter.mc1_15.nbt.LazyCompoundTag_1_15; import com.boydti.fawe.object.collection.AdaptedMap; import com.boydti.fawe.object.collection.BitArray4096; -import com.boydti.fawe.util.ReflectionUtils; import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; import com.sk89q.jnbt.CompoundTag; @@ -41,7 +40,6 @@ import java.util.concurrent.Future; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import javax.annotation.Nullable; import net.minecraft.server.v1_15_R1.BiomeBase; import net.minecraft.server.v1_15_R1.BiomeStorage; import net.minecraft.server.v1_15_R1.BlockPosition; @@ -365,7 +363,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { syncTasks[1] = () -> { for (final CompoundTag nativeTag : entities) { - final Map entityTagMap = ReflectionUtils.getMap(nativeTag.getValue()); + final Map entityTagMap = nativeTag.getValue(); final StringTag idTag = (StringTag) entityTagMap.get("Id"); final ListTag posTag = (ListTag) entityTagMap.get("Pos"); final ListTag rotTag = (ListTag) entityTagMap.get("Rotation"); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java index cc6c4bae1..dab8cd329 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java @@ -6,11 +6,9 @@ import com.boydti.fawe.beta.IChunkSet; import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks; import com.boydti.fawe.beta.implementation.queue.QueueHandler; import com.boydti.fawe.bukkit.adapter.DelegateLock; -import com.boydti.fawe.bukkit.adapter.mc1_15.nbt.LazyCompoundTag_1_15; import com.boydti.fawe.bukkit.adapter.mc1_15_2.nbt.LazyCompoundTag_1_15_2; import com.boydti.fawe.object.collection.AdaptedMap; import com.boydti.fawe.object.collection.BitArray4096; -import com.boydti.fawe.util.ReflectionUtils; import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; import com.sk89q.jnbt.Tag; @@ -354,7 +352,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { syncTasks[1] = () -> { for (final CompoundTag nativeTag : entities) { - final Map entityTagMap = ReflectionUtils.getMap(nativeTag.getValue()); + final Map entityTagMap = nativeTag.getValue(); final StringTag idTag = (StringTag) entityTagMap.get("Id"); final ListTag posTag = (ListTag) entityTagMap.get("Pos"); final ListTag rotTag = (ListTag) entityTagMap.get("Rotation"); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java index f79e57190..f1fbbcbb2 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncDataContainer.java @@ -1,7 +1,6 @@ package com.boydti.fawe.bukkit.wrapper.state; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; import java.util.Collections; @@ -35,10 +34,10 @@ public final class AsyncDataContainer implements PersistentDataContainer { Map raw; if (tag == null) { if (!create) return Collections.emptyMap(); - Map map = ReflectionUtils.getMap(root.getValue()); + Map map = root.getValue(); map.put("PublicBukkitValues", new CompoundTag(raw = new HashMap<>())); } else { - raw = ReflectionUtils.getMap(tag.getValue()); + raw = tag.getValue(); } return raw; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java index b3bde9636..c1e97f7e3 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/state/AsyncSign.java @@ -2,7 +2,6 @@ package com.boydti.fawe.bukkit.wrapper.state; import com.boydti.fawe.bukkit.wrapper.AsyncBlock; import com.boydti.fawe.bukkit.wrapper.AsyncBlockState; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; @@ -58,7 +57,7 @@ public class AsyncSign extends AsyncBlockState implements Sign { public void setLine(int index, String line) throws IndexOutOfBoundsException { CompoundTag nbt = getNbtData(); if (nbt != null) { - Map map = ReflectionUtils.getMap(nbt.getValue()); + Map map = nbt.getValue(); map.put("Text" + (index + 1), new StringTag(toJson(line))); } } @@ -92,7 +91,7 @@ public class AsyncSign extends AsyncBlockState implements Sign { public void setColor(DyeColor color) { CompoundTag nbt = getNbtData(); if (nbt != null) { - Map map = ReflectionUtils.getMap(nbt.getValue()); + Map map = nbt.getValue(); map.put("Color", new StringTag(color.name().toLowerCase())); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java index dee7d30bb..c3d17c2a0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java @@ -1,7 +1,6 @@ package com.boydti.fawe.object.changeset; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.extent.inventory.BlockBag; @@ -114,7 +113,7 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet { @Override public void addTileCreate(CompoundTag nbt) { if (nbt.containsKey("items")) { - Map map = ReflectionUtils.getMap(nbt.getValue()); + Map map = nbt.getValue(); map.remove("items"); } super.addTileCreate(nbt); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index bbf8788af..83fa495ca 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -2,14 +2,12 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.jnbt.streamer.IntValueReader; import com.boydti.fawe.object.IntegerTrio; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; @@ -22,11 +20,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.UUID; public class CPUOptimizedClipboard extends LinearClipboard { @@ -153,7 +148,7 @@ public class CPUOptimizedClipboard extends LinearClipboard { for (Map.Entry entry : nbtMapIndex.entrySet()) { int index = entry.getKey(); CompoundTag tag = entry.getValue(); - Map values = ReflectionUtils.getMap(tag.getValue()); + Map values = tag.getValue(); if (!values.containsKey("x")) { int y = index / getArea(); index -= y * getArea(); @@ -175,7 +170,7 @@ public class CPUOptimizedClipboard extends LinearClipboard { public boolean setTile(int index, CompoundTag tag) { nbtMapIndex.put(index, tag); - Map values = ReflectionUtils.getMap(tag.getValue()); + Map values = tag.getValue(); values.remove("x"); values.remove("y"); values.remove("z"); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index ace476311..3dae705d2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -5,7 +5,6 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.jnbt.streamer.IntValueReader; import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; @@ -372,7 +371,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { nbtMap.put(new IntegerTrio(x, y, z), tag); - Map values = ReflectionUtils.getMap(tag.getValue()); + Map values = tag.getValue(); values.put("x", new IntTag(x)); values.put("y", new IntTag(y)); values.put("z", new IntTag(z)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index 9ce701740..6872dc094 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -4,7 +4,6 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.jnbt.streamer.IntValueReader; import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; @@ -12,7 +11,6 @@ import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard.ClipboardEntity; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; @@ -199,7 +197,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard { for (Map.Entry entry : nbtMapIndex.entrySet()) { int index = entry.getKey(); CompoundTag tag = entry.getValue(); - Map values = ReflectionUtils.getMap(tag.getValue()); + Map values = tag.getValue(); if (!values.containsKey("x")) { int y = index / getArea(); index -= y * getArea(); @@ -270,7 +268,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard { public boolean setTile(int index, CompoundTag tag) { nbtMapIndex.put(index, tag); - Map values = ReflectionUtils.getMap(tag.getValue()); + Map values = tag.getValue(); values.remove("x"); values.remove("y"); values.remove("z"); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java index ef83c1285..065c653ef 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/MinecraftStructure.java @@ -3,7 +3,6 @@ package com.boydti.fawe.object.schematic; import static org.slf4j.LoggerFactory.getLogger; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.ListTag; @@ -231,7 +230,7 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter { BaseEntity state = entity.getState(); if (state != null) { CompoundTag nbt = state.getNbtData(); - Map nbtMap = ReflectionUtils.getMap(nbt.getValue()); + Map nbtMap = nbt.getValue(); // Replace rotation data nbtMap.put("Rotation", writeRotation(entity.getLocation())); nbtMap.put("id", new StringTag(state.getType().getId())); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java b/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java index 5aa7c6245..f484c043c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java @@ -2,8 +2,6 @@ package com.boydti.fawe.util; import static org.slf4j.LoggerFactory.getLogger; -import com.boydti.fawe.FaweCache; -import com.boydti.fawe.object.brush.BrushSettings; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.sk89q.jnbt.CompoundTag; @@ -80,7 +78,7 @@ public final class BrushCache { } nbt = new CompoundTag(map = new HashMap<>()); } else { - map = ReflectionUtils.getMap(nbt.getValue()); + map = nbt.getValue(); } brushCache.remove(getKey(item)); CompoundTag display = (CompoundTag) map.get("display"); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/MainUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/MainUtil.java index 25dfbbdea..548cbc78a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/MainUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/MainUtil.java @@ -432,14 +432,14 @@ public class MainUtil { } public static void setPosition(CompoundTag tag, int x, int y, int z) { - Map value = ReflectionUtils.getMap(tag.getValue()); + Map value = tag.getValue(); value.put("x", new IntTag(x)); value.put("y", new IntTag(y)); value.put("z", new IntTag(z)); } public static void setEntityInfo(CompoundTag tag, Entity entity) { - Map map = ReflectionUtils.getMap(tag.getValue()); + Map map = tag.getValue(); map.put("Id", new StringTag(entity.getState().getType().getId())); ListTag pos = (ListTag) map.get("Pos"); if (pos != null) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index 74640b513..3bae038c9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -73,25 +73,6 @@ public class ReflectionUtils { blankField(enumClass, "enumConstants"); // IBM JDK } - private static Class UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.emptyMap()) - .getClass(); - - public static Map getMap(Map map) { - try { - Class clazz = map.getClass(); - if (clazz != UNMODIFIABLE_MAP) { - Fawe.debug("getMap is unused. Please report this to MattBDev on Github or Discord"); - return map; - } - Field m = clazz.getDeclaredField("m"); - m.setAccessible(true); - return (Map) m.get(map); - } catch (Throwable e) { - e.printStackTrace(); - return map; - } - } - public static List getList(List list) { try { Class> clazz = (Class>) Class diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 720072153..6a395446b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -37,7 +37,6 @@ import static com.sk89q.worldedit.util.Direction.findClosest; import static com.sk89q.worldedit.util.Direction.values; import com.boydti.fawe.object.extent.ResettableExtent; -import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; @@ -67,7 +66,6 @@ import java.util.Map; import javax.annotation.Nullable; import com.sk89q.worldedit.world.block.BlockTypesCache; -import java.util.HashMap; import org.jetbrains.annotations.NotNull; import static com.google.common.base.Preconditions.checkNotNull; @@ -335,7 +333,7 @@ public class BlockTransformExtent extends ResettableExtent { Direction newDirection = Direction.findClosest(applyAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL); if (newDirection != null) { - Map values = ReflectionUtils.getMap(tag.getValue()); + Map values = tag.getValue(); values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection))); } }