forked from SteamWar/SteamWar
Merge branch 'main' into MojMapReflections
# Conflicts: # SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java # SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java # SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java
This commit is contained in:
@@ -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 de.steamwar.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");
|
||||
|
||||
@@ -99,9 +99,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();
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import de.steamwar.sql.NodeData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -36,20 +37,22 @@ import java.util.logging.Level;
|
||||
public interface WorldEditWrapper {
|
||||
WorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
|
||||
|
||||
InputStream getPlayerClipboard(Player player, boolean schemFormat);
|
||||
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
|
||||
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;
|
||||
InputStream getPlayerClipboard(Player player);
|
||||
void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat);
|
||||
Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException;
|
||||
|
||||
Vector getOrigin(Clipboard clipboard);
|
||||
Vector getMinimum(Region region);
|
||||
Vector getMaximum(Region region);
|
||||
Vector applyTransform(Vector vector, Transform transform);
|
||||
|
||||
NodeData.SchematicFormat getNativeFormat();
|
||||
|
||||
static WorldEditPlugin getWorldEditPlugin() {
|
||||
return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
}
|
||||
|
||||
public static InputStream getPlayerClipboard(Player player, boolean schemFormat, SchematicWriter consumer) {
|
||||
static InputStream getPlayerClipboard(Player player, SchematicWriter consumer) {
|
||||
ClipboardHolder clipboardHolder;
|
||||
try {
|
||||
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
|
||||
@@ -85,7 +88,7 @@ public interface WorldEditWrapper {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
public static interface SchematicWriter {
|
||||
interface SchematicWriter {
|
||||
void write(OutputStream outputStream, Clipboard clipboard, ClipboardHolder holder) throws IOException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 de.steamwar.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.Field<Boolean> fullChunkFlag = Reflection.getField(mapChunk, boolean.class, 0);
|
||||
private static final Reflection.Field<Integer> chunkX = Reflection.getField(mapChunk, int.class, 0);
|
||||
private static final Reflection.Field<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,21 +21,19 @@ package de.steamwar.inventory;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.core.FlatteningWrapper;
|
||||
import de.steamwar.core.TrickyTrialsWrapper;
|
||||
import de.steamwar.core.VersionDependent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SWItem {
|
||||
|
||||
@@ -192,6 +190,11 @@ public class SWItem {
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
public void setLore(String... lore) {
|
||||
itemMeta.setLore(Arrays.stream(lore).collect(Collectors.toList()));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
public void setEnchanted(boolean enchanted) {
|
||||
if (enchanted){
|
||||
itemMeta.addEnchant(TrickyTrialsWrapper.impl.getUnbreakingEnchantment() , 10, true);
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class SchematicData {
|
||||
|
||||
public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) {
|
||||
public static Clipboard clipboardFromStream(InputStream is, NodeData.SchematicFormat schemFormat) {
|
||||
try {
|
||||
return WorldEditWrapper.impl.getClipboard(is, schemFormat);
|
||||
} catch (IOException e) {
|
||||
@@ -61,15 +61,11 @@ public class SchematicData {
|
||||
}
|
||||
|
||||
public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
|
||||
saveFromPlayer(player, Core.getVersion() > 12);
|
||||
}
|
||||
|
||||
public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
|
||||
data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat);
|
||||
data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.impl.getNativeFormat());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void saveFromBytes(byte[] bytes, boolean newFormat) {
|
||||
public void saveFromBytes(byte[] bytes, NodeData.SchematicFormat newFormat) {
|
||||
data.saveFromStream(new ByteArrayInputStream(bytes), newFormat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ author: Lixfel
|
||||
api-version: "1.13"
|
||||
load: STARTUP
|
||||
softdepend:
|
||||
- ViaVersion
|
||||
- WorldEdit
|
||||
|
||||
main: de.steamwar.core.Core
|
||||
|
||||
Reference in New Issue
Block a user