diff --git a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java
index 3a28106..2092669 100644
--- a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java
+++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java
@@ -222,15 +222,15 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT);
}
- private static final Reflection.FieldAccessor> scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, Reflection.getClass("{nms}.IChatBaseComponent"), 0);
- private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms}.ChatComponentText"), String.class);
+ private static final Reflection.FieldAccessor> scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0);
+ private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class);
@Override
public void setScoreboardTitle(Object packet, String title) {
scoreboardName.set(packet, chatComponentConstructor.invoke(title));
}
- private static final Class> scoreActionEnum = Reflection.getClass("{nms}.ScoreboardServer$Action");
+ private static final Class> scoreActionEnum = Reflection.getClass("{nms.server}.ScoreboardServer$Action");
private static final Reflection.FieldAccessor> scoreAction = Reflection.getField(SWScoreboard.scoreboardScore, scoreActionEnum, 0);
private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
diff --git a/SpigotCore_18/build.gradle b/SpigotCore_18/build.gradle
new file mode 100644
index 0000000..c6185e9
--- /dev/null
+++ b/SpigotCore_18/build.gradle
@@ -0,0 +1,50 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2021 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 .
+ */
+
+plugins {
+ id 'base'
+ id 'java'
+}
+
+group 'steamwar'
+version '1.0'
+
+compileJava.options.encoding = 'UTF-8'
+
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
+
+sourceSets {
+ main {
+ java {
+ srcDirs = ['src/']
+ }
+ resources {
+ srcDirs = ['src/']
+ exclude '**/*.java', '**/*.kt'
+ }
+ }
+}
+
+dependencies {
+ implementation project(":SpigotCore_Main")
+
+ compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
+ compileOnly files("${project.rootDir}/lib/Spigot-1.18.jar")
+}
diff --git a/SpigotCore_18/settings.gradle b/SpigotCore_18/settings.gradle
new file mode 100644
index 0000000..8943e4f
--- /dev/null
+++ b/SpigotCore_18/settings.gradle
@@ -0,0 +1,20 @@
+/*
+ * 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 .
+ */
+
+rootProject.name = 'SpigotCore_18'
\ No newline at end of file
diff --git a/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java b/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java
new file mode 100644
index 0000000..594fbac
--- /dev/null
+++ b/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java
@@ -0,0 +1,42 @@
+/*
+ This file is a part of the SteamWar software.
+
+ Copyright (C) 2021 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 .
+*/
+
+package de.steamwar.core;
+
+import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.world.level.chunk.Chunk;
+import org.bukkit.craftbukkit.v1_18_R1.CraftChunk;
+import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper {
+
+ @Override
+ public void sendChunk(Player p, int chunkX, int chunkZ) {
+ Chunk chunk = ((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle();
+ ((CraftPlayer)p).getHandle().b.a(new ClientboundLevelChunkWithLightPacket(chunk, chunk.q.l_(), null, null, false));
+ }
+
+ @Override
+ @SuppressWarnings("deprecation")
+ public double[] getSpigotTPS() {
+ return MinecraftServer.getServer().recentTps;
+ }
+}
diff --git a/SpigotCore_Main/build.gradle b/SpigotCore_Main/build.gradle
index 746d01e..1eb2599 100644
--- a/SpigotCore_Main/build.gradle
+++ b/SpigotCore_Main/build.gradle
@@ -43,7 +43,10 @@ sourceSets {
}
dependencies {
- compileOnly files("${project.rootDir}/lib/Spigot-1.15.jar")
+ compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
+ compileOnly 'io.netty:netty-all:4.1.68.Final'
+ compileOnly 'com.mojang:authlib:1.5.25'
+ compileOnly 'mysql:mysql-connector-java:5.1.49'
compileOnly files("${project.rootDir}/lib/WorldEdit-1.12.jar")
implementation 'net.wesjd:anvilgui:1.4.0-SNAPSHOT'
diff --git a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java
index 1e18232..e13db9a 100644
--- a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java
+++ b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java
@@ -1,5 +1,6 @@
package com.comphenix.tinyprotocol;
+import de.steamwar.core.Core;
import org.bukkit.Bukkit;
import java.lang.reflect.Constructor;
@@ -25,7 +26,7 @@ public final class Reflection {
* @param arguments - the arguments to pass to the constructor.
* @return The constructed object.
*/
- public Object invoke(Object... arguments);
+ Object invoke(Object... arguments);
}
/**
@@ -39,7 +40,7 @@ public final class Reflection {
* @param arguments - the arguments to pass to the method.
* @return The return value, or NULL if is void.
*/
- public Object invoke(Object target, Object... arguments);
+ Object invoke(Object target, Object... arguments);
}
/**
@@ -54,7 +55,7 @@ public final class Reflection {
* @param target - the target object, or NULL for a static field.
* @return The value of the field.
*/
- public T get(Object target);
+ T get(Object target);
/**
* Set the content of a field.
@@ -62,7 +63,7 @@ public final class Reflection {
* @param target - the target object, or NULL for a static field.
* @param value - the new value of the field.
*/
- public void set(Object target, Object value);
+ void set(Object target, Object value);
/**
* Determine if the given object has this field.
@@ -70,16 +71,16 @@ public final class Reflection {
* @param target - the object to test.
* @return TRUE if it does, FALSE otherwise.
*/
- public boolean hasField(Object target);
+ boolean hasField(Object target);
}
// Deduce the net.minecraft.server.v* package
- private static String OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName();
- private static String NMS_PREFIX = OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server");
- private static String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", "");
+ private static final String OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName();
+ private static final String NMS_PREFIX = OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server");
+ private static final String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", "");
// Variable replacement
- private static Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}");
+ private static final Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}");
private Reflection() {
// Seal class
@@ -148,7 +149,7 @@ public final class Reflection {
try {
return (T) field.get(target);
} catch (IllegalAccessException e) {
- throw new RuntimeException("Cannot access reflection.", e);
+ throw new IllegalArgumentException("Cannot access reflection.", e);
}
}
@@ -157,7 +158,7 @@ public final class Reflection {
try {
field.set(target, value);
} catch (IllegalAccessException e) {
- throw new RuntimeException("Cannot access reflection.", e);
+ throw new IllegalArgumentException("Cannot access reflection.", e);
}
}
@@ -220,17 +221,12 @@ public final class Reflection {
&& Arrays.equals(method.getParameterTypes(), params)) {
method.setAccessible(true);
- return new MethodInvoker() {
-
- @Override
- public Object invoke(Object target, Object... arguments) {
- try {
- return method.invoke(target, arguments);
- } catch (Exception e) {
- throw new RuntimeException("Cannot invoke method " + method, e);
- }
+ return (target, arguments) -> {
+ try {
+ return method.invoke(target, arguments);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Cannot invoke method " + method, e);
}
-
};
}
}
@@ -267,17 +263,12 @@ public final class Reflection {
if (Arrays.equals(constructor.getParameterTypes(), params)) {
constructor.setAccessible(true);
- return new ConstructorInvoker() {
-
- @Override
- public Object invoke(Object... arguments) {
- try {
- return constructor.newInstance(arguments);
- } catch (Exception e) {
- throw new RuntimeException("Cannot invoke constructor " + constructor, e);
- }
+ return arguments -> {
+ try {
+ return constructor.newInstance(arguments);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Cannot invoke constructor " + constructor, e);
}
-
};
}
}
@@ -290,8 +281,7 @@ public final class Reflection {
*
* This is useful when looking up fields by a NMS or OBC type.
*
- *
- * @see {@link #getClass()} for more information.
+ *
* @param lookupName - the class name with variables.
* @return The class.
*/
@@ -330,40 +320,10 @@ public final class Reflection {
* @throws IllegalArgumentException If a variable or class could not be found.
*/
public static Class> getClass(String lookupName) {
- return getCanonicalClass(expandVariables(lookupName));
- }
-
- /**
- * Retrieve a class in the net.minecraft.server.VERSION.* package.
- *
- * @param name - the name of the class, excluding the package.
- * @throws IllegalArgumentException If the class doesn't exist.
- */
- public static Class> getMinecraftClass(String name) {
- return getCanonicalClass(NMS_PREFIX + "." + name);
- }
-
- /**
- * Retrieve a class in the org.bukkit.craftbukkit.VERSION.* package.
- *
- * @param name - the name of the class, excluding the package.
- * @throws IllegalArgumentException If the class doesn't exist.
- */
- public static Class> getCraftBukkitClass(String name) {
- return getCanonicalClass(OBC_PREFIX + "." + name);
- }
-
- /**
- * Retrieve a class by its canonical name.
- *
- * @param canonicalName - the canonical name.
- * @return The class.
- */
- private static Class> getCanonicalClass(String canonicalName) {
try {
- return Class.forName(canonicalName);
+ return Class.forName(expandVariables(lookupName));
} catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("Cannot find " + canonicalName, e);
+ throw new IllegalArgumentException("Cannot find " + expandVariables(lookupName), e);
}
}
@@ -379,14 +339,17 @@ public final class Reflection {
while (matcher.find()) {
String variable = matcher.group(1);
- String replacement = "";
+ String replacement;
// Expand all detected variables
- if ("nms".equalsIgnoreCase(variable))
- replacement = NMS_PREFIX;
- else if ("obc".equalsIgnoreCase(variable))
+ if (variable.startsWith("nms")) {
+ if(Core.getVersion() >= 17)
+ replacement = NMS_PREFIX;
+ else
+ replacement = "net.minecraft" + variable.substring(3);
+ } else if ("obc".equals(variable))
replacement = OBC_PREFIX;
- else if ("version".equalsIgnoreCase(variable))
+ else if ("version".equals(variable))
replacement = VERSION;
else
throw new IllegalArgumentException("Unknown variable: " + variable);
@@ -401,6 +364,7 @@ public final class Reflection {
return output.toString();
}
+ @SuppressWarnings("deprecation")
public static Object newInstance(Class> clazz) {
try {
return clazz.newInstance();
diff --git a/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java
index 3d2e41a..1718efc 100644
--- a/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java
+++ b/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java
@@ -5,6 +5,7 @@ import com.comphenix.tinyprotocol.Reflection.MethodInvoker;
import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
import com.mojang.authlib.GameProfile;
+import de.steamwar.core.Core;
import io.netty.channel.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -28,18 +29,20 @@ import java.util.logging.Level;
*
* @author Kristian
*/
-public abstract class TinyProtocol {
+public class TinyProtocol {
private static final AtomicInteger ID = new AtomicInteger(0);
// Used in order to lookup a channel
private static final MethodInvoker getPlayerHandle = Reflection.getMethod("{obc}.entity.CraftPlayer", "getHandle");
- private static final FieldAccessor