Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-24 18:10:08 +01:00
Remove unnecessary reflection
Dieser Commit ist enthalten in:
Ursprung
ecedc1ff12
Commit
1df5853f33
@ -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<String, Tag> entityTagMap = ReflectionUtils.getMap(nativeTag.getValue());
|
||||
final Map<String, Tag> entityTagMap = nativeTag.getValue();
|
||||
final StringTag idTag = (StringTag) entityTagMap.get("Id");
|
||||
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
|
||||
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");
|
||||
|
@ -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<String, Tag> entityTagMap = ReflectionUtils.getMap(nativeTag.getValue());
|
||||
final Map<String, Tag> entityTagMap = nativeTag.getValue();
|
||||
final StringTag idTag = (StringTag) entityTagMap.get("Id");
|
||||
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
|
||||
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");
|
||||
|
@ -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<String, Tag> entityTagMap = ReflectionUtils.getMap(nativeTag.getValue());
|
||||
final Map<String, Tag> entityTagMap = nativeTag.getValue();
|
||||
final StringTag idTag = (StringTag) entityTagMap.get("Id");
|
||||
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
|
||||
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");
|
||||
|
@ -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<String, Tag> raw;
|
||||
if (tag == null) {
|
||||
if (!create) return Collections.emptyMap();
|
||||
Map<String, Tag> map = ReflectionUtils.getMap(root.getValue());
|
||||
Map<String, Tag> map = root.getValue();
|
||||
map.put("PublicBukkitValues", new CompoundTag(raw = new HashMap<>()));
|
||||
} else {
|
||||
raw = ReflectionUtils.getMap(tag.getValue());
|
||||
raw = tag.getValue();
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
@ -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<String, Tag> map = ReflectionUtils.getMap(nbt.getValue());
|
||||
Map<String, Tag> 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<String, Tag> map = ReflectionUtils.getMap(nbt.getValue());
|
||||
Map<String, Tag> map = nbt.getValue();
|
||||
map.put("Color", new StringTag(color.name().toLowerCase()));
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Tag> map = ReflectionUtils.getMap(nbt.getValue());
|
||||
Map<String, Tag> map = nbt.getValue();
|
||||
map.remove("items");
|
||||
}
|
||||
super.addTileCreate(nbt);
|
||||
|
@ -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<Integer, CompoundTag> entry : nbtMapIndex.entrySet()) {
|
||||
int index = entry.getKey();
|
||||
CompoundTag tag = entry.getValue();
|
||||
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
|
||||
Map<String, Tag> 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<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
|
||||
Map<String, Tag> values = tag.getValue();
|
||||
values.remove("x");
|
||||
values.remove("y");
|
||||
values.remove("z");
|
||||
|
@ -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<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
|
||||
Map<String, Tag> values = tag.getValue();
|
||||
values.put("x", new IntTag(x));
|
||||
values.put("y", new IntTag(y));
|
||||
values.put("z", new IntTag(z));
|
||||
|
@ -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<Integer, CompoundTag> entry : nbtMapIndex.entrySet()) {
|
||||
int index = entry.getKey();
|
||||
CompoundTag tag = entry.getValue();
|
||||
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
|
||||
Map<String, Tag> 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<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
|
||||
Map<String, Tag> values = tag.getValue();
|
||||
values.remove("x");
|
||||
values.remove("y");
|
||||
values.remove("z");
|
||||
|
@ -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<String, Tag> nbtMap = ReflectionUtils.getMap(nbt.getValue());
|
||||
Map<String, Tag> nbtMap = nbt.getValue();
|
||||
// Replace rotation data
|
||||
nbtMap.put("Rotation", writeRotation(entity.getLocation()));
|
||||
nbtMap.put("id", new StringTag(state.getType().getId()));
|
||||
|
@ -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");
|
||||
|
@ -432,14 +432,14 @@ public class MainUtil {
|
||||
}
|
||||
|
||||
public static void setPosition(CompoundTag tag, int x, int y, int z) {
|
||||
Map<String, Tag> value = ReflectionUtils.getMap(tag.getValue());
|
||||
Map<String, Tag> 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<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
|
||||
Map<String, Tag> map = tag.getValue();
|
||||
map.put("Id", new StringTag(entity.getState().getType().getId()));
|
||||
ListTag pos = (ListTag) map.get("Pos");
|
||||
if (pos != null) {
|
||||
|
@ -73,25 +73,6 @@ public class ReflectionUtils {
|
||||
blankField(enumClass, "enumConstants"); // IBM JDK
|
||||
}
|
||||
|
||||
private static Class<?> UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.emptyMap())
|
||||
.getClass();
|
||||
|
||||
public static <T, V> Map<T, V> getMap(Map<T, V> map) {
|
||||
try {
|
||||
Class<? extends Map> 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<T, V>) m.get(map);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> getList(List<T> list) {
|
||||
try {
|
||||
Class<? extends List<T>> clazz = (Class<? extends List<T>>) Class
|
||||
|
@ -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<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
|
||||
Map<String, Tag> values = tag.getValue();
|
||||
values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren