Merge pull request 'Move ViaVersion to Proxy' (#87) from ViaOnProxy into main

Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/87
Reviewed-by: YoyoNow <jwsteam@nidido.de>
This commit is contained in:
Lixfel
2025-01-03 07:33:45 +01:00
23 changed files with 107 additions and 190 deletions
-2
View File
@@ -26,6 +26,4 @@ dependencies {
compileOnly(project(":SpigotCore:SpigotCore_8", "default"))
compileOnly(libs.nms9)
compileOnly(libs.viaapi)
}
@@ -20,10 +20,8 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import com.viaversion.viaversion.api.Via;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.minecraft.server.v1_9_R2.PacketPlayOutEntity;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@@ -38,7 +36,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
@Override
public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) {
if(type == ChatMessageType.CHAT && Via.getAPI().getPlayerVersion(player.getUniqueId()) >= 759)
if(type == ChatMessageType.CHAT)
type = ChatMessageType.SYSTEM;
player.spigot().sendMessage(type, msg);
@@ -35,7 +35,6 @@ dependencies {
compileOnly(libs.spigotapi)
compileOnly(libs.netty)
compileOnly(libs.authlib)
compileOnly(libs.viaapi)
compileOnly(libs.fastutil)
implementation(libs.anvilgui)
@@ -21,7 +21,6 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import com.viaversion.viaversion.api.Via;
import de.steamwar.sql.internal.Statement;
import io.netty.channel.ChannelFuture;
import org.bukkit.Bukkit;
@@ -99,7 +98,6 @@ class CheckpointUtilsJ9 {
Statement.closeAll();
// Close socket
Via.getManager().getInjector().uninject();
Object serverConnection = TinyProtocol.getServerConnection(Core.getInstance());
List<?> channels = channelFutures.get(serverConnection);
for(Object future : channels) {
@@ -140,7 +138,6 @@ class CheckpointUtilsJ9 {
((ChannelFuture) future).channel().config().setAutoRead(true);
}
}
Via.getManager().getInjector().inject();
Bukkit.getPluginManager().callEvent(new CRIUWakeupEvent());
Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored");
@@ -100,9 +100,6 @@ public class Core extends JavaPlugin{
CheckpointUtils.signalHandler();
new AntiNocom();
if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null)
new PartialChunkFixer();
if(Core.getVersion() >= 19)
new ServerDataHandler();
@@ -1,84 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.core.events;
import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaAPI;
import de.steamwar.core.Core;
import de.steamwar.core.CraftbukkitWrapper;
import org.bukkit.Bukkit;
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.
* This class can only be loaded on 1.9 to 1.15 with active ViaVersion.
**/
public class PartialChunkFixer {
private static final int PROTOCOL1_17 = 755;
private static final Class<?> mapChunk = Reflection.getClass("{nms}.PacketPlayOutMapChunk");
private static final Reflection.FieldAccessor<Boolean> fullChunkFlag = Reflection.getField(mapChunk, boolean.class, 0);
private static final Reflection.FieldAccessor<Integer> chunkX = Reflection.getField(mapChunk, int.class, 0);
private static final Reflection.FieldAccessor<Integer> chunkZ = Reflection.getField(mapChunk, int.class, 1);
private final ViaAPI<Player> via = Via.getAPI();
private final List<ResendChunk> chunksToResend = new ArrayList<>();
public PartialChunkFixer() {
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) {
if(via.getPlayerVersion(player) >= PROTOCOL1_17 && !fullChunkFlag.get(packet)) {
// partial chunk update
synchronized (chunksToResend) {
chunksToResend.add(new ResendChunk(player, chunkX.get(packet), chunkZ.get(packet)));
}
return null;
}
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;
}
}
}
@@ -4,7 +4,6 @@ author: Lixfel
api-version: "1.13"
load: STARTUP
softdepend:
- ViaVersion
- WorldEdit
main: de.steamwar.core.Core