Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Merge pull request #1303 from KennyTV/master
Some minor optimization
Dieser Commit ist enthalten in:
Commit
da7a57026d
@ -67,9 +67,10 @@ public class PlayerSneakListener extends ViaBukkitListener {
|
||||
Player player = event.getPlayer();
|
||||
UserConnection userConnection = getUserConnection(player);
|
||||
if (userConnection == null) return;
|
||||
if (!userConnection.has(ProtocolInfo.class)) return;
|
||||
ProtocolInfo info = userConnection.get(ProtocolInfo.class);
|
||||
if (info == null) return;
|
||||
|
||||
int protocolVersion = userConnection.get(ProtocolInfo.class).getProtocolVersion();
|
||||
int protocolVersion = info.getProtocolVersion();
|
||||
if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
|
||||
setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT);
|
||||
if (!useCache) return;
|
||||
|
@ -9,6 +9,7 @@ import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
@ -38,8 +39,9 @@ public class DeathListener extends ViaBukkitListener {
|
||||
@Override
|
||||
public void run() {
|
||||
// If online
|
||||
if (getUserConnection(p) != null) {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
|
||||
UserConnection userConnection = getUserConnection(p);
|
||||
if (userConnection != null) {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x2C, null, userConnection);
|
||||
try {
|
||||
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
|
||||
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID
|
||||
|
@ -1,6 +1,7 @@
|
||||
package us.myles.ViaVersion.bukkit.platform;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -116,8 +117,9 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
@Override
|
||||
public Item call() throws Exception {
|
||||
UUID playerUUID = info.get(ProtocolInfo.class).getUuid();
|
||||
if (Bukkit.getPlayer(playerUUID) != null) {
|
||||
return HandItemCache.convert(Bukkit.getPlayer(playerUUID).getItemInHand());
|
||||
Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player != null) {
|
||||
return HandItemCache.convert(player.getItemInHand());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// 1.10 Entity / Object ids
|
||||
public class Entity1_10Types {
|
||||
|
||||
@ -113,6 +116,8 @@ public class Entity1_10Types {
|
||||
PLAYER(-1, ENTITY_HUMAN),
|
||||
COMPLEX_PART(-1, ENTITY);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
@ -121,15 +126,16 @@ public class Entity1_10Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,18 +168,21 @@ public class Entity1_10Types {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType type;
|
||||
|
||||
static {
|
||||
for (ObjectTypes type : ObjectTypes.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<ObjectTypes> findById(int id) {
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (ObjectTypes ent : ObjectTypes.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
|
@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// 1.11 Entity / Object ids TODO maybe in the future instead of copying it, some api.
|
||||
public class Entity1_11Types {
|
||||
public static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||
@ -140,6 +143,8 @@ public class Entity1_11Types {
|
||||
COMPLEX_PART(-1, ENTITY),
|
||||
LIAMA_SPIT(-1, ENTITY);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
@ -148,15 +153,16 @@ public class Entity1_11Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public boolean is(EntityType... types) {
|
||||
@ -215,18 +221,21 @@ public class Entity1_11Types {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType type;
|
||||
|
||||
static {
|
||||
for (ObjectTypes type : ObjectTypes.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<ObjectTypes> findById(int id) {
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (ObjectTypes ent : ObjectTypes.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
|
@ -15,6 +15,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// 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 static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||
@ -153,6 +156,8 @@ public class Entity1_12Types {
|
||||
COMPLEX_PART(-1, ENTITY),
|
||||
LIAMA_SPIT(-1, ENTITY);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
@ -161,15 +166,16 @@ public class Entity1_12Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public boolean is(EntityType... types) {
|
||||
@ -228,18 +234,21 @@ public class Entity1_12Types {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType type;
|
||||
|
||||
static {
|
||||
for (ObjectTypes type : ObjectTypes.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<ObjectTypes> findById(int id) {
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (ObjectTypes ent : ObjectTypes.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
|
@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
// TODO auto generate 18w11a with PAaaS
|
||||
public class Entity1_13Types {
|
||||
@ -196,6 +199,7 @@ public class Entity1_13Types {
|
||||
SPAWNER_MINECART(44, MINECART_ABSTRACT), // amb
|
||||
BOAT(5, ENTITY); // alv
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
@ -205,15 +209,16 @@ public class Entity1_13Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public boolean is(EntityType... types) {
|
||||
@ -273,18 +278,21 @@ public class Entity1_13Types {
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL),
|
||||
TRIDENT(94, EntityType.TRIDENT);
|
||||
|
||||
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType type;
|
||||
|
||||
static {
|
||||
for (ObjectTypes type : ObjectTypes.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<ObjectTypes> findById(int id) {
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (ObjectTypes ent : ObjectTypes.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
|
@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class Entity1_14Types {
|
||||
public static EntityType getTypeFromId(int typeID) {
|
||||
@ -196,6 +199,8 @@ public class Entity1_14Types {
|
||||
BOAT(5, ENTITY),
|
||||
;
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
@ -204,15 +209,16 @@ public class Entity1_14Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public boolean is(EntityType... types) {
|
||||
|
@ -4,6 +4,7 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@ -31,7 +32,7 @@ public enum ArmorType {
|
||||
GOLD_BOOTS(1, 317, "minecraft:gold_boots"),
|
||||
NONE(0, 0, "none");
|
||||
|
||||
private static HashMap<Integer, ArmorType> armor;
|
||||
private static Map<Integer, ArmorType> armor;
|
||||
|
||||
static {
|
||||
armor = new HashMap<>();
|
||||
@ -51,10 +52,8 @@ public enum ArmorType {
|
||||
* @return Return the ArmourType, ArmourType.NONE if not found
|
||||
*/
|
||||
public static ArmorType findById(int id) {
|
||||
for (ArmorType a : ArmorType.values())
|
||||
if (a.getId() == id)
|
||||
return a;
|
||||
return ArmorType.NONE;
|
||||
ArmorType type = armor.get(id);
|
||||
return type == null ? ArmorType.NONE : type;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,10 +76,7 @@ public enum ArmorType {
|
||||
* @return True if the item is a piece of armour
|
||||
*/
|
||||
public static boolean isArmor(int id) {
|
||||
for (ArmorType a : ArmorType.values())
|
||||
if (a.getId() == id)
|
||||
return true;
|
||||
return false;
|
||||
return armor.containsKey(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,8 @@ public class ViaIdleThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection info : Via.getManager().getPortedPlayers().values()) {
|
||||
if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||
ProtocolInfo protocolInfo = info.get(ProtocolInfo.class);
|
||||
if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||
long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
|
||||
if (nextIdleUpdate <= System.currentTimeMillis()) {
|
||||
if (info.getChannel().isOpen()) {
|
||||
|
@ -1,10 +1,11 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Effect {
|
||||
|
||||
private final static HashMap<Integer, Integer> effects;
|
||||
private static final Map<Integer, Integer> effects;
|
||||
|
||||
static {
|
||||
effects = new HashMap<>();
|
||||
@ -29,9 +30,8 @@ public class Effect {
|
||||
}
|
||||
|
||||
public static int getNewId(int id) {
|
||||
if (!contains(id))
|
||||
return id;
|
||||
return effects.get(id);
|
||||
Integer newId = effects.get(id);
|
||||
return newId != null ? newId : id;
|
||||
}
|
||||
|
||||
public static boolean contains(int oldId) {
|
||||
|
@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public enum SoundEffect {
|
||||
@ -259,7 +260,7 @@ public enum SoundEffect {
|
||||
private final SoundCategory category;
|
||||
private final boolean breaksound;
|
||||
|
||||
private static HashMap<String, SoundEffect> effects;
|
||||
private static Map<String, SoundEffect> effects;
|
||||
|
||||
static {
|
||||
effects = new HashMap<>();
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren