3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-25 07:40:08 +01:00

Fix Bungee constant entity ids

Dieser Commit ist enthalten in:
Matsv 2016-11-02 18:07:21 +01:00
Ursprung c896ed5f63
Commit 69e444f83d
5 geänderte Dateien mit 56 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -7,10 +7,12 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.bungee.handlers.BungeeServerHandler;
import us.myles.ViaVersion.bungee.listeners.UpdateListener;
import us.myles.ViaVersion.bungee.providers.BungeeEntityIdProvider;
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider;
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
import us.myles.ViaVersion.protocols.base.VersionProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import java.util.concurrent.TimeUnit;
@ -29,6 +31,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
// Providers
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
if (plugin.getConf().getBungeePingInterval() > 0) {
plugin.getProxy().getScheduler().schedule(plugin, new ProtocolDetectorService(plugin), 0, plugin.getConf().getBungeePingInterval(), TimeUnit.SECONDS);
}

Datei anzeigen

@ -0,0 +1,28 @@
package us.myles.ViaVersion.bungee.providers;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.bungee.storage.BungeeStorage;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
import java.lang.reflect.Method;
public class BungeeEntityIdProvider extends EntityIdProvider {
private static Method getClientEntityId;
static {
try {
getClientEntityId = Class.forName("net.md_5.bungee.UserConnection").getDeclaredMethod("getClientEntityId");
} catch (NoSuchMethodException | ClassNotFoundException e) {
e.printStackTrace();
}
}
@Override
public int getEntityId(UserConnection user) throws Exception {
BungeeStorage storage = user.get(BungeeStorage.class);
ProxiedPlayer player = storage.getPlayer();
return (int) getClientEntityId.invoke(player);
}
}

Datei anzeigen

@ -5,17 +5,15 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Metadata1_8Type;
import us.myles.ViaVersion.api.type.types.version.MetadataList1_8Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.*;
@ -30,10 +28,6 @@ public class Protocol1_9TO1_8 extends Protocol {
return fixJson(line);
}
};
@Deprecated
public static Type<List<Metadata>> METADATA_LIST = new MetadataList1_8Type();
@Deprecated
public static Type<Metadata> METADATA = new Metadata1_8Type();
public static String fixJson(String line) {
if (line == null || line.equalsIgnoreCase("null")) {
@ -101,6 +95,7 @@ public class Protocol1_9TO1_8 extends Protocol {
protected void register(ViaProviders providers) {
providers.register(HandItemProvider.class, new HandItemProvider());
providers.register(BulkChunkTranslatorProvider.class, new BulkChunkTranslatorProvider());
providers.register(EntityIdProvider.class, new EntityIdProvider());
providers.require(MovementTransmitterProvider.class);
if (Via.getConfig().isStimulatePlayerTick()) {
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);

Datei anzeigen

@ -0,0 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.providers;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
public class EntityIdProvider implements Provider {
public int getEntityId(UserConnection user) throws Exception {
return user.get(EntityTracker.class).getEntityID();
}
}

Datei anzeigen

@ -24,6 +24,7 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -44,7 +45,7 @@ public class EntityTracker extends StoredObject {
@Setter
private boolean autoTeam = false;
@Setter
private int entityID;
private int entityID = -1;
@Setter
private Position currentlyDigging = null;
private boolean teamExists = false;
@ -150,7 +151,7 @@ public class EntityTracker extends StoredObject {
if (metadata.getId() == 0) {
// Byte
byte data = (byte) metadata.getValue();
if (entityID != getEntityID() && Via.getConfig().isShieldBlocking()) {
if (entityID != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) {
if ((data & 0x10) == 0x10) {
if (validBlocking.contains(entityID)) {
Item shield = new Item((short) 442, (byte) 1, (short) 0, null);
@ -285,4 +286,12 @@ public class EntityTracker extends StoredObject {
metadataBuffer.remove(entityID);
}
}
public int getProvidedEntityId() {
try {
return Via.getManager().getProviders().get(EntityIdProvider.class).getEntityId(getUser());
} catch (Exception e) {
return entityID;
}
}
}