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

Some metadata and entity rewriter cleanup

Dieser Commit ist enthalten in:
KennyTV 2020-06-03 22:48:48 +02:00
Ursprung cf5e5590ad
Commit 004d0d2b23
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
10 geänderte Dateien mit 47 neuen und 137 gelöschten Zeilen

Datei anzeigen

@ -77,19 +77,17 @@ public class MetaHandlerSettings {
return filterFamily; return filterFamily;
} }
/**
* Returns true if the metadata should be handled by this object.
*
* @param type entity type
* @param metadata metadata
* @return true if gucci
*/
public boolean isGucci(EntityType type, Metadata metadata) { public boolean isGucci(EntityType type, Metadata metadata) {
if (!hasHandler()) return false; if (!hasHandler()) return false;
if (hasType() && (filterFamily ? !type.isOrHasParent(filterType) : !filterType.is(type))) {
if (hasType()) { return false;
if (filterFamily) {
if (!type.isOrHasParent(filterType)) {
return false;
}
} else {
if (!filterType.is(type)) {
return false;
}
}
} }
return !hasIndex() || metadata.getId() == filterIndex; return !hasIndex() || metadata.getId() == filterIndex;
} }

Datei anzeigen

@ -18,7 +18,8 @@ public class RemovedValueException extends IOException {
* May be cached since it is never actually printed, only checked. * May be cached since it is never actually printed, only checked.
*/ */
public static final RemovedValueException EX = new RemovedValueException() { public static final RemovedValueException EX = new RemovedValueException() {
public synchronized Throwable fillInStackTrace() { @Override
public Throwable fillInStackTrace() {
return this; return this;
} }
}; };

Datei anzeigen

@ -24,10 +24,12 @@ import us.myles.ViaVersion.packets.State;
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.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
/** /**
* Entity rewriter base class. * Entity rewriter base class.
@ -138,60 +140,52 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
} }
EntityType type = storedEntity.getType(); EntityType type = storedEntity.getType();
List<Metadata> newList = new ArrayList<>();
for (MetaHandlerSettings settings : metaHandlers) { for (MetaHandlerSettings settings : metaHandlers) {
List<Metadata> extraData = null; List<Metadata> newData = new ArrayList<>();
for (Metadata md : storage.getMetaDataList()) { for (Metadata meta : storage.getMetaDataList()) {
Metadata nmd = md;
MetaHandlerEvent event = null; MetaHandlerEvent event = null;
try { try {
if (settings.isGucci(type, nmd)) { Metadata modifiedMeta = meta;
event = new MetaHandlerEvent(user, storedEntity, nmd.getId(), nmd, storage); if (settings.isGucci(type, meta)) {
nmd = settings.getHandler().handle(event); event = new MetaHandlerEvent(user, storedEntity, meta.getId(), meta, storage);
modifiedMeta = settings.getHandler().handle(event);
if (event.getExtraData() != null) { if (event.getExtraData() != null) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).addAll(event.getExtraData()); newData.addAll(event.getExtraData());
event.clearExtraData(); event.clearExtraData();
} }
} }
if (nmd == null) { if (modifiedMeta == null) {
throw RemovedValueException.EX; throw RemovedValueException.EX;
} }
newList.add(nmd); newData.add(modifiedMeta);
} catch (RemovedValueException e) { } catch (RemovedValueException e) {
// add the additionally created data here in case of an interruption // Add the additionally created data here in case of an interruption
if (event != null && event.getExtraData() != null) { if (event != null && event.getExtraData() != null) {
(extraData != null ? extraData : (extraData = new ArrayList<>())).addAll(event.getExtraData()); newData.addAll(event.getExtraData());
} }
} catch (Exception e) { } catch (Exception e) {
Logger log = ViaBackwards.getPlatform().getLogger(); Logger log = ViaBackwards.getPlatform().getLogger();
log.warning("Unable to handle metadata " + nmd); log.warning("Unable to handle metadata " + meta + " for entity type " + type);
log.warning("Full metadata list " + storage); log.warning(storage.getMetaDataList().stream().sorted(Comparator.comparingInt(Metadata::getId))
.map(Metadata::toString).collect(Collectors.joining("\n", "Full metadata list: ", "")));
e.printStackTrace(); e.printStackTrace();
} }
} }
List<Metadata> newData = new ArrayList<>(newList);
if (extraData != null) {
newData.addAll(extraData);
}
storage.setMetaDataList(newData); storage.setMetaDataList(newData);
newList.clear();
} }
// Handle Entity Name // Handle Entity Name
Metadata data = storage.get(displayNameIndex); Metadata data = storage.get(displayNameIndex);
if (data != null) { if (data != null) {
EntityData entityData = getEntityData(type); EntityData entityData = getEntityData(type);
if (entityData != null) { if (entityData != null && entityData.getMobName() != null
if (entityData.getMobName() != null && && (data.getValue() == null || ((String) data.getValue()).isEmpty())
(data.getValue() == null || ((String) data.getValue()).isEmpty()) && && data.getMetaType().getTypeID() == displayNameMetaType.getTypeID()) {
data.getMetaType().getTypeID() == displayNameMetaType.getTypeID()) { data.setValue(entityData.getMobName());
data.setValue(entityData.getMobName());
}
} }
} }

Datei anzeigen

@ -166,26 +166,10 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
registerExtraTracker(0x04, Entity1_11Types.EntityType.PAINTING); registerExtraTracker(0x04, Entity1_11Types.EntityType.PAINTING);
// Join game // Join game
protocol.registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() { registerJoinGame(0x23, 0x23, Entity1_11Types.EntityType.PLAYER);
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(getTrackerHandler(Entity1_11Types.EntityType.PLAYER, Type.INT)); // Respawn Packet
handler(getDimensionHandler(1)); registerRespawn(0x33, 0x33);
}
});
// Respawn Packet (save dimension id)
protocol.registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID
handler(getDimensionHandler(0));
}
});
// Spawn Player // Spawn Player
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {

Datei anzeigen

@ -165,14 +165,8 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
} }
}); });
// Respawn Packet (save dimension id) // Respawn Packet
protocol.registerOutgoing(State.PLAY, 0x34, 0x33, new PacketRemapper() { registerRespawn(0x34, 0x33);
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID
handler(getDimensionHandler(0));
}
});
// Destroy entities // Destroy entities
registerEntityDestroy(0x31, 0x30); registerEntityDestroy(0x31, 0x30);

Datei anzeigen

@ -83,26 +83,10 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter<Protocol1_11To1_11
registerExtraTracker(0x04, Entity1_11Types.EntityType.PAINTING); registerExtraTracker(0x04, Entity1_11Types.EntityType.PAINTING);
// Join game // Join game
protocol.registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() { registerJoinGame(0x23, 0x23, Entity1_11Types.EntityType.PLAYER);
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(getTrackerHandler(Entity1_11Types.EntityType.PLAYER, Type.INT)); // Respawn Packet
handler(getDimensionHandler(1)); registerRespawn(0x33, 0x33);
}
});
// Respawn Packet (save dimension id)
protocol.registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID
handler(getDimensionHandler(0));
}
});
// Spawn Player // Spawn Player
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {

Datei anzeigen

@ -198,19 +198,9 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
}); });
// Join game // Join game
protocol.out(State.PLAY, 0x25, 0x23, new PacketRemapper() { registerJoinGame(0x25, 0x23, Entity1_13Types.EntityType.PLAYER);
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(getTrackerHandler(Entity1_13Types.EntityType.PLAYER, Type.INT)); // Respawn Packet
handler(getDimensionHandler(1));
}
});
// Respawn Packet (save dimension id)
protocol.registerOutgoing(State.PLAY, 0x38, 0x35, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x38, 0x35, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {

Datei anzeigen

@ -126,28 +126,10 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<Protocol1_13To1_13
registerExtraTracker(0x04, Entity1_13Types.EntityType.PAINTING); registerExtraTracker(0x04, Entity1_13Types.EntityType.PAINTING);
// Join Game // Join Game
protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { registerJoinGame(0x25, 0x25, Entity1_13Types.EntityType.PLAYER);
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(getTrackerHandler(Entity1_13Types.EntityType.PLAYER, Type.INT));
handler(getDimensionHandler(1));
}
});
// Respawn // Respawn
protocol.out(State.PLAY, 0x38, 0x38, new PacketRemapper() { registerRespawn(0x38, 0x38);
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID\
// Save dimension
handler(getDimensionHandler(0));
}
});
// Destroy entities // Destroy entities
registerEntityDestroy(0x35); registerEntityDestroy(0x35);

Datei anzeigen

@ -18,7 +18,6 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.Particle;
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_9_3to1_9_1_2.storage.ClientWorld;
import java.util.ArrayList; import java.util.ArrayList;
@ -97,7 +96,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
public void registerMap() { public void registerMap() {
map(Type.INT); map(Type.INT);
map(Type.LONG, Type.NOTHING); // Seed map(Type.LONG, Type.NOTHING); // Seed
handler(wrapper -> wrapper.user().get(ClientWorld.class).setEnvironment(wrapper.get(Type.INT, 0))); handler(getDimensionHandler(0));
} }
}); });

Datei anzeigen

@ -142,26 +142,10 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10>
registerExtraTracker(0x04, Entity1_10Types.EntityType.PAINTING); registerExtraTracker(0x04, Entity1_10Types.EntityType.PAINTING);
// Join game // Join game
protocol.registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() { registerJoinGame(0x23, 0x23, Entity1_10Types.EntityType.PLAYER);
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(getTrackerHandler(Entity1_10Types.EntityType.PLAYER, Type.INT)); // Respawn Packet
handler(getDimensionHandler(1)); registerRespawn(0x33, 0x33);
}
});
// Respawn Packet (save dimension id)
protocol.registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID
handler(getDimensionHandler(0));
}
});
// Spawn Player // Spawn Player
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {