Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Resize registry data array to actual size once collected
Dieser Commit ist enthalten in:
Ursprung
c8d339ab30
Commit
a5bd8abe93
@ -162,7 +162,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
|||||||
@Override
|
@Override
|
||||||
public PlatformTask runRepeatingAsync(final Runnable runnable, final long ticks) {
|
public PlatformTask runRepeatingAsync(final Runnable runnable, final long ticks) {
|
||||||
if (FOLIA) {
|
if (FOLIA) {
|
||||||
return new BukkitViaTaskTask(Via.getManager().getScheduler().schedule(runnable, ticks * 50, TimeUnit.MILLISECONDS));
|
return new BukkitViaTaskTask(Via.getManager().getScheduler().scheduleRepeating(runnable, 0, ticks * 50, TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
return new BukkitViaTask(getServer().getScheduler().runTaskTimerAsynchronously(this, runnable, 0, ticks));
|
return new BukkitViaTask(getServer().getScheduler().runTaskTimerAsynchronously(this, runnable, 0, ticks));
|
||||||
}
|
}
|
||||||
|
@ -55,46 +55,47 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
registerMetadataRewriter(ClientboundPackets1_20_3.ENTITY_METADATA, Types1_20_3.METADATA_LIST, Types1_20_5.METADATA_LIST);
|
registerMetadataRewriter(ClientboundPackets1_20_3.ENTITY_METADATA, Types1_20_3.METADATA_LIST, Types1_20_5.METADATA_LIST);
|
||||||
registerRemoveEntities(ClientboundPackets1_20_3.REMOVE_ENTITIES);
|
registerRemoveEntities(ClientboundPackets1_20_3.REMOVE_ENTITIES);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, wrapper -> {
|
||||||
@Override
|
final CompoundTag registryData = wrapper.read(Type.COMPOUND_TAG);
|
||||||
protected void register() {
|
cacheDimensionData(wrapper.user(), registryData);
|
||||||
handler(wrapper -> {
|
trackBiomeSize(wrapper.user(), registryData);
|
||||||
final CompoundTag registryData = wrapper.read(Type.COMPOUND_TAG);
|
|
||||||
cacheDimensionData(wrapper.user(), registryData);
|
|
||||||
trackBiomeSize(wrapper.user(), registryData);
|
|
||||||
|
|
||||||
for (final Map.Entry<String, Tag> entry : registryData.entrySet()) {
|
for (final Map.Entry<String, Tag> entry : registryData.entrySet()) {
|
||||||
final CompoundTag entryTag = (CompoundTag) entry.getValue();
|
final CompoundTag entryTag = (CompoundTag) entry.getValue();
|
||||||
final StringTag typeTag = entryTag.get("type");
|
final StringTag typeTag = entryTag.get("type");
|
||||||
final ListTag valueTag = entryTag.get("value");
|
final ListTag valueTag = entryTag.get("value");
|
||||||
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
|
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
|
||||||
boolean requiresDummyValues = false;
|
boolean requiresDummyValues = false;
|
||||||
for (final Tag tag : valueTag) {
|
int entriesLength = registryEntries.length;
|
||||||
final CompoundTag compoundTag = (CompoundTag) tag;
|
for (final Tag tag : valueTag) {
|
||||||
final StringTag nameTag = compoundTag.get("name");
|
final CompoundTag compoundTag = (CompoundTag) tag;
|
||||||
final int id = ((NumberTag) compoundTag.get("id")).asInt();
|
final StringTag nameTag = compoundTag.get("name");
|
||||||
if (id >= registryEntries.length) {
|
final int id = ((NumberTag) compoundTag.get("id")).asInt();
|
||||||
// It was previously possible to have arbitrary ids
|
entriesLength = Math.max(entriesLength, id + 1);
|
||||||
registryEntries = Arrays.copyOf(registryEntries, Math.max(registryEntries.length * 2, id + 1));
|
if (id >= registryEntries.length) {
|
||||||
requiresDummyValues = true;
|
// It was previously possible to have arbitrary ids
|
||||||
}
|
registryEntries = Arrays.copyOf(registryEntries, Math.max(registryEntries.length * 2, id + 1));
|
||||||
|
requiresDummyValues = true;
|
||||||
registryEntries[id] = new RegistryEntry(nameTag.getValue(), compoundTag.get("element"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requiresDummyValues) {
|
|
||||||
fill(registryEntries);
|
|
||||||
}
|
|
||||||
|
|
||||||
final PacketWrapper registryPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
|
|
||||||
registryPacket.write(Type.STRING, typeTag.getValue());
|
|
||||||
registryPacket.write(Type.REGISTRY_ENTRY_ARRAY, registryEntries);
|
|
||||||
registryPacket.send(Protocol1_20_5To1_20_3.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.cancel();
|
registryEntries[id] = new RegistryEntry(nameTag.getValue(), compoundTag.get("element"));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (requiresDummyValues) {
|
||||||
|
// Truncate and replace null values
|
||||||
|
if (registryEntries.length != entriesLength) {
|
||||||
|
registryEntries = Arrays.copyOf(registryEntries, entriesLength);
|
||||||
|
}
|
||||||
|
replaceNullValues(registryEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
final PacketWrapper registryPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
|
||||||
|
registryPacket.write(Type.STRING, typeTag.getValue());
|
||||||
|
registryPacket.write(Type.REGISTRY_ENTRY_ARRAY, registryEntries);
|
||||||
|
registryPacket.send(Protocol1_20_5To1_20_3.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wrapper.cancel();
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_3.JOIN_GAME, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundPackets1_20_3.JOIN_GAME, new PacketHandlers() {
|
||||||
@ -126,17 +127,12 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_3.RESPAWN, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundPackets1_20_3.RESPAWN, wrapper -> {
|
||||||
@Override
|
final String dimensionKey = wrapper.read(Type.STRING);
|
||||||
public void register() {
|
final DimensionData data = tracker(wrapper.user()).dimensionData(dimensionKey);
|
||||||
handler(wrapper -> {
|
wrapper.write(Type.VAR_INT, data.id());
|
||||||
final String dimensionKey = wrapper.read(Type.STRING);
|
wrapper.passthrough(Type.STRING); // World
|
||||||
final DimensionData data = tracker(wrapper.user()).dimensionData(dimensionKey);
|
worldDataTrackerHandlerByKey1_20_5(0).handle(wrapper); // Tracks world height and name for chunk data and entity (un)tracking
|
||||||
wrapper.write(Type.VAR_INT, data.id());
|
|
||||||
});
|
|
||||||
map(Type.STRING); // World
|
|
||||||
handler(worldDataTrackerHandlerByKey1_20_5(0)); // Tracks world height and name for chunk data and entity (un)tracking
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_3.ENTITY_EFFECT, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_20_3.ENTITY_EFFECT, wrapper -> {
|
||||||
@ -169,7 +165,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fill(final RegistryEntry[] entries) {
|
private void replaceNullValues(final RegistryEntry[] entries) {
|
||||||
// Find the first non-null entry and fill the array with dummy values where needed (which is easier than remapping them to different ids in a new, smaller array)
|
// Find the first non-null entry and fill the array with dummy values where needed (which is easier than remapping them to different ids in a new, smaller array)
|
||||||
RegistryEntry first = null;
|
RegistryEntry first = null;
|
||||||
for (final RegistryEntry registryEntry : entries) {
|
for (final RegistryEntry registryEntry : entries) {
|
||||||
|
@ -103,8 +103,11 @@ public class MetaFilter {
|
|||||||
&& (this.metaType == null || metadata.metaType() == this.metaType);
|
&& (this.metaType == null || metadata.metaType() == this.metaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchesType(@Nullable EntityType type) {
|
private boolean matchesType(EntityType type) {
|
||||||
return type != null && (this.filterFamily ? type.isOrHasParent(this.type) : this.type == type);
|
if (type == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.filterFamily ? type.isOrHasParent(this.type) : this.type == type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,8 +54,8 @@ public final class TaskScheduler implements Scheduler {
|
|||||||
scheduledExecutorService.shutdown();
|
scheduledExecutorService.shutdown();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
executorService.awaitTermination(2, TimeUnit.SECONDS);
|
executorService.awaitTermination(1, TimeUnit.SECONDS);
|
||||||
scheduledExecutorService.awaitTermination(2, TimeUnit.SECONDS);
|
scheduledExecutorService.awaitTermination(1, TimeUnit.SECONDS);
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren