From 44a4ffb26af2d87ca975b3cce637ca8d2f2b33ca Mon Sep 17 00:00:00 2001 From: Nassim <28825609+KennyTV@users.noreply.github.com> Date: Sat, 21 Sep 2019 11:57:28 +0200 Subject: [PATCH] Migrate to Java optionals (#1458) * Add fromEntityType method to 1.13 objecttypes * Migrate guava optionals to java optionals --- .../api/entities/Entity1_10Types.java | 14 +- .../api/entities/Entity1_11Types.java | 14 +- .../api/entities/Entity1_12Types.java | 14 +- .../api/entities/Entity1_13Types.java | 22 ++- .../api/entities/Entity1_14Types.java | 12 +- .../api/entities/Entity1_15Types.java | 6 +- .../ViaVersion/api/storage/EntityTracker.java | 16 +- .../Protocol1_11To1_10.java | 3 +- .../metadata/MetadataRewriter1_11To1_10.java | 15 +- .../Protocol1_12To1_11_1.java | 3 +- .../packets/EntityPackets.java | 10 +- .../data/EntityNameRewriter.java | 4 +- .../data/EntityTypeRewriter.java | 11 +- .../data/NamedSoundRewriter.java | 3 +- .../data/ParticleRewriter.java | 4 +- .../data/SoundSource.java | 7 +- .../data/SpawnEggRewriter.java | 9 +- .../packets/EntityPackets.java | 7 +- .../packets/InventoryPackets.java | 19 +-- .../packets/WorldPackets.java | 4 +- .../providers/BlockEntityProvider.java | 4 +- .../providers/PaintingProvider.java | 8 +- .../blockentities/FlowerPotHandler.java | 6 +- .../storage/BlockStorage.java | 8 +- .../packets/EntityPackets.java | 147 +++++++++--------- .../data/EntityTypeRewriter.java | 7 +- .../packets/EntityPackets.java | 11 +- .../packets/EntityPackets.java | 4 +- .../chunks/BlockEntity.java | 6 +- .../chunks/FakeTileEntity.java | 4 +- .../protocol1_9to1_8/metadata/MetaIndex.java | 4 +- .../packets/EntityPackets.java | 1 - .../packets/SpawnPackets.java | 2 +- .../packets/WorldPackets.java | 2 +- .../providers/CommandBlockProvider.java | 5 +- .../storage/CommandBlockStorage.java | 6 +- .../storage/EntityTracker1_9.java | 7 +- 37 files changed, 214 insertions(+), 215 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_10Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_10Types.java index 78cc31906..acc05fac7 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_10Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_10Types.java @@ -1,12 +1,12 @@ package us.myles.ViaVersion.api.entities; -import com.google.common.base.Optional; import lombok.AllArgsConstructor; import lombok.Getter; import us.myles.ViaVersion.api.Via; import java.util.HashMap; import java.util.Map; +import java.util.Optional; // 1.10 Entity / Object ids public class Entity1_10Types { @@ -134,8 +134,8 @@ public class Entity1_10Types { public static Optional findById(int id) { if (id == -1) // Check if this is called - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } } @@ -181,16 +181,16 @@ public class Entity1_10Types { public static Optional findById(int id) { if (id == -1) - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } public static Optional getPCEntity(int id) { Optional output = findById(id); if (!output.isPresent()) - return Optional.absent(); - return Optional.of(output.get().getType()); + return Optional.empty(); + return Optional.of(output.get().type); } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_11Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_11Types.java index 500ed0f7a..96d9be2d5 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_11Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_11Types.java @@ -1,12 +1,12 @@ package us.myles.ViaVersion.api.entities; -import com.google.common.base.Optional; import lombok.AllArgsConstructor; import lombok.Getter; import us.myles.ViaVersion.api.Via; import java.util.HashMap; import java.util.Map; +import java.util.Optional; // 1.11 Entity / Object ids TODO maybe in the future instead of copying it, some api. public class Entity1_11Types { @@ -162,8 +162,8 @@ public class Entity1_11Types { public static Optional findById(int id) { if (id == -1) // Check if this is called - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } } @@ -211,16 +211,16 @@ public class Entity1_11Types { public static Optional findById(int id) { if (id == -1) - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } public static Optional getPCEntity(int id) { Optional output = findById(id); if (!output.isPresent()) - return Optional.absent(); - return Optional.of(output.get().getType()); + return Optional.empty(); + return Optional.of(output.get().type); } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_12Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_12Types.java index a844e8ae7..cb6586ef4 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_12Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_12Types.java @@ -10,13 +10,13 @@ package us.myles.ViaVersion.api.entities; -import com.google.common.base.Optional; import lombok.AllArgsConstructor; import lombok.Getter; import us.myles.ViaVersion.api.Via; import java.util.HashMap; import java.util.Map; +import java.util.Optional; // 1.12 Entity / Object taken from https://github.com/Matsv/ViaBackwards/blob/master/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_12.java public class Entity1_12Types { @@ -175,8 +175,8 @@ public class Entity1_12Types { public static Optional findById(int id) { if (id == -1) // Check if this is called - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } } @@ -224,16 +224,16 @@ public class Entity1_12Types { public static Optional findById(int id) { if (id == -1) - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } public static Optional getPCEntity(int id) { Optional output = findById(id); if (!output.isPresent()) - return Optional.absent(); - return Optional.of(output.get().getType()); + return Optional.empty(); + return Optional.of(output.get().type); } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java index 253688ea3..33e8b22a5 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java @@ -1,12 +1,12 @@ package us.myles.ViaVersion.api.entities; -import com.google.common.base.Optional; import lombok.AllArgsConstructor; import lombok.Getter; import us.myles.ViaVersion.api.Via; import java.util.HashMap; import java.util.Map; +import java.util.Optional; // TODO auto generate 18w11a with PAaaS public class Entity1_13Types { @@ -217,8 +217,8 @@ public class Entity1_13Types { public static Optional findById(int id) { if (id == -1) // Check if this is called - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } } @@ -267,16 +267,22 @@ public class Entity1_13Types { public static Optional findById(int id) { if (id == -1) - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } public static Optional getPCEntity(int id) { Optional output = findById(id); - if (!output.isPresent()) - return Optional.absent(); - return Optional.of(output.get().getType()); + return Optional.empty(); + return Optional.of(output.get().type); + } + + public static Optional fromEntityType(EntityType type) { + for (ObjectType ent : ObjectType.values()) + if (ent.type == type) + return Optional.of(ent); + return Optional.empty(); } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java index df81d6e6e..732ce68ed 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java @@ -1,22 +1,22 @@ package us.myles.ViaVersion.api.entities; -import com.google.common.base.Optional; import lombok.AllArgsConstructor; import lombok.Getter; import us.myles.ViaVersion.api.Via; import java.util.HashMap; import java.util.Map; +import java.util.Optional; public class Entity1_14Types { public static EntityType getTypeFromId(int typeID) { - Optional type = Entity1_14Types.EntityType.findById(typeID); + Optional type = EntityType.findById(typeID); if (!type.isPresent()) { Via.getPlatform().getLogger().severe("Could not find type id " + typeID); - return Entity1_14Types.EntityType.ENTITY; // Fall back to the basic ENTITY + return EntityType.ENTITY; // Fall back to the basic ENTITY } return type.get(); @@ -212,15 +212,15 @@ public class Entity1_14Types { } static { - for (EntityType type : Entity1_14Types.EntityType.values()) { + for (EntityType type : EntityType.values()) { TYPES.put(type.id, type); } } public static Optional findById(int id) { if (id == -1) - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_15Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_15Types.java index efa9e2780..000dc7a97 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_15Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_15Types.java @@ -1,12 +1,12 @@ package us.myles.ViaVersion.api.entities; -import com.google.common.base.Optional; import lombok.AllArgsConstructor; import lombok.Getter; import us.myles.ViaVersion.api.Via; import java.util.HashMap; import java.util.Map; +import java.util.Optional; public class Entity1_15Types { @@ -219,8 +219,8 @@ public class Entity1_15Types { public static Optional findById(int id) { if (id == -1) - return Optional.absent(); - return Optional.fromNullable(TYPES.get(id)); + return Optional.empty(); + return Optional.ofNullable(TYPES.get(id)); } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java index 6db9a8ec6..931b5592c 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java @@ -1,20 +1,16 @@ package us.myles.ViaVersion.api.storage; -import com.google.common.base.Optional; -import lombok.Getter; -import lombok.Setter; import us.myles.ViaVersion.api.data.ExternalJoinGameListener; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.entities.EntityType; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; public abstract class EntityTracker extends StoredObject implements ExternalJoinGameListener { private final Map clientEntityTypes = new ConcurrentHashMap<>(); - @Getter - @Setter private int clientEntityId; private final T playerType; @@ -36,7 +32,7 @@ public abstract class EntityTracker extends StoredObject i } public Optional getEntity(int entityId) { - return Optional.fromNullable(clientEntityTypes.get(entityId)); + return Optional.ofNullable(clientEntityTypes.get(entityId)); } @Override @@ -44,4 +40,12 @@ public abstract class EntityTracker extends StoredObject i clientEntityId = playerEntityId; clientEntityTypes.put(playerEntityId, playerType); } + + public int getClientEntityId() { + return clientEntityId; + } + + public void setClientEntityId(int clientEntityId) { + this.clientEntityId = clientEntityId; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java index c7a151106..26fa37ef7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java @@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_11to1_10; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -22,6 +21,8 @@ import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker1_1 import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; +import java.util.Optional; + public class Protocol1_11To1_10 extends Protocol { private static final ValueTransformer toOldByte = new ValueTransformer(Type.UNSIGNED_BYTE) { @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java index c14a8ab7b..531cf1a33 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java @@ -1,10 +1,8 @@ package us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.entities.Entity1_11Types; import us.myles.ViaVersion.api.entities.Entity1_11Types.EntityType; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -17,8 +15,9 @@ import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker1_1 import java.util.List; import java.util.Map; +import java.util.Optional; -public class MetadataRewriter1_11To1_10 extends MetadataRewriter { +public class MetadataRewriter1_11To1_10 extends MetadataRewriter { @Override protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List metadatas, Map metadataMap, UserConnection connection) { @@ -95,15 +94,15 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter flags = Optional.fromNullable(metadataMap.get(11)); - Optional customName = Optional.fromNullable(metadataMap.get(2)); - Optional customNameVisible = Optional.fromNullable(metadataMap.get(3)); + Optional flags = Optional.ofNullable(metadataMap.get(11)); + Optional customName = Optional.ofNullable(metadataMap.get(2)); + Optional customNameVisible = Optional.ofNullable(metadataMap.get(3)); if (metadata.getId() == 0 && flags.isPresent() && customName.isPresent() && customNameVisible.isPresent()) { Metadata meta = flags.get(); byte data = (byte) metadata.getValue(); // Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true if ((data & 0x20) == 0x20 && ((byte) meta.getValue() & 0x01) == 0x01 - && !((String) customName.get().getValue()).isEmpty() && (boolean) customNameVisible.get().getValue()) { + && !((String) customName.get().getValue()).isEmpty() && (boolean) customNameVisible.get().getValue()) { EntityTracker1_11 tracker = connection.get(EntityTracker1_11.class); if (!tracker.isHologram(entityId)) { tracker.addHologram(entityId); @@ -212,6 +211,6 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId); - protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); + Optional type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId); + protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java index df918be0b..d1a5b83ba 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java @@ -1,7 +1,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; +import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; /* CHANGED ENTITY NAMES IN 1.13 @@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap; xp_orb => experience_orb */ public class EntityNameRewriter { - private static Map entityNames = new ConcurrentHashMap<>(); + private static final Map entityNames = new HashMap<>(); static { /* diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java index 0a2c17518..0573c2c72 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java @@ -1,13 +1,12 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; -import com.google.common.base.Optional; - +import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import java.util.Optional; public class EntityTypeRewriter { - private static Map entityTypes = new ConcurrentHashMap<>(); + private static final Map entityTypes = new HashMap<>(); static { registerEntity(1, 32); // item - ajl @@ -94,10 +93,8 @@ public class EntityTypeRewriter { registerEntity(105, 50); // parrot - agx registerEntity(120, 79); // villager - ala - // OBJECTS // Couldn't find any object id change with mapped values - } private static void registerEntity(int type1_12, int type1_13) { @@ -105,6 +102,6 @@ public class EntityTypeRewriter { } public static Optional getNewId(int type1_12) { - return Optional.fromNullable(entityTypes.get(type1_12)); + return Optional.ofNullable(entityTypes.get(type1_12)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/NamedSoundRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/NamedSoundRewriter.java index 64a75681a..fa300c7d7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/NamedSoundRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/NamedSoundRewriter.java @@ -5,7 +5,7 @@ import java.util.Locale; import java.util.Map; public class NamedSoundRewriter { - private static Map oldToNew = new HashMap<>(); + private static final Map oldToNew = new HashMap<>(); static { // Extracted from Minecraft Wiki @@ -144,7 +144,6 @@ public class NamedSoundRewriter { oldToNew.put("record.strad", "music_disc.strad"); oldToNew.put("record.wait", "music_disc.wait"); oldToNew.put("record.ward", "music_disc.ward"); - } public static String getNewId(String old) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java index e700ac779..4ec271722 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java @@ -8,13 +8,13 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; +import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.ThreadLocalRandom; public class ParticleRewriter { - private static List particles = new LinkedList<>(); + private static final List particles = new ArrayList<>(); static { add(34); // (0->34) explode -> minecraft:poof diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SoundSource.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SoundSource.java index c6aeeabed..0d6ac2c44 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SoundSource.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SoundSource.java @@ -1,9 +1,10 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; -import com.google.common.base.Optional; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Optional; + @Getter @AllArgsConstructor public enum SoundSource { @@ -23,8 +24,8 @@ public enum SoundSource { public static Optional findBySource(String source) { for (SoundSource item : SoundSource.values()) - if (item.getName().equalsIgnoreCase(source)) + if (item.name.equalsIgnoreCase(source)) return Optional.of(item); - return Optional.absent(); + return Optional.empty(); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java index d4ff6564c..fc351c1c8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java @@ -1,11 +1,12 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; -import com.google.common.base.Optional; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import java.util.Optional; + public class SpawnEggRewriter { - private final static BiMap spawnEggs = HashBiMap.create(); + private static final BiMap spawnEggs = HashBiMap.create(); static { // Class yz.java in 18w14b @@ -70,7 +71,7 @@ public class SpawnEggRewriter { } public static Optional getEntityId(int spawnEggId) { - if (spawnEggId >> 16 != 383) return Optional.absent(); - return Optional.fromNullable(spawnEggs.inverse().get(spawnEggId & 0xFFFF)); + if (spawnEggId >> 16 != 383) return Optional.empty(); + return Optional.ofNullable(spawnEggs.inverse().get(spawnEggId & 0xFFFF)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java index 36dc8137d..013a6e465 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java @@ -1,6 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.protocol.Protocol; @@ -14,6 +13,8 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewrite import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; +import java.util.Optional; + public class EntityPackets { public static void register(final Protocol protocol) { // Outgoing packets @@ -103,7 +104,7 @@ public class EntityPackets { int type = wrapper.get(Type.VAR_INT, 1); Optional optNewType = EntityTypeRewriter.getNewId(type); - type = optNewType.or(type); + type = optNewType.orElse(type); Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false); wrapper.set(Type.VAR_INT, 1, type); @@ -172,7 +173,7 @@ public class EntityPackets { int entityId = wrapper.get(Type.VAR_INT, 0); Optional type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId); - protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); + protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index a66ea41bb..891181295 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -1,14 +1,8 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; import com.github.steveice10.opennbt.conversion.ConverterRegistry; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.IntTag; -import com.github.steveice10.opennbt.tag.builtin.ListTag; -import com.github.steveice10.opennbt.tag.builtin.ShortTag; -import com.github.steveice10.opennbt.tag.builtin.StringTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; +import com.github.steveice10.opennbt.tag.builtin.*; import com.google.common.base.Joiner; -import com.google.common.base.Optional; import com.google.common.primitives.Ints; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; @@ -28,6 +22,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.Optional; public class InventoryPackets { private static String NBT_TAG_NAME; @@ -124,7 +119,7 @@ public class InventoryPackets { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().info("Could not handle unknown sound source " + originalSource + " falling back to default: master"); } - finalSource = Optional.of(SoundSource.MASTER); + finalSource = java.util.Optional.of(SoundSource.MASTER); } @@ -514,9 +509,9 @@ public class InventoryPackets { case "bungeecord:main": return null; case "FML|MP": - return "fml:mp"; + return "fml:mp"; case "FML|HS": - return "fml:hs"; + return "fml:hs"; default: return old.matches("([0-9a-z_.-]+):([0-9a-z_/.-]+)") // Identifier regex ? old : null; @@ -759,9 +754,9 @@ public class InventoryPackets { case "wdl:request": return "WDL|REQUEST"; case "fml:hs": - return "FML|HS"; + return "FML|HS"; case "fml:mp": - return "FML:MP"; + return "FML:MP"; default: return newId.length() > 20 ? newId.substring(0, 20) : newId; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 17680c8e0..06cb00462 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -1,7 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -30,6 +29,7 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; public class WorldPackets { @@ -76,7 +76,7 @@ public class WorldPackets { if (!id.isPresent() && (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug())) { Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)"); } - wrapper.write(Type.VAR_INT, id.or(0)); + wrapper.write(Type.VAR_INT, id.orElse(0)); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java index 4543eb367..caad565a8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java @@ -10,11 +10,11 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.*; +import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; public class BlockEntityProvider implements Provider { - private final Map handlers = new ConcurrentHashMap<>(); + private final Map handlers = new HashMap<>(); public BlockEntityProvider() { handlers.put("minecraft:flower_pot", new FlowerPotHandler()); 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 f6c190cca..b1f507c5b 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 @@ -1,14 +1,14 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.platform.providers.Provider; +import java.util.HashMap; import java.util.Locale; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import java.util.Optional; public class PaintingProvider implements Provider { - private Map paintings = new ConcurrentHashMap<>(); + private final Map paintings = new HashMap<>(); public PaintingProvider() { add("kebab"); @@ -47,6 +47,6 @@ public class PaintingProvider implements Provider { // Handle older versions if (!motive.startsWith("minecraft:")) motive = "minecraft:" + motive.toLowerCase(Locale.ROOT); - return Optional.fromNullable(paintings.get(motive)); + return Optional.ofNullable(paintings.get(motive)); } } \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java index 244afae94..059ec9673 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java @@ -6,12 +6,12 @@ import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; +import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler { - private static final Map, Integer> flowers = new ConcurrentHashMap<>(); - private static final Map, Integer> flowersNumberId = new ConcurrentHashMap<>(); + private static final Map, Integer> flowers = new HashMap<>(); + private static final Map, Integer> flowersNumberId = new HashMap<>(); static { register("minecraft:air", (byte) 0, (byte) 0, 5265); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java index 8137f764a..a15ce7004 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java @@ -1,19 +1,19 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage; -import com.google.common.collect.Sets; import lombok.AllArgsConstructor; import lombok.Data; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.Position; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class BlockStorage extends StoredObject { - // This BlockStorage is very exclusive (; - private static final Set whitelist = Sets.newConcurrentHashSet(); + private static final Set whitelist = new HashSet<>(); + private final Map blocks = new ConcurrentHashMap<>(); static { // Flower pots @@ -37,8 +37,6 @@ public class BlockStorage extends StoredObject { whitelist.add(5447 + i); } - private Map blocks = new ConcurrentHashMap<>(); - public BlockStorage(UserConnection user) { super(user); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java index e153c87c3..60d3447a9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java @@ -1,6 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.entities.Entity1_14Types; import us.myles.ViaVersion.api.protocol.Protocol; @@ -12,90 +11,92 @@ import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1; +import java.util.Optional; + public class EntityPackets { - public static void register(final Protocol protocol) { + public static void register(final Protocol protocol) { - // Spawn Mob - protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Type.UUID); // 1 - Entity UUID - map(Type.VAR_INT); // 2 - Entity Type - map(Type.DOUBLE); // 3 - X - map(Type.DOUBLE); // 4 - Y - map(Type.DOUBLE); // 5 - Z - map(Type.BYTE); // 6 - Yaw - map(Type.BYTE); // 7 - Pitch - map(Type.BYTE); // 8 - Head Pitch - map(Type.SHORT); // 9 - Velocity X - map(Type.SHORT); // 10 - Velocity Y - map(Type.SHORT); // 11 - Velocity Z - map(Types1_14.METADATA_LIST); // 12 - Metadata + // Spawn Mob + protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.UUID); // 1 - Entity UUID + map(Type.VAR_INT); // 2 - Entity Type + map(Type.DOUBLE); // 3 - X + map(Type.DOUBLE); // 4 - Y + map(Type.DOUBLE); // 5 - Z + map(Type.BYTE); // 6 - Yaw + map(Type.BYTE); // 7 - Pitch + map(Type.BYTE); // 8 - Head Pitch + map(Type.SHORT); // 9 - Velocity X + map(Type.SHORT); // 10 - Velocity Y + map(Type.SHORT); // 11 - Velocity Z + map(Types1_14.METADATA_LIST); // 12 - Metadata - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); - int type = wrapper.get(Type.VAR_INT, 1); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); + int type = wrapper.get(Type.VAR_INT, 1); - Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); + Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); - // Register Type ID - wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType); + // Register Type ID + wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType); - protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); - } - }); - } - }); + protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); - // Spawn Player - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Type.UUID); // 1 - Player UUID - map(Type.DOUBLE); // 2 - X - map(Type.DOUBLE); // 3 - Y - map(Type.DOUBLE); // 4 - Z - map(Type.BYTE); // 5 - Yaw - map(Type.BYTE); // 6 - Pitch - map(Types1_14.METADATA_LIST); // 7 - Metadata + // Spawn Player + protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Type.UUID); // 1 - Player UUID + map(Type.DOUBLE); // 2 - X + map(Type.DOUBLE); // 3 - Y + map(Type.DOUBLE); // 4 - Z + map(Type.BYTE); // 5 - Yaw + map(Type.BYTE); // 6 - Pitch + map(Types1_14.METADATA_LIST); // 7 - Metadata - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); - Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER; + Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER; - // Register Type ID - wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType); - protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); - } - }); - } - }); + // Register Type ID + wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType); + protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); - // Entity Metadata - protocol.registerOutgoing(State.PLAY, 0x43, 0x43, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); // 0 - Entity ID - map(Types1_14.METADATA_LIST); // 1 - Metadata list + // Entity Metadata + protocol.registerOutgoing(State.PLAY, 0x43, 0x43, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + map(Types1_14.METADATA_LIST); // 1 - Metadata list - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int entityId = wrapper.get(Type.VAR_INT, 0); - Optional type = wrapper.user().get(EntityTracker1_14_1.class).getEntity(entityId); - protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); - } - }); - } - }); - } + Optional type = wrapper.user().get(EntityTracker1_14_1.class).getEntity(entityId); + protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java index 922b6e853..32529384a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java @@ -1,12 +1,11 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data; -import com.google.common.base.Optional; - import java.util.HashMap; import java.util.Map; +import java.util.Optional; public class EntityTypeRewriter { - private static Map entityTypes = new HashMap<>(); + private static final Map entityTypes = new HashMap<>(); static { regEnt(6, 7); // cave_spider @@ -105,6 +104,6 @@ public class EntityTypeRewriter { } public static Optional getNewId(int type1_13) { - return Optional.fromNullable(entityTypes.get(type1_13)); + return Optional.ofNullable(entityTypes.get(type1_13)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java index c9ea22ec7..75a35c2cc 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java @@ -1,6 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.Entity1_14Types; @@ -14,14 +13,14 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_13_2; import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; import java.util.LinkedList; import java.util.List; -import java.util.UUID; +import java.util.Optional; public class EntityPackets { @@ -52,7 +51,7 @@ public class EntityPackets { int typeId = wrapper.get(Type.VAR_INT, 1); Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true); - typeId = EntityTypeRewriter.getNewId(type1_13.getId()).or(type1_13.getId()); + typeId = EntityTypeRewriter.getNewId(type1_13.getId()).orElse(type1_13.getId()); Entity1_14Types.EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId); if (type1_14 != null) { @@ -129,7 +128,7 @@ public class EntityPackets { int entityId = wrapper.get(Type.VAR_INT, 0); int type = wrapper.get(Type.VAR_INT, 1); - type = EntityTypeRewriter.getNewId(type).or(type); + type = EntityTypeRewriter.getNewId(type).orElse(type); wrapper.set(Type.VAR_INT, 1, type); Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); @@ -262,7 +261,7 @@ public class EntityPackets { int entityId = wrapper.get(Type.VAR_INT, 0); Optional type = wrapper.user().get(EntityTracker1_14.class).getEntity(entityId); - protocol.get(MetadataRewriter1_14To1_13_2.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + protocol.get(MetadataRewriter1_14To1_13_2.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java index 2f379f060..7cc60f332 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java @@ -1,6 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.entities.Entity1_15Types; import us.myles.ViaVersion.api.protocol.Protocol; @@ -13,6 +12,7 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.MetadataRewriter; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; +import java.util.Optional; import java.util.UUID; public class EntityPackets { @@ -123,7 +123,7 @@ public class EntityPackets { public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); Optional type = wrapper.user().get(EntityTracker1_15.class).getEntity(entityId); - MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + MetadataRewriter.handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/BlockEntity.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/BlockEntity.java index f60345318..01cfeba43 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/BlockEntity.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/BlockEntity.java @@ -1,7 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import lombok.Getter; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -9,13 +8,12 @@ import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; public class BlockEntity { - @Getter - private static final Map types = new ConcurrentHashMap<>(); + private static final Map types = new HashMap<>(); static { types.put("MobSpawner", 1); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/FakeTileEntity.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/FakeTileEntity.java index aefe7cedb..72a688cb8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/FakeTileEntity.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/FakeTileEntity.java @@ -5,16 +5,16 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; /** * Mojang changed the way how tile entities inside chunk packets work in 1.10.1 * It requires now to have all tile entity data included in the chunk packet, otherwise it'll crash. */ public class FakeTileEntity { - private static final Map tileEntities = new ConcurrentHashMap<>(); + private static final Map tileEntities = new HashMap<>(); static { register(Arrays.asList(61, 62), "Furnace"); 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 3d2ef48ab..3c74899fa 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 @@ -1,6 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata; -import com.google.common.base.Optional; import lombok.Getter; import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.entities.Entity1_10Types; @@ -8,6 +7,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_8; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9; import java.util.HashMap; +import java.util.Optional; import static us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType.*; @@ -173,7 +173,7 @@ public enum MetaIndex { private static Optional getIndex(Entity1_10Types.EntityType type, int index) { Pair pair = new Pair<>(type, index); - return Optional.fromNullable(metadataRewrites.get(pair)); + return Optional.ofNullable(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/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index c795d1bfa..586b384cd 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -1,6 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Pair; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java index f24f16835..aa90d0c5b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java @@ -1,6 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.entities.Entity1_10Types; @@ -23,6 +22,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class SpawnPackets { public static final ValueTransformer toNewDouble = new ValueTransformer(Type.DOUBLE) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 35ea94e31..ee56c4847 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; -import com.google.common.base.Optional; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; @@ -28,6 +27,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.Chunk1_9to1_8Type; import java.io.IOException; import java.util.List; +import java.util.Optional; public class WorldPackets { public static void register(Protocol protocol) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/providers/CommandBlockProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/providers/CommandBlockProvider.java index 166d3097a..1dd81abba 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/providers/CommandBlockProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/providers/CommandBlockProvider.java @@ -1,7 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.providers; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.Position; @@ -11,6 +10,8 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.CommandBlockStorage; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; +import java.util.Optional; + public class CommandBlockProvider implements Provider { public void addOrUpdateBlock(UserConnection user, Position position, CompoundTag tag) throws Exception { @@ -23,7 +24,7 @@ public class CommandBlockProvider implements Provider { checkPermission(user); if (isEnabled()) return getStorage(user).getCommandBlock(position); - return Optional.absent(); + return Optional.empty(); } public void unloadChunk(UserConnection user, int x, int z) throws Exception { 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 d6e99db20..161c1e953 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 @@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage; import com.github.steveice10.opennbt.tag.builtin.ByteTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.google.common.base.Optional; import lombok.Getter; import lombok.Setter; import us.myles.ViaVersion.api.Pair; @@ -11,6 +10,7 @@ import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.Position; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; public class CommandBlockStorage extends StoredObject { @@ -55,11 +55,11 @@ public class CommandBlockStorage extends StoredObject { Map blocks = storedCommandBlocks.get(chunkCoords); if (blocks == null) - return Optional.absent(); + return Optional.empty(); CompoundTag tag = blocks.get(position); if (tag == null) - return Optional.absent(); + return Optional.empty(); tag = tag.clone(); tag.put(new ByteTag("powered", (byte) 0)); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java index 6b4dc6285..6a34ac42c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java @@ -11,7 +11,6 @@ import us.myles.ViaVersion.api.boss.BossBar; import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossStyle; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.entities.Entity1_10Types; import us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType; import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.item.Item; @@ -32,7 +31,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @Getter -public class EntityTracker1_9 extends EntityTracker { +public class EntityTracker1_9 extends EntityTracker { private final Map uuidMap = new ConcurrentHashMap<>(); private final Map> metadataBuffer = new ConcurrentHashMap<>(); private final Map vehicleMap = new ConcurrentHashMap<>(); @@ -117,7 +116,7 @@ public class EntityTracker1_9 extends EntityTracker } public void handleMetadata(int entityId, List metadataList) { - EntityType type = getEntity(entityId).orNull(); + EntityType type = getEntity(entityId).orElse(null); if (type == null) { return; } @@ -293,7 +292,7 @@ public class EntityTracker1_9 extends EntityTracker wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, metadataList); getUser().get(ProtocolInfo.class).getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class) - .handleMetadata(entityId, getEntity(entityId).orNull(), metadataList, getUser()); + .handleMetadata(entityId, getEntity(entityId).orElse(null), metadataList, getUser()); handleMetadata(entityId, metadataList); if (!metadataList.isEmpty()) { try {