From 033d3bcd4dca3f5e129ecc5d00f0ca6fafe47cf7 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Sun, 30 Sep 2018 21:19:18 +0200 Subject: [PATCH] Remove some more unncessary/doubled map check --- .../protocol1_11to1_10/storage/EntityTracker.java | 4 +--- .../protocol1_12to1_11_1/storage/EntityTracker.java | 4 +--- .../protocol1_13to1_12_2/providers/PaintingProvider.java | 8 +------- .../protocol1_13to1_12_2/storage/EntityTracker.java | 4 +--- .../protocols/protocol1_9to1_8/metadata/MetaIndex.java | 7 +------ .../protocol1_9to1_8/storage/CommandBlockStorage.java | 7 +++++-- common/src/main/java/us/myles/ViaVersion/util/Config.java | 2 +- 7 files changed, 11 insertions(+), 25 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/storage/EntityTracker.java index 328be0ec6..f0864562b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/storage/EntityTracker.java @@ -33,9 +33,7 @@ public class EntityTracker extends StoredObject { } public Optional get(int id) { - if (!has(id)) - return Optional.absent(); - return Optional.of(clientEntityTypes.get(id)); + return Optional.fromNullable(clientEntityTypes.get(id)); } public void addHologram(int entId) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/EntityTracker.java index 1464d0468..015831329 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/EntityTracker.java @@ -28,9 +28,7 @@ public class EntityTracker extends StoredObject { } public Optional get(int id) { - if (!has(id)) - return Optional.absent(); - return Optional.of(clientEntityTypes.get(id)); + return Optional.fromNullable(clientEntityTypes.get(id)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java index 61b29fbb4..819aa808c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java @@ -46,12 +46,6 @@ public class PaintingProvider implements Provider { // Handle older versions if (!motive.startsWith("minecraft:")) motive = "minecraft:" + motive.toLowerCase(); - - Integer index = paintings.get(motive); - if (index != null) { - return Optional.of(index); - } - - return Optional.absent(); + return Optional.fromNullable(paintings.get(motive)); } } \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/EntityTracker.java index db7994407..9b23f76da 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/EntityTracker.java @@ -28,9 +28,7 @@ public class EntityTracker extends StoredObject { } public Optional get(int id) { - if (!has(id)) - return Optional.absent(); - return Optional.of(clientEntityTypes.get(id)); + return Optional.fromNullable(clientEntityTypes.get(id)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java index 3c69cf583..3d2ef48ab 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java @@ -173,12 +173,7 @@ public enum MetaIndex { private static Optional getIndex(Entity1_10Types.EntityType type, int index) { Pair pair = new Pair<>(type, index); - MetaIndex metaIndex = metadataRewrites.get(pair); - if (metaIndex != null) { - return Optional.of(metaIndex); - } - - return Optional.absent(); + return Optional.fromNullable(metadataRewrites.get(pair)); } public static MetaIndex searchIndex(Entity1_10Types.EntityType type, int index) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java index 41841df84..d6e99db20 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java @@ -57,11 +57,14 @@ public class CommandBlockStorage extends StoredObject { if (blocks == null) return Optional.absent(); - CompoundTag tag = blocks.get(position).clone(); + CompoundTag tag = blocks.get(position); + if (tag == null) + return Optional.absent(); + + tag = tag.clone(); tag.put(new ByteTag("powered", (byte) 0)); tag.put(new ByteTag("auto", (byte) 0)); tag.put(new ByteTag("conditionMet", (byte) 0)); - return Optional.of(tag); } diff --git a/common/src/main/java/us/myles/ViaVersion/util/Config.java b/common/src/main/java/us/myles/ViaVersion/util/Config.java index 590895db0..822b9c29f 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/Config.java +++ b/common/src/main/java/us/myles/ViaVersion/util/Config.java @@ -183,7 +183,7 @@ public abstract class Config implements ConfigurationProvider { public List getIntegerList(String key) { Object o = this.config.get(key); if (o != null) { - return (List) this.config.get(key); + return (List) o; } else { return new ArrayList<>(); }