SteamWar/SpigotCore
Archiviert
13
0

Merge remote-tracking branch 'origin/master'
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-07-01 21:02:14 +02:00
Commit 5f1d760465
10 geänderte Dateien mit 138 neuen und 42 gelöschten Zeilen

@ -1 +1 @@
Subproject commit 6879d3cc2a08c19ca62aae32fbeb3c1e1813cea4 Subproject commit 21e77c55f023261d3a63d5c6200d28b2f6f6fc4c

Datei anzeigen

@ -47,6 +47,7 @@ dependencies {
compileOnly 'io.netty:netty-all:4.1.68.Final' compileOnly 'io.netty:netty-all:4.1.68.Final'
compileOnly 'com.mojang:authlib:1.5.25' compileOnly 'com.mojang:authlib:1.5.25'
compileOnly 'mysql:mysql-connector-java:5.1.49' compileOnly 'mysql:mysql-connector-java:5.1.49'
compileOnly 'com.viaversion:viaversion-api:4.3.1'
compileOnly files("${project.rootDir}/lib/WorldEdit-1.12.jar") compileOnly files("${project.rootDir}/lib/WorldEdit-1.12.jar")
implementation 'net.wesjd:anvilgui:1.5.3-SNAPSHOT' implementation 'net.wesjd:anvilgui:1.5.3-SNAPSHOT'

Datei anzeigen

@ -20,6 +20,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
@ -71,7 +72,12 @@ public class TinyProtocol {
private volatile boolean closed; private volatile boolean closed;
private final Plugin plugin; private final Plugin plugin;
private final Map<Class<?>, List<BiFunction<Player, Object, Object>>> packetFilters = new HashMap<>();
@Deprecated
private PacketFilter inFilter = (player, channel, packet) -> packet; private PacketFilter inFilter = (player, channel, packet) -> packet;
@Deprecated
private PacketFilter outFilter = (player, channel, packet) -> packet; private PacketFilter outFilter = (player, channel, packet) -> packet;
public static final TinyProtocol instance = new TinyProtocol(Core.getInstance()); public static final TinyProtocol instance = new TinyProtocol(Core.getInstance());
@ -245,18 +251,41 @@ public class TinyProtocol {
} }
} }
public void addFilter(Class<?> packetType, BiFunction<Player, Object, Object> filter) {
packetFilters.computeIfAbsent(packetType, c -> new ArrayList<>(1)).add(filter);
}
public void removeFilter(Class<?> packetType, BiFunction<Player, Object, Object> filter) {
packetFilters.getOrDefault(packetType, Collections.emptyList()).remove(filter);
}
public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) { public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) {
return outFilter.onPacket(receiver, channel, packet); return filterPacket(outFilter, receiver, channel, packet);
} }
public Object onPacketInAsync(Player sender, Channel channel, Object packet) { public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
return inFilter.onPacket(sender, channel, packet); return filterPacket(inFilter, sender, channel, packet);
} }
private Object filterPacket(PacketFilter handler, Player player, Channel channel, Object packet) {
List<BiFunction<Player, Object, Object>> filters = packetFilters.getOrDefault(packet.getClass(), Collections.emptyList());
for(BiFunction<Player, Object, Object> filter : filters) {
packet = filter.apply(player, packet);
if(packet == null)
return packet;
}
return handler.onPacket(player, channel, packet);
}
@Deprecated
public void setInFilter(PacketFilter filter) { public void setInFilter(PacketFilter filter) {
inFilter = filter; inFilter = filter;
} }
@Deprecated
public void setOutFilter(PacketFilter filter) { public void setOutFilter(PacketFilter filter) {
outFilter = filter; outFilter = filter;
} }
@ -363,6 +392,7 @@ public class TinyProtocol {
} }
} }
@Deprecated
public interface PacketFilter { public interface PacketFilter {
Object onPacket(Player player, Channel channel, Object packet); Object onPacket(Player player, Channel channel, Object packet);
} }

Datei anzeigen

@ -22,9 +22,11 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.SWTypeMapperCreator; import de.steamwar.command.SWTypeMapperCreator;
import de.steamwar.command.TabCompletionCache;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import de.steamwar.core.authlib.AuthlibInjector; import de.steamwar.core.authlib.AuthlibInjector;
import de.steamwar.core.events.ChattingEvent; import de.steamwar.core.events.ChattingEvent;
import de.steamwar.core.events.PartialChunkFixer;
import de.steamwar.core.events.PlayerJoinedEvent; import de.steamwar.core.events.PlayerJoinedEvent;
import de.steamwar.core.events.WorldLoadEvent; import de.steamwar.core.events.WorldLoadEvent;
import de.steamwar.message.Message; import de.steamwar.message.Message;
@ -111,6 +113,7 @@ public class Core extends JavaPlugin{
return tabCompleter.apply(sender, s); return tabCompleter.apply(sender, s);
} }
}); });
Bukkit.getScheduler().runTaskTimer(this, TabCompletionCache::invalidateOldEntries, 20, 20);
setSqlConfig(); setSqlConfig();
errorHandler = new ErrorHandler(); errorHandler = new ErrorHandler();
@ -125,6 +128,10 @@ public class Core extends JavaPlugin{
if(Core.getVersion() < 19) if(Core.getVersion() < 19)
AuthlibInjector.inject(); AuthlibInjector.inject();
TinyProtocol.init(); TinyProtocol.init();
if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null)
new PartialChunkFixer();
try { try {
getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine()); getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine());
} catch (IOException e) { } catch (IOException e) {

Datei anzeigen

@ -144,6 +144,8 @@ public class ErrorHandler extends Handler {
startsWith.add("This version of Minecraft is extremely outdated"); startsWith.add("This version of Minecraft is extremely outdated");
startsWith.add("Custom worlds heights are NOT SUPPORTED for 1.16 players and older"); startsWith.add("Custom worlds heights are NOT SUPPORTED for 1.16 players and older");
startsWith.add("You have min/max set to -64/384"); startsWith.add("You have min/max set to -64/384");
startsWith.add("You have min/max set to -64/256");
startsWith.add("Biome with id");
ignoreStartsWith = Collections.unmodifiableList(startsWith); ignoreStartsWith = Collections.unmodifiableList(startsWith);
List<String> contains = new ArrayList<>(); List<String> contains = new ArrayList<>();

Datei anzeigen

@ -1,33 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 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 de.steamwar.core.CraftbukkitWrapper;
import org.bukkit.entity.Player;
@Deprecated
public class ChunkListener {
private ChunkListener(){}
@Deprecated
public static void sendChunk(Player p, int chunkX, int chunkZ) {
CraftbukkitWrapper.impl.sendChunk(p, chunkX, chunkZ);
}
}

Datei anzeigen

@ -0,0 +1,84 @@
/*
* 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;
}
}
}

Datei anzeigen

@ -28,28 +28,28 @@ import de.steamwar.network.packets.client.InventoryCallbackPacket;
import de.steamwar.network.packets.server.InventoryPacket; import de.steamwar.network.packets.server.InventoryPacket;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
public class InventoryHandler extends PacketHandler { public class InventoryHandler extends PacketHandler {
@Handler @Handler
public static void handleInventoryPacket(InventoryPacket packet) { public static void handleInventoryPacket(InventoryPacket packet) {
Player player = Bukkit.getPlayer(SteamwarUser.get(packet.getPlayer()).getUUID());
Map<Integer, SWItem> items = new HashMap<>(); Map<Integer, SWItem> items = new HashMap<>();
packet.getItems().forEach((i, item) -> { packet.getItems().forEach((i, item) -> {
@SuppressWarnings("deprecation") SWItem it = SWItem.getItemFromJson(new JsonParser().parse(item).getAsJsonObject()); @SuppressWarnings("deprecation") SWItem it = SWItem.getItemFromJson(new JsonParser().parse(item).getAsJsonObject());
it.setCallback(click -> NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).position(i).type(InventoryCallbackPacket.CallbackType.CLICK).clickType(InventoryCallbackPacket.ClickType.getByName(click.name())).build())); it.setCallback(click -> NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).position(i).type(InventoryCallbackPacket.CallbackType.CLICK).clickType(InventoryCallbackPacket.ClickType.getByName(click.name())).build(), player));
items.put(i, it); items.put(i, it);
}); });
UUID player = SteamwarUser.get(packet.getPlayer()).getUUID();
SWInventory inventory = new SWInventory(Bukkit.getPlayer(player), packet.getSize(), packet.getTitle(), items); SWInventory inventory = new SWInventory(player, packet.getSize(), packet.getTitle(), items);
inventory.addCloseCallback(click -> { inventory.addCloseCallback(click -> {
if(Bukkit.getPlayer(player).getOpenInventory().getType() != InventoryType.CHEST) if(player.getOpenInventory().getType() != InventoryType.CHEST)
NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).type(InventoryCallbackPacket.CallbackType.CLOSE).build()); NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).type(InventoryCallbackPacket.CallbackType.CLOSE).build(), player);
}); });
inventory.open(); inventory.open();
} }

Datei anzeigen

@ -4,6 +4,7 @@ author: Lixfel
api-version: "1.13" api-version: "1.13"
load: STARTUP load: STARTUP
softdepend: softdepend:
- ViaVersion
- WorldEdit - WorldEdit
main: de.steamwar.core.Core main: de.steamwar.core.Core

Datei anzeigen

@ -81,6 +81,10 @@ allprojects {
maven { maven {
url = uri('https://libraries.minecraft.net') url = uri('https://libraries.minecraft.net')
} }
maven {
url = uri('https://repo.viaversion.com')
}
} }
} }