SteamWar/SpigotCore
Archiviert
13
0

Fix chunk fixer
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-06-23 22:08:58 +02:00
Ursprung c19e3bc2f4
Commit a46fbbbedb

Datei anzeigen

@ -23,9 +23,14 @@ import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaAPI; import com.viaversion.viaversion.api.ViaAPI;
import de.steamwar.core.Core;
import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.core.CraftbukkitWrapper;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
/** /**
* TinyProtocol can't translate BlockEntities during 1.16 to 1.17 conversions du to removed partial chunk update support. This class cancels PartialChunkUpdates for this players and sends them a complete chunk instead. * TinyProtocol can't translate BlockEntities during 1.16 to 1.17 conversions du to removed partial chunk update support. This class cancels PartialChunkUpdates for this players and sends them a complete chunk instead.
* This class can only be loaded on 1.9 to 1.15 with active ViaVersion. * This class can only be loaded on 1.9 to 1.15 with active ViaVersion.
@ -40,16 +45,40 @@ public class PartialChunkFixer {
private final ViaAPI<Player> via = Via.getAPI(); private final ViaAPI<Player> via = Via.getAPI();
private final List<ResendChunk> chunksToResend = new ArrayList<>();
public PartialChunkFixer() { public PartialChunkFixer() {
TinyProtocol.instance.addFilter(mapChunk, this::chunkFilter); TinyProtocol.instance.addFilter(mapChunk, this::chunkFilter);
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
synchronized (chunksToResend) {
for(ResendChunk chunk : chunksToResend) {
CraftbukkitWrapper.impl.sendChunk(chunk.player, chunk.x, chunk.z);
}
chunksToResend.clear();
}
}, 1, 1);
} }
private Object chunkFilter(Player player, Object packet) { private Object chunkFilter(Player player, Object packet) {
if(via.getPlayerVersion(player) >= PROTOCOL1_17 && !fullChunkFlag.get(packet)) { if(via.getPlayerVersion(player) >= PROTOCOL1_17 && !fullChunkFlag.get(packet)) {
// partial chunk update // partial chunk update
CraftbukkitWrapper.impl.sendChunk(player, chunkX.get(packet), chunkZ.get(packet)); synchronized (chunksToResend) {
chunksToResend.add(new ResendChunk(player, chunkX.get(packet), chunkZ.get(packet)));
}
return null; return null;
} }
return packet; return packet;
} }
private static class ResendChunk {
private final Player player;
private final int x;
private final int z;
private ResendChunk(Player player, int x, int z) {
this.player = player;
this.x = x;
this.z = z;
}
}
} }