3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Migrate to Java optionals (#1458)

* Add fromEntityType method to 1.13 objecttypes

* Migrate guava optionals to java optionals
Dieser Commit ist enthalten in:
Nassim 2019-09-21 11:57:28 +02:00 committet von Myles
Ursprung 9408946b36
Commit 44a4ffb26a
37 geänderte Dateien mit 214 neuen und 215 gelöschten Zeilen

Datei anzeigen

@ -1,12 +1,12 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
// 1.10 Entity / Object ids // 1.10 Entity / Object ids
public class Entity1_10Types { public class Entity1_10Types {
@ -134,8 +134,8 @@ public class Entity1_10Types {
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called if (id == -1) // Check if this is called
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
} }
@ -181,16 +181,16 @@ public class Entity1_10Types {
public static Optional<ObjectType> findById(int id) { public static Optional<ObjectType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
public static Optional<EntityType> getPCEntity(int id) { public static Optional<EntityType> getPCEntity(int id) {
Optional<ObjectType> output = findById(id); Optional<ObjectType> output = findById(id);
if (!output.isPresent()) if (!output.isPresent())
return Optional.absent(); return Optional.empty();
return Optional.of(output.get().getType()); return Optional.of(output.get().type);
} }
} }
} }

Datei anzeigen

@ -1,12 +1,12 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
// 1.11 Entity / Object ids TODO maybe in the future instead of copying it, some api. // 1.11 Entity / Object ids TODO maybe in the future instead of copying it, some api.
public class Entity1_11Types { public class Entity1_11Types {
@ -162,8 +162,8 @@ public class Entity1_11Types {
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called if (id == -1) // Check if this is called
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
} }
@ -211,16 +211,16 @@ public class Entity1_11Types {
public static Optional<ObjectType> findById(int id) { public static Optional<ObjectType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
public static Optional<EntityType> getPCEntity(int id) { public static Optional<EntityType> getPCEntity(int id) {
Optional<ObjectType> output = findById(id); Optional<ObjectType> output = findById(id);
if (!output.isPresent()) if (!output.isPresent())
return Optional.absent(); return Optional.empty();
return Optional.of(output.get().getType()); return Optional.of(output.get().type);
} }
} }
} }

Datei anzeigen

@ -10,13 +10,13 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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 // 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 { public class Entity1_12Types {
@ -175,8 +175,8 @@ public class Entity1_12Types {
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called if (id == -1) // Check if this is called
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
} }
@ -224,16 +224,16 @@ public class Entity1_12Types {
public static Optional<ObjectType> findById(int id) { public static Optional<ObjectType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
public static Optional<EntityType> getPCEntity(int id) { public static Optional<EntityType> getPCEntity(int id) {
Optional<ObjectType> output = findById(id); Optional<ObjectType> output = findById(id);
if (!output.isPresent()) if (!output.isPresent())
return Optional.absent(); return Optional.empty();
return Optional.of(output.get().getType()); return Optional.of(output.get().type);
} }
} }
} }

Datei anzeigen

@ -1,12 +1,12 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
// TODO auto generate 18w11a with PAaaS // TODO auto generate 18w11a with PAaaS
public class Entity1_13Types { public class Entity1_13Types {
@ -217,8 +217,8 @@ public class Entity1_13Types {
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called if (id == -1) // Check if this is called
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
} }
@ -267,16 +267,22 @@ public class Entity1_13Types {
public static Optional<ObjectType> findById(int id) { public static Optional<ObjectType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
public static Optional<EntityType> getPCEntity(int id) { public static Optional<EntityType> getPCEntity(int id) {
Optional<ObjectType> output = findById(id); Optional<ObjectType> output = findById(id);
if (!output.isPresent()) if (!output.isPresent())
return Optional.absent(); return Optional.empty();
return Optional.of(output.get().getType()); return Optional.of(output.get().type);
}
public static Optional<ObjectType> fromEntityType(EntityType type) {
for (ObjectType ent : ObjectType.values())
if (ent.type == type)
return Optional.of(ent);
return Optional.empty();
} }
} }
} }

Datei anzeigen

@ -1,22 +1,22 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class Entity1_14Types { public class Entity1_14Types {
public static EntityType getTypeFromId(int typeID) { public static EntityType getTypeFromId(int typeID) {
Optional<EntityType> type = Entity1_14Types.EntityType.findById(typeID); Optional<EntityType> type = EntityType.findById(typeID);
if (!type.isPresent()) { if (!type.isPresent()) {
Via.getPlatform().getLogger().severe("Could not find type id " + typeID); 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(); return type.get();
@ -212,15 +212,15 @@ public class Entity1_14Types {
} }
static { static {
for (EntityType type : Entity1_14Types.EntityType.values()) { for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type); TYPES.put(type.id, type);
} }
} }
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
} }
} }

Datei anzeigen

@ -1,12 +1,12 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class Entity1_15Types { public class Entity1_15Types {
@ -219,8 +219,8 @@ public class Entity1_15Types {
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.empty();
return Optional.fromNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
} }
} }

Datei anzeigen

@ -1,20 +1,16 @@
package us.myles.ViaVersion.api.storage; 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.ExternalJoinGameListener;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.entities.EntityType;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public abstract class EntityTracker<T extends EntityType> extends StoredObject implements ExternalJoinGameListener { public abstract class EntityTracker<T extends EntityType> extends StoredObject implements ExternalJoinGameListener {
private final Map<Integer, T> clientEntityTypes = new ConcurrentHashMap<>(); private final Map<Integer, T> clientEntityTypes = new ConcurrentHashMap<>();
@Getter
@Setter
private int clientEntityId; private int clientEntityId;
private final T playerType; private final T playerType;
@ -36,7 +32,7 @@ public abstract class EntityTracker<T extends EntityType> extends StoredObject i
} }
public Optional<T> getEntity(int entityId) { public Optional<T> getEntity(int entityId) {
return Optional.fromNullable(clientEntityTypes.get(entityId)); return Optional.ofNullable(clientEntityTypes.get(entityId));
} }
@Override @Override
@ -44,4 +40,12 @@ public abstract class EntityTracker<T extends EntityType> extends StoredObject i
clientEntityId = playerEntityId; clientEntityId = playerEntityId;
clientEntityTypes.put(playerEntityId, playerType); clientEntityTypes.put(playerEntityId, playerType);
} }
public int getClientEntityId() {
return clientEntityId;
}
public void setClientEntityId(int clientEntityId) {
this.clientEntityId = clientEntityId;
}
} }

Datei anzeigen

@ -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.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; 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.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; 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_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.Optional;
public class Protocol1_11To1_10 extends Protocol { public class Protocol1_11To1_10 extends Protocol {
private static final ValueTransformer<Float, Short> toOldByte = new ValueTransformer<Float, Short>(Type.UNSIGNED_BYTE) { private static final ValueTransformer<Float, Short> toOldByte = new ValueTransformer<Float, Short>(Type.UNSIGNED_BYTE) {
@Override @Override

Datei anzeigen

@ -1,10 +1,8 @@
package us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata; 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.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; 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.entities.Entity1_11Types.EntityType;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; 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.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class MetadataRewriter1_11To1_10 extends MetadataRewriter<Entity1_11Types.EntityType> { public class MetadataRewriter1_11To1_10 extends MetadataRewriter<EntityType> {
@Override @Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) { protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) {
@ -95,9 +94,9 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter<Entity1_11Types
} }
if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) { if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) {
Optional<Metadata> flags = Optional.fromNullable(metadataMap.get(11)); Optional<Metadata> flags = Optional.ofNullable(metadataMap.get(11));
Optional<Metadata> customName = Optional.fromNullable(metadataMap.get(2)); Optional<Metadata> customName = Optional.ofNullable(metadataMap.get(2));
Optional<Metadata> customNameVisible = Optional.fromNullable(metadataMap.get(3)); Optional<Metadata> customNameVisible = Optional.ofNullable(metadataMap.get(3));
if (metadata.getId() == 0 && flags.isPresent() && customName.isPresent() && customNameVisible.isPresent()) { if (metadata.getId() == 0 && flags.isPresent() && customName.isPresent() && customNameVisible.isPresent()) {
Metadata meta = flags.get(); Metadata meta = flags.get();
byte data = (byte) metadata.getValue(); byte data = (byte) metadata.getValue();
@ -212,6 +211,6 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter<Entity1_11Types
for (Metadata metadata : metadatas) { for (Metadata metadata : metadatas) {
if (metadata.getId() == id) return Optional.of(metadata); if (metadata.getId() == id) return Optional.of(metadata);
} }
return Optional.absent(); return Optional.empty();
} }
} }

Datei anzeigen

@ -3,7 +3,6 @@ package us.myles.ViaVersion.protocols.protocol1_12to1_11_1;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.google.common.base.Optional;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
@ -27,6 +26,8 @@ import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import java.util.Optional;
public class Protocol1_12To1_11_1 extends Protocol { public class Protocol1_12To1_11_1 extends Protocol {
@Override @Override

Datei anzeigen

@ -1,19 +1,19 @@
package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets; package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets;
import com.google.common.base.Optional;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.Entity1_13Types;
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
import java.util.Optional;
public class EntityPackets { public class EntityPackets {
public static void register(final Protocol protocol) { public static void register(final Protocol protocol) {
@ -141,8 +141,8 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<EntityType> type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId); Optional<Entity1_13Types.EntityType> 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()); protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
} }
}); });
} }

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/* /*
CHANGED ENTITY NAMES IN 1.13 CHANGED ENTITY NAMES IN 1.13
@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
xp_orb => experience_orb xp_orb => experience_orb
*/ */
public class EntityNameRewriter { public class EntityNameRewriter {
private static Map<String, String> entityNames = new ConcurrentHashMap<>(); private static final Map<String, String> entityNames = new HashMap<>();
static { static {
/* /*

Datei anzeigen

@ -1,13 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; 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.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.Optional;
public class EntityTypeRewriter { public class EntityTypeRewriter {
private static Map<Integer, Integer> entityTypes = new ConcurrentHashMap<>(); private static final Map<Integer, Integer> entityTypes = new HashMap<>();
static { static {
registerEntity(1, 32); // item - ajl registerEntity(1, 32); // item - ajl
@ -94,10 +93,8 @@ public class EntityTypeRewriter {
registerEntity(105, 50); // parrot - agx registerEntity(105, 50); // parrot - agx
registerEntity(120, 79); // villager - ala registerEntity(120, 79); // villager - ala
// OBJECTS // OBJECTS
// Couldn't find any object id change with mapped values // Couldn't find any object id change with mapped values
} }
private static void registerEntity(int type1_12, int type1_13) { private static void registerEntity(int type1_12, int type1_13) {
@ -105,6 +102,6 @@ public class EntityTypeRewriter {
} }
public static Optional<Integer> getNewId(int type1_12) { public static Optional<Integer> getNewId(int type1_12) {
return Optional.fromNullable(entityTypes.get(type1_12)); return Optional.ofNullable(entityTypes.get(type1_12));
} }
} }

Datei anzeigen

@ -5,7 +5,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
public class NamedSoundRewriter { public class NamedSoundRewriter {
private static Map<String, String> oldToNew = new HashMap<>(); private static final Map<String, String> oldToNew = new HashMap<>();
static { static {
// Extracted from Minecraft Wiki // Extracted from Minecraft Wiki
@ -144,7 +144,6 @@ public class NamedSoundRewriter {
oldToNew.put("record.strad", "music_disc.strad"); oldToNew.put("record.strad", "music_disc.strad");
oldToNew.put("record.wait", "music_disc.wait"); oldToNew.put("record.wait", "music_disc.wait");
oldToNew.put("record.ward", "music_disc.ward"); oldToNew.put("record.ward", "music_disc.ward");
} }
public static String getNewId(String old) { public static String getNewId(String old) {

Datei anzeigen

@ -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.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class ParticleRewriter { public class ParticleRewriter {
private static List<NewParticle> particles = new LinkedList<>(); private static final List<NewParticle> particles = new ArrayList<>();
static { static {
add(34); // (0->34) explode -> minecraft:poof add(34); // (0->34) explode -> minecraft:poof

Datei anzeigen

@ -1,9 +1,10 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import com.google.common.base.Optional;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.Optional;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum SoundSource { public enum SoundSource {
@ -23,8 +24,8 @@ public enum SoundSource {
public static Optional<SoundSource> findBySource(String source) { public static Optional<SoundSource> findBySource(String source) {
for (SoundSource item : SoundSource.values()) for (SoundSource item : SoundSource.values())
if (item.getName().equalsIgnoreCase(source)) if (item.name.equalsIgnoreCase(source))
return Optional.of(item); return Optional.of(item);
return Optional.absent(); return Optional.empty();
} }
} }

Datei anzeigen

@ -1,11 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data; 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.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import java.util.Optional;
public class SpawnEggRewriter { public class SpawnEggRewriter {
private final static BiMap<String, Integer> spawnEggs = HashBiMap.create(); private static final BiMap<String, Integer> spawnEggs = HashBiMap.create();
static { static {
// Class yz.java in 18w14b // Class yz.java in 18w14b
@ -70,7 +71,7 @@ public class SpawnEggRewriter {
} }
public static Optional<String> getEntityId(int spawnEggId) { public static Optional<String> getEntityId(int spawnEggId) {
if (spawnEggId >> 16 != 383) return Optional.absent(); if (spawnEggId >> 16 != 383) return Optional.empty();
return Optional.fromNullable(spawnEggs.inverse().get(spawnEggId & 0xFFFF)); return Optional.ofNullable(spawnEggs.inverse().get(spawnEggId & 0xFFFF));
} }
} }

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; 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.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.Entity1_13Types;
import us.myles.ViaVersion.api.protocol.Protocol; 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.metadata.MetadataRewriter1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
import java.util.Optional;
public class EntityPackets { public class EntityPackets {
public static void register(final Protocol protocol) { public static void register(final Protocol protocol) {
// Outgoing packets // Outgoing packets
@ -103,7 +104,7 @@ public class EntityPackets {
int type = wrapper.get(Type.VAR_INT, 1); int type = wrapper.get(Type.VAR_INT, 1);
Optional<Integer> optNewType = EntityTypeRewriter.getNewId(type); Optional<Integer> optNewType = EntityTypeRewriter.getNewId(type);
type = optNewType.or(type); type = optNewType.orElse(type);
Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false); Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false);
wrapper.set(Type.VAR_INT, 1, type); wrapper.set(Type.VAR_INT, 1, type);
@ -172,7 +173,7 @@ public class EntityPackets {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<Entity1_13Types.EntityType> type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId); Optional<Entity1_13Types.EntityType> 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());
} }
}); });
} }

Datei anzeigen

@ -1,14 +1,8 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets;
import com.github.steveice10.opennbt.conversion.ConverterRegistry; import com.github.steveice10.opennbt.conversion.ConverterRegistry;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.*;
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.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -28,6 +22,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
public class InventoryPackets { public class InventoryPackets {
private static String NBT_TAG_NAME; private static String NBT_TAG_NAME;
@ -124,7 +119,7 @@ public class InventoryPackets {
if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().info("Could not handle unknown sound source " + originalSource + " falling back to default: master"); 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);
} }

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; 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.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; 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.HashSet;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
public class WorldPackets { public class WorldPackets {
@ -76,7 +76,7 @@ public class WorldPackets {
if (!id.isPresent() && (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug())) { 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)"); 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));
} }
}); });
} }

Datei anzeigen

@ -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.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.*; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.*;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class BlockEntityProvider implements Provider { public class BlockEntityProvider implements Provider {
private final Map<String, BlockEntityHandler> handlers = new ConcurrentHashMap<>(); private final Map<String, BlockEntityHandler> handlers = new HashMap<>();
public BlockEntityProvider() { public BlockEntityProvider() {
handlers.put("minecraft:flower_pot", new FlowerPotHandler()); handlers.put("minecraft:flower_pot", new FlowerPotHandler());

Datei anzeigen

@ -1,14 +1,14 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers; 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 us.myles.ViaVersion.api.platform.providers.Provider;
import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.Optional;
public class PaintingProvider implements Provider { public class PaintingProvider implements Provider {
private Map<String, Integer> paintings = new ConcurrentHashMap<>(); private final Map<String, Integer> paintings = new HashMap<>();
public PaintingProvider() { public PaintingProvider() {
add("kebab"); add("kebab");
@ -47,6 +47,6 @@ public class PaintingProvider implements Provider {
// Handle older versions // Handle older versions
if (!motive.startsWith("minecraft:")) if (!motive.startsWith("minecraft:"))
motive = "minecraft:" + motive.toLowerCase(Locale.ROOT); motive = "minecraft:" + motive.toLowerCase(Locale.ROOT);
return Optional.fromNullable(paintings.get(motive)); return Optional.ofNullable(paintings.get(motive));
} }
} }

Datei anzeigen

@ -6,12 +6,12 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler { public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler {
private static final Map<Pair<String, Byte>, Integer> flowers = new ConcurrentHashMap<>(); private static final Map<Pair<String, Byte>, Integer> flowers = new HashMap<>();
private static final Map<Pair<Byte, Byte>, Integer> flowersNumberId = new ConcurrentHashMap<>(); private static final Map<Pair<Byte, Byte>, Integer> flowersNumberId = new HashMap<>();
static { static {
register("minecraft:air", (byte) 0, (byte) 0, 5265); register("minecraft:air", (byte) 0, (byte) 0, 5265);

Datei anzeigen

@ -1,19 +1,19 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
import com.google.common.collect.Sets;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class BlockStorage extends StoredObject { public class BlockStorage extends StoredObject {
// This BlockStorage is very exclusive (; private static final Set<Integer> whitelist = new HashSet<>();
private static final Set<Integer> whitelist = Sets.newConcurrentHashSet(); private final Map<Position, ReplacementData> blocks = new ConcurrentHashMap<>();
static { static {
// Flower pots // Flower pots
@ -37,8 +37,6 @@ public class BlockStorage extends StoredObject {
whitelist.add(5447 + i); whitelist.add(5447 + i);
} }
private Map<Position, ReplacementData> blocks = new ConcurrentHashMap<>();
public BlockStorage(UserConnection user) { public BlockStorage(UserConnection user) {
super(user); super(user);
} }

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets; 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.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_14Types; import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
@ -12,6 +11,8 @@ 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.metadata.MetadataRewriter1_14_1To1_14;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
import java.util.Optional;
public class EntityPackets { public class EntityPackets {
public static void register(final Protocol protocol) { public static void register(final Protocol protocol) {
@ -92,7 +93,7 @@ public class EntityPackets {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker1_14_1.class).getEntity(entityId); Optional<Entity1_14Types.EntityType> 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()); protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
} }
}); });
} }

Datei anzeigen

@ -1,12 +1,11 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data; package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data;
import com.google.common.base.Optional;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class EntityTypeRewriter { public class EntityTypeRewriter {
private static Map<Integer, Integer> entityTypes = new HashMap<>(); private static final Map<Integer, Integer> entityTypes = new HashMap<>();
static { static {
regEnt(6, 7); // cave_spider regEnt(6, 7); // cave_spider
@ -105,6 +104,6 @@ public class EntityTypeRewriter {
} }
public static Optional<Integer> getNewId(int type1_13) { public static Optional<Integer> getNewId(int type1_13) {
return Optional.fromNullable(entityTypes.get(type1_13)); return Optional.ofNullable(entityTypes.get(type1_13));
} }
} }

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; 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.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.Entity1_13Types;
import us.myles.ViaVersion.api.entities.Entity1_14Types; 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_13_2;
import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State; 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.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter; 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 us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.Optional;
public class EntityPackets { public class EntityPackets {
@ -52,7 +51,7 @@ public class EntityPackets {
int typeId = wrapper.get(Type.VAR_INT, 1); int typeId = wrapper.get(Type.VAR_INT, 1);
Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true); 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); Entity1_14Types.EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId);
if (type1_14 != null) { if (type1_14 != null) {
@ -129,7 +128,7 @@ public class EntityPackets {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1); 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); wrapper.set(Type.VAR_INT, 1, type);
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type);
@ -262,7 +261,7 @@ public class EntityPackets {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker1_14.class).getEntity(entityId); Optional<Entity1_14Types.EntityType> 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());
} }
}); });
} }

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets; 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.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_15Types; import us.myles.ViaVersion.api.entities.Entity1_15Types;
import us.myles.ViaVersion.api.protocol.Protocol; 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.Protocol1_15To1_14_4;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class EntityPackets { public class EntityPackets {
@ -123,7 +123,7 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<Entity1_15Types.EntityType> type = wrapper.user().get(EntityTracker1_15.class).getEntity(entityId); Optional<Entity1_15Types.EntityType> 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());
} }
}); });
} }

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks; package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.Getter;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; 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.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4; 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.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class BlockEntity { public class BlockEntity {
@Getter private static final Map<String, Integer> types = new HashMap<>();
private static final Map<String, Integer> types = new ConcurrentHashMap<>();
static { static {
types.put("MobSpawner", 1); types.put("MobSpawner", 1);

Datei anzeigen

@ -5,16 +5,16 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* Mojang changed the way how tile entities inside chunk packets work in 1.10.1 * 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. * It requires now to have all tile entity data included in the chunk packet, otherwise it'll crash.
*/ */
public class FakeTileEntity { public class FakeTileEntity {
private static final Map<Integer, CompoundTag> tileEntities = new ConcurrentHashMap<>(); private static final Map<Integer, CompoundTag> tileEntities = new HashMap<>();
static { static {
register(Arrays.asList(61, 62), "Furnace"); register(Arrays.asList(61, 62), "Furnace");

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata; package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import com.google.common.base.Optional;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.entities.Entity1_10Types; 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 us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
import java.util.HashMap; import java.util.HashMap;
import java.util.Optional;
import static us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType.*; import static us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType.*;
@ -173,7 +173,7 @@ public enum MetaIndex {
private static Optional<MetaIndex> getIndex(Entity1_10Types.EntityType type, int index) { private static Optional<MetaIndex> getIndex(Entity1_10Types.EntityType type, int index) {
Pair pair = new Pair<>(type, 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) { public static MetaIndex searchIndex(Entity1_10Types.EntityType type, int index) {

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; 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.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.entities.Entity1_10Types; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
public class SpawnPackets { public class SpawnPackets {
public static final ValueTransformer<Integer, Double> toNewDouble = new ValueTransformer<Integer, Double>(Type.DOUBLE) { public static final ValueTransformer<Integer, Double> toNewDouble = new ValueTransformer<Integer, Double>(Type.DOUBLE) {

Datei anzeigen

@ -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.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.google.common.base.Optional;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; 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.io.IOException;
import java.util.List; import java.util.List;
import java.util.Optional;
public class WorldPackets { public class WorldPackets {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.providers; package us.myles.ViaVersion.protocols.protocol1_9to1_8.providers;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; 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.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; 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.CommandBlockStorage;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import java.util.Optional;
public class CommandBlockProvider implements Provider { public class CommandBlockProvider implements Provider {
public void addOrUpdateBlock(UserConnection user, Position position, CompoundTag tag) throws Exception { public void addOrUpdateBlock(UserConnection user, Position position, CompoundTag tag) throws Exception {
@ -23,7 +24,7 @@ public class CommandBlockProvider implements Provider {
checkPermission(user); checkPermission(user);
if (isEnabled()) if (isEnabled())
return getStorage(user).getCommandBlock(position); return getStorage(user).getCommandBlock(position);
return Optional.absent(); return Optional.empty();
} }
public void unloadChunk(UserConnection user, int x, int z) throws Exception { public void unloadChunk(UserConnection user, int x, int z) throws Exception {

Datei anzeigen

@ -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.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.common.base.Optional;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import us.myles.ViaVersion.api.Pair; 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 us.myles.ViaVersion.api.minecraft.Position;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class CommandBlockStorage extends StoredObject { public class CommandBlockStorage extends StoredObject {
@ -55,11 +55,11 @@ public class CommandBlockStorage extends StoredObject {
Map<Position, CompoundTag> blocks = storedCommandBlocks.get(chunkCoords); Map<Position, CompoundTag> blocks = storedCommandBlocks.get(chunkCoords);
if (blocks == null) if (blocks == null)
return Optional.absent(); return Optional.empty();
CompoundTag tag = blocks.get(position); CompoundTag tag = blocks.get(position);
if (tag == null) if (tag == null)
return Optional.absent(); return Optional.empty();
tag = tag.clone(); tag = tag.clone();
tag.put(new ByteTag("powered", (byte) 0)); tag.put(new ByteTag("powered", (byte) 0));

Datei anzeigen

@ -11,7 +11,6 @@ import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle; import us.myles.ViaVersion.api.boss.BossStyle;
import us.myles.ViaVersion.api.data.UserConnection; 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.entities.Entity1_10Types.EntityType;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -32,7 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Getter @Getter
public class EntityTracker1_9 extends EntityTracker<Entity1_10Types.EntityType> { public class EntityTracker1_9 extends EntityTracker<EntityType> {
private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>(); private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>();
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>(); private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
private final Map<Integer, Integer> vehicleMap = new ConcurrentHashMap<>(); private final Map<Integer, Integer> vehicleMap = new ConcurrentHashMap<>();
@ -117,7 +116,7 @@ public class EntityTracker1_9 extends EntityTracker<Entity1_10Types.EntityType>
} }
public void handleMetadata(int entityId, List<Metadata> metadataList) { public void handleMetadata(int entityId, List<Metadata> metadataList) {
EntityType type = getEntity(entityId).orNull(); EntityType type = getEntity(entityId).orElse(null);
if (type == null) { if (type == null) {
return; return;
} }
@ -293,7 +292,7 @@ public class EntityTracker1_9 extends EntityTracker<Entity1_10Types.EntityType>
wrapper.write(Type.VAR_INT, entityId); wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Types1_9.METADATA_LIST, metadataList); wrapper.write(Types1_9.METADATA_LIST, metadataList);
getUser().get(ProtocolInfo.class).getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class) 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); handleMetadata(entityId, metadataList);
if (!metadataList.isEmpty()) { if (!metadataList.isEmpty()) {
try { try {