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
|
||||
public PlatformTask runRepeatingAsync(final Runnable runnable, final long ticks) {
|
||||
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));
|
||||
}
|
||||
|
@ -55,10 +55,7 @@ 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);
|
||||
registerRemoveEntities(ClientboundPackets1_20_3.REMOVE_ENTITIES);
|
||||
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
handler(wrapper -> {
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, wrapper -> {
|
||||
final CompoundTag registryData = wrapper.read(Type.COMPOUND_TAG);
|
||||
cacheDimensionData(wrapper.user(), registryData);
|
||||
trackBiomeSize(wrapper.user(), registryData);
|
||||
@ -69,10 +66,12 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
final ListTag valueTag = entryTag.get("value");
|
||||
RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()];
|
||||
boolean requiresDummyValues = false;
|
||||
int entriesLength = registryEntries.length;
|
||||
for (final Tag tag : valueTag) {
|
||||
final CompoundTag compoundTag = (CompoundTag) tag;
|
||||
final StringTag nameTag = compoundTag.get("name");
|
||||
final int id = ((NumberTag) compoundTag.get("id")).asInt();
|
||||
entriesLength = Math.max(entriesLength, id + 1);
|
||||
if (id >= registryEntries.length) {
|
||||
// It was previously possible to have arbitrary ids
|
||||
registryEntries = Arrays.copyOf(registryEntries, Math.max(registryEntries.length * 2, id + 1));
|
||||
@ -83,7 +82,11 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
}
|
||||
|
||||
if (requiresDummyValues) {
|
||||
fill(registryEntries);
|
||||
// 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);
|
||||
@ -94,8 +97,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
|
||||
wrapper.cancel();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_20_3.JOIN_GAME, new PacketHandlers() {
|
||||
@Override
|
||||
@ -126,17 +127,12 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_20_3.RESPAWN, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
protocol.registerClientbound(ClientboundPackets1_20_3.RESPAWN, wrapper -> {
|
||||
final String dimensionKey = wrapper.read(Type.STRING);
|
||||
final DimensionData data = tracker(wrapper.user()).dimensionData(dimensionKey);
|
||||
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
|
||||
}
|
||||
wrapper.passthrough(Type.STRING); // World
|
||||
worldDataTrackerHandlerByKey1_20_5(0).handle(wrapper); // Tracks world height and name for chunk data and entity (un)tracking
|
||||
});
|
||||
|
||||
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)
|
||||
RegistryEntry first = null;
|
||||
for (final RegistryEntry registryEntry : entries) {
|
||||
|
@ -103,8 +103,11 @@ public class MetaFilter {
|
||||
&& (this.metaType == null || metadata.metaType() == this.metaType);
|
||||
}
|
||||
|
||||
private boolean matchesType(@Nullable EntityType type) {
|
||||
return type != null && (this.filterFamily ? type.isOrHasParent(this.type) : this.type == type);
|
||||
private boolean matchesType(EntityType type) {
|
||||
if (type == null) {
|
||||
return false;
|
||||
}
|
||||
return this.filterFamily ? type.isOrHasParent(this.type) : this.type == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,8 +54,8 @@ public final class TaskScheduler implements Scheduler {
|
||||
scheduledExecutorService.shutdown();
|
||||
|
||||
try {
|
||||
executorService.awaitTermination(2, TimeUnit.SECONDS);
|
||||
scheduledExecutorService.awaitTermination(2, TimeUnit.SECONDS);
|
||||
executorService.awaitTermination(1, TimeUnit.SECONDS);
|
||||
scheduledExecutorService.awaitTermination(1, TimeUnit.SECONDS);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren