diff --git a/.gitignore b/.gitignore
index 377ce8c..36e1257 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,15 @@
+# Package Files
+*.jar
+
+# Gradle
+.gradle
+**/build/
+!gradle/wrapper/gradle-wrapper.jar
+steamwar.properties
+
+# IntelliJ IDEA
.idea
-target
-lib
-dependency-reduced-pom.xml
-*.iml
\ No newline at end of file
+*.iml
+
+# Other
+lib
\ No newline at end of file
diff --git a/SpigotCore_10/build.gradle b/SpigotCore_10/build.gradle
new file mode 100644
index 0000000..34ef6f9
--- /dev/null
+++ b/SpigotCore_10/build.gradle
@@ -0,0 +1,49 @@
+/*
+ * 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 files("${project.rootDir}/lib/Spigot-1.10.jar")
+}
diff --git a/SpigotCore_10/pom.xml b/SpigotCore_10/pom.xml
deleted file mode 100644
index a04f9d3..0000000
--- a/SpigotCore_10/pom.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
- 4.0.0
-
-
- steamwar
- SpigotCore
- 2.0
-
-
-
- ${project.basedir}/..
-
-
- SpigotCore_10
- 2.0
-
-
- src
-
-
- src
-
- **/*.java
- **/*.kt
-
-
-
-
-
-
-
- steamwar
- Spigot
- 1.10
- system
- ${main.basedir}/lib/Spigot-1.10.jar
-
-
- steamwar
- WorldEdit
- 1.12
- system
- ${main.basedir}/lib/WorldEdit-1.12.jar
-
-
- steamwar
- SpigotCore_API
- 2.0
-
-
- steamwar
- SpigotCore_9
- 2.0
-
-
-
diff --git a/SpigotCore_10/settings.gradle b/SpigotCore_10/settings.gradle
new file mode 100644
index 0000000..13f4f4a
--- /dev/null
+++ b/SpigotCore_10/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_10'
\ No newline at end of file
diff --git a/SpigotCore_10/src/de/steamwar/chunk/Chunk_10.java b/SpigotCore_10/src/de/steamwar/core/CraftbukkitWrapper10.java
similarity index 74%
rename from SpigotCore_10/src/de/steamwar/chunk/Chunk_10.java
rename to SpigotCore_10/src/de/steamwar/core/CraftbukkitWrapper10.java
index 4f59621..8916735 100644
--- a/SpigotCore_10/src/de/steamwar/chunk/Chunk_10.java
+++ b/SpigotCore_10/src/de/steamwar/core/CraftbukkitWrapper10.java
@@ -1,6 +1,6 @@
-/*
+/*
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
@@ -17,17 +17,24 @@
along with this program. If not, see .
*/
-package de.steamwar.chunk;
+package de.steamwar.core;
+import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.PacketPlayOutMapChunk;
import org.bukkit.craftbukkit.v1_10_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
-public class Chunk_10 {
- private Chunk_10(){}
+public class CraftbukkitWrapper10 implements CraftbukkitWrapper.ICraftbukkitWrapper {
- public static void sendChunk(Player p, int chunkX, int chunkZ){
+ @Override
+ public void sendChunk(Player p, int chunkX, int chunkZ) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535));
}
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public double[] getSpigotTPS() {
+ return MinecraftServer.getServer().recentTps;
+ }
}
diff --git a/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java
deleted file mode 100644
index 2cc2d26..0000000
--- a/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java
+++ /dev/null
@@ -1,32 +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 .
-*/
-
-package de.steamwar.core;
-
-import net.minecraft.server.v1_10_R1.MinecraftServer;
-
-public class SpigotTPS_10 {
-
- private SpigotTPS_10(){}
-
- static double[] getTps(){
- return MinecraftServer.getServer().recentTps;
- }
-
-}
diff --git a/SpigotCore_12/build.gradle b/SpigotCore_12/build.gradle
new file mode 100644
index 0000000..5ee8ca9
--- /dev/null
+++ b/SpigotCore_12/build.gradle
@@ -0,0 +1,49 @@
+/*
+ * 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 files("${project.rootDir}/lib/Spigot-1.12.jar")
+}
diff --git a/SpigotCore_12/pom.xml b/SpigotCore_12/pom.xml
deleted file mode 100644
index c91c885..0000000
--- a/SpigotCore_12/pom.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
- 4.0.0
-
-
- steamwar
- SpigotCore
- 2.0
-
-
-
- ${project.basedir}/..
-
-
- SpigotCore_12
- 2.0
-
-
- src
-
-
- src
-
- **/*.java
- **/*.kt
-
-
-
-
-
-
-
- steamwar
- Spigot
- 1.12
- system
- ${main.basedir}/lib/Spigot-1.12.jar
-
-
- steamwar
- WorldEdit
- 1.12
- system
- ${main.basedir}/lib/WorldEdit-1.12.jar
-
-
- steamwar
- SpigotCore_API
- 2.0
-
-
- steamwar
- SpigotCore_8
- 2.0
-
-
-
\ No newline at end of file
diff --git a/SpigotCore_12/settings.gradle b/SpigotCore_12/settings.gradle
new file mode 100644
index 0000000..079bf5a
--- /dev/null
+++ b/SpigotCore_12/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_12'
\ No newline at end of file
diff --git a/SpigotCore_12/src/de/steamwar/chunk/Chunk_12.java b/SpigotCore_12/src/de/steamwar/core/CraftbukkitWrapper12.java
similarity index 74%
rename from SpigotCore_12/src/de/steamwar/chunk/Chunk_12.java
rename to SpigotCore_12/src/de/steamwar/core/CraftbukkitWrapper12.java
index 8944a1f..3d084b3 100644
--- a/SpigotCore_12/src/de/steamwar/chunk/Chunk_12.java
+++ b/SpigotCore_12/src/de/steamwar/core/CraftbukkitWrapper12.java
@@ -1,6 +1,6 @@
-/*
+/*
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
@@ -17,17 +17,24 @@
along with this program. If not, see .
*/
-package de.steamwar.chunk;
+package de.steamwar.core;
+import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk;
import org.bukkit.craftbukkit.v1_12_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
-public class Chunk_12 {
- private Chunk_12(){}
+public class CraftbukkitWrapper12 implements CraftbukkitWrapper.ICraftbukkitWrapper {
- public static void sendChunk(Player p, int chunkX, int chunkZ){
+ @Override
+ public void sendChunk(Player p, int chunkX, int chunkZ) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535));
}
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public double[] getSpigotTPS() {
+ return MinecraftServer.getServer().recentTps;
+ }
}
diff --git a/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java
deleted file mode 100644
index 17541c7..0000000
--- a/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java
+++ /dev/null
@@ -1,32 +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 .
-*/
-
-package de.steamwar.core;
-
-import net.minecraft.server.v1_12_R1.MinecraftServer;
-
-public class SpigotTPS_12 {
-
- private SpigotTPS_12(){}
-
- static double[] getTps(){
- return MinecraftServer.getServer().recentTps;
- }
-
-}
diff --git a/SpigotCore_12/src/de/steamwar/message/Message_12.java b/SpigotCore_12/src/de/steamwar/core/WorldOfColorWrapper12.java
similarity index 84%
rename from SpigotCore_12/src/de/steamwar/message/Message_12.java
rename to SpigotCore_12/src/de/steamwar/core/WorldOfColorWrapper12.java
index a228394..f6c5050 100644
--- a/SpigotCore_12/src/de/steamwar/message/Message_12.java
+++ b/SpigotCore_12/src/de/steamwar/core/WorldOfColorWrapper12.java
@@ -17,16 +17,16 @@
along with this program. If not, see .
*/
-package de.steamwar.message;
+package de.steamwar.core;
import org.bukkit.entity.Player;
import java.util.Locale;
-class Message_12 {
- private Message_12(){}
+public class WorldOfColorWrapper12 implements WorldOfColorWrapper.IWorldOfColorWrapper {
- static Locale getLocale(Player player){
+ @Override
+ public Locale getLocale(Player player){
return Locale.forLanguageTag(player.getLocale());
}
}
diff --git a/SpigotCore_14/build.gradle b/SpigotCore_14/build.gradle
new file mode 100644
index 0000000..688968a
--- /dev/null
+++ b/SpigotCore_14/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 files("${project.rootDir}/lib/Spigot-1.14.jar")
+ compileOnly files("${project.rootDir}/lib/WorldEdit-1.15.jar")
+}
diff --git a/SpigotCore_14/pom.xml b/SpigotCore_14/pom.xml
deleted file mode 100644
index 724d006..0000000
--- a/SpigotCore_14/pom.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
- 4.0.0
-
-
- steamwar
- SpigotCore
- 2.0
-
-
-
- ${project.basedir}/..
-
-
- SpigotCore_14
- 2.0
-
-
- src
-
-
- src
-
- **/*.java
- **/*.kt
-
-
-
-
-
-
-
- steamwar
- Spigot
- 1.14
- system
- ${main.basedir}/lib/Spigot-1.14.jar
-
-
- steamwar
- WorldEdit
- 1.15
- system
- ${main.basedir}/lib/WorldEdit-1.15.jar
-
-
- steamwar
- SpigotCore_API
- 2.0
- compile
-
-
-
\ No newline at end of file
diff --git a/SpigotCore_14/settings.gradle b/SpigotCore_14/settings.gradle
new file mode 100644
index 0000000..4a8abac
--- /dev/null
+++ b/SpigotCore_14/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_14'
\ No newline at end of file
diff --git a/SpigotCore_14/src/de/steamwar/chunk/Chunk_14.java b/SpigotCore_14/src/de/steamwar/core/CraftbukkitWrapper14.java
similarity index 74%
rename from SpigotCore_14/src/de/steamwar/chunk/Chunk_14.java
rename to SpigotCore_14/src/de/steamwar/core/CraftbukkitWrapper14.java
index fa5a2ca..bc27af3 100644
--- a/SpigotCore_14/src/de/steamwar/chunk/Chunk_14.java
+++ b/SpigotCore_14/src/de/steamwar/core/CraftbukkitWrapper14.java
@@ -1,6 +1,6 @@
-/*
+/*
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
@@ -17,17 +17,24 @@
along with this program. If not, see .
*/
-package de.steamwar.chunk;
+package de.steamwar.core;
+import net.minecraft.server.v1_14_R1.MinecraftServer;
import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk;
import org.bukkit.craftbukkit.v1_14_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
-public class Chunk_14 {
- private Chunk_14(){}
+public class CraftbukkitWrapper14 implements CraftbukkitWrapper.ICraftbukkitWrapper {
- public static void sendChunk(Player p, int chunkX, int chunkZ){
+ @Override
+ public void sendChunk(Player p, int chunkX, int chunkZ) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535));
}
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public double[] getSpigotTPS() {
+ return MinecraftServer.getServer().recentTps;
+ }
}
diff --git a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java
similarity index 91%
rename from SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java
rename to SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java
index 623dd20..3a28106 100644
--- a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java
+++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java
@@ -1,6 +1,6 @@
-/*
+/*
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
@@ -17,8 +17,10 @@
along with this program. If not, see .
*/
-package de.steamwar.inventory;
+package de.steamwar.core;
+import com.comphenix.tinyprotocol.Reflection;
+import de.steamwar.scoreboard.SWScoreboard;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@@ -27,8 +29,7 @@ import org.bukkit.inventory.meta.SkullMeta;
import java.util.HashMap;
import java.util.Map;
-class SWItem_14 {
- private SWItem_14(){}
+public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper {
private static final Map renamedLegacy = new HashMap<>();
@@ -221,7 +222,25 @@ class SWItem_14 {
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT);
}
- static Material getMaterial(String material) {
+ 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);
+
+ @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 Reflection.FieldAccessor> scoreAction = Reflection.getField(SWScoreboard.scoreboardScore, scoreActionEnum, 0);
+ private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
+
+ @Override
+ public void setScoreAction(Object packet) {
+ scoreAction.set(packet, scoreActionChange);
+ }
+
+ @Override
+ public Material getMaterial(String material) {
try{
return Material.valueOf(material);
}catch(IllegalArgumentException e){
@@ -229,7 +248,8 @@ class SWItem_14 {
}
}
- static Material getDye(int colorCode){
+ @Override
+ public Material getDye(int colorCode) {
switch(colorCode){
case 1:
return Material.RED_DYE;
@@ -266,7 +286,9 @@ class SWItem_14 {
}
}
- static ItemStack setSkullOwner(String player){
+ @SuppressWarnings("deprecation")
+ @Override
+ public ItemStack setSkullOwner(String player) {
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta headmeta = (SkullMeta) head.getItemMeta();
assert headmeta != null;
diff --git a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java b/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java
similarity index 93%
rename from SpigotCore_14/src/de/steamwar/sql/Schematic_14.java
rename to SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java
index 3e3164f..96b135b 100644
--- a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java
+++ b/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java
@@ -1,23 +1,4 @@
-/*
- 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 .
-*/
-
-package de.steamwar.sql;
+package de.steamwar.core;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
@@ -25,7 +6,6 @@ import com.sk89q.jnbt.*;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
-import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
@@ -46,7 +26,7 @@ import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
-import org.bukkit.Bukkit;
+import de.steamwar.sql.NoClipboardException;
import org.bukkit.entity.Player;
import java.io.ByteArrayOutputStream;
@@ -54,20 +34,19 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
-import java.util.zip.GZIPInputStream;
import static com.google.common.base.Preconditions.checkNotNull;
-class Schematic_14 {
- private Schematic_14(){}
+public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
private static final ClipboardFormat SCHEMATIC = BuiltInClipboardFormat.MCEDIT_SCHEMATIC;
private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
- static byte[] getPlayerClipboard(Player player, boolean schemFormat) {
+ @Override
+ public byte[] getPlayerClipboard(Player player, boolean schemFormat) {
ClipboardHolder clipboardHolder;
try {
- clipboardHolder = getWorldEditPlugin().getSession(player).getClipboard();
+ clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
} catch (EmptyClipboardException e) {
throw new NoClipboardException();
}
@@ -93,7 +72,8 @@ class Schematic_14 {
return outputStream.toByteArray();
}
- static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) {
+ @Override
+ public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) {
Clipboard clipboard = null;
try {
clipboard = getClipboard(is, schemFormat);
@@ -104,26 +84,23 @@ class Schematic_14 {
if (clipboard == null)
throw new NoClipboardException();
- Actor actor = getWorldEditPlugin().wrapCommandSender(player);
- getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard));
+ Actor actor = WorldEditWrapper.getWorldEditPlugin().wrapCommandSender(player);
+ WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard));
}
- static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
+ @Override
+ public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
try {
if(schemFormat){
- return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read();
+ return new SpongeSchematicReader(new NBTInputStream(is)).read();
}else{
- return new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read();
+ return new MCEditSchematicReader(new NBTInputStream(is)).read();
}
} catch (NullPointerException e) {
throw new NoClipboardException();
}
}
- private static WorldEditPlugin getWorldEditPlugin() {
- return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
- }
-
private static class MCEditSchematicReader extends NBTSchematicReader {
private final NBTInputStream inputStream;
@@ -420,7 +397,7 @@ class Schematic_14 {
return readVersion1(schematicTag);
} else if (schematicVersion == 2) {
dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue();
- if (dataVersion < liveDataVersion) {
+ if (dataVersion < liveDataVersion) {
fixer = platform.getDataFixer();
}
diff --git a/SpigotCore_15/build.gradle b/SpigotCore_15/build.gradle
new file mode 100644
index 0000000..76dc3ee
--- /dev/null
+++ b/SpigotCore_15/build.gradle
@@ -0,0 +1,49 @@
+/*
+ * 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 files("${project.rootDir}/lib/Spigot-1.15.jar")
+}
diff --git a/SpigotCore_15/pom.xml b/SpigotCore_15/pom.xml
deleted file mode 100644
index a7ecfbd..0000000
--- a/SpigotCore_15/pom.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
- 4.0.0
-
-
- steamwar
- SpigotCore
- 2.0
-
-
-
- ${project.basedir}/..
-
-
- SpigotCore_15
- 2.0
-
-
- src
-
-
- src
-
- **/*.java
- **/*.kt
-
-
-
-
-
-
-
- steamwar
- Spigot
- 1.15
- system
- ${main.basedir}/lib/Spigot-1.15.jar
-
-
- steamwar
- WorldEdit
- 1.15
- system
- ${main.basedir}/lib/WorldEdit-1.15.jar
-
-
- steamwar
- SpigotCore_API
- 2.0
-
-
- steamwar
- SpigotCore_14
- 2.0
-
-
-
\ No newline at end of file
diff --git a/SpigotCore_15/settings.gradle b/SpigotCore_15/settings.gradle
new file mode 100644
index 0000000..a861db0
--- /dev/null
+++ b/SpigotCore_15/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_15'
\ No newline at end of file
diff --git a/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java b/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java
deleted file mode 100644
index 9864a31..0000000
--- a/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java
+++ /dev/null
@@ -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 .
- */
-
-package de.steamwar.authlib;
-
-import net.minecraft.server.v1_15_R1.MinecraftServer;
-
-public class AuthlibInjector_15 {
-
- static Class getMinecraftClass() {
- return MinecraftServer.class;
- }
-
- static Object getMinecraftServerInstance() {
- return MinecraftServer.getServer();
- }
-}
diff --git a/SpigotCore_15/src/de/steamwar/chunk/Chunk_15.java b/SpigotCore_15/src/de/steamwar/core/CraftbukkitWrapper15.java
similarity index 74%
rename from SpigotCore_15/src/de/steamwar/chunk/Chunk_15.java
rename to SpigotCore_15/src/de/steamwar/core/CraftbukkitWrapper15.java
index 8a8b636..d5b908f 100644
--- a/SpigotCore_15/src/de/steamwar/chunk/Chunk_15.java
+++ b/SpigotCore_15/src/de/steamwar/core/CraftbukkitWrapper15.java
@@ -1,6 +1,6 @@
-/*
+/*
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
@@ -17,17 +17,24 @@
along with this program. If not, see .
*/
-package de.steamwar.chunk;
+package de.steamwar.core;
+import net.minecraft.server.v1_15_R1.MinecraftServer;
import net.minecraft.server.v1_15_R1.PacketPlayOutMapChunk;
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
-public class Chunk_15 {
- private Chunk_15(){}
+public class CraftbukkitWrapper15 implements CraftbukkitWrapper.ICraftbukkitWrapper {
- public static void sendChunk(Player p, int chunkX, int chunkZ){
+ @Override
+ public void sendChunk(Player p, int chunkX, int chunkZ) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535));
}
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public double[] getSpigotTPS() {
+ return MinecraftServer.getServer().recentTps;
+ }
}
diff --git a/SpigotCore_8/build.gradle b/SpigotCore_8/build.gradle
new file mode 100644
index 0000000..8007cef
--- /dev/null
+++ b/SpigotCore_8/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 files("${project.rootDir}/lib/Spigot-1.8.jar")
+ compileOnly files("${project.rootDir}/lib/WorldEdit-1.12.jar")
+}
diff --git a/SpigotCore_8/pom.xml b/SpigotCore_8/pom.xml
deleted file mode 100644
index 0e05af5..0000000
--- a/SpigotCore_8/pom.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
- 4.0.0
-
-
- steamwar
- SpigotCore
- 2.0
-
-
-
- ${project.basedir}/..
-
-
- SpigotCore_8
- 2.0
-
-
- src
-
-
- src
-
- **/*.java
- **/*.kt
-
-
-
-
-
-
-
- steamwar
- Spigot
- 1.8
- system
- ${main.basedir}/lib/Spigot-1.8.jar
-
-
- steamwar
- WorldEdit
- 1.12
- system
- ${main.basedir}/lib/WorldEdit-1.12.jar
-
-
- steamwar
- SpigotCore_API
- 2.0
-
-
-
\ No newline at end of file
diff --git a/SpigotCore_8/settings.gradle b/SpigotCore_8/settings.gradle
new file mode 100644
index 0000000..e4a8e0a
--- /dev/null
+++ b/SpigotCore_8/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_8'
\ No newline at end of file
diff --git a/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java b/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java
new file mode 100644
index 0000000..8c08082
--- /dev/null
+++ b/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java
@@ -0,0 +1,41 @@
+/*
+ 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 .
+ */
+
+package de.steamwar.core;
+
+import net.md_5.bungee.api.ChatMessageType;
+import net.md_5.bungee.api.chat.BaseComponent;
+import net.minecraft.server.v1_8_R3.ChatComponentText;
+import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
+import org.bukkit.Sound;
+import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
+
+ @Override
+ public void playPling(Player player) {
+ player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 1);
+ }
+
+ @Override
+ public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) {
+ ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(BaseComponent.toLegacyText(msg)), (byte)type.ordinal()));
+ }
+}
diff --git a/SpigotCore_8/src/de/steamwar/chunk/Chunk_8.java b/SpigotCore_8/src/de/steamwar/core/CraftbukkitWrapper8.java
similarity index 76%
rename from SpigotCore_8/src/de/steamwar/chunk/Chunk_8.java
rename to SpigotCore_8/src/de/steamwar/core/CraftbukkitWrapper8.java
index 404c158..149664c 100644
--- a/SpigotCore_8/src/de/steamwar/chunk/Chunk_8.java
+++ b/SpigotCore_8/src/de/steamwar/core/CraftbukkitWrapper8.java
@@ -1,6 +1,6 @@
-/*
+/*
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
@@ -17,17 +17,23 @@
along with this program. If not, see .
*/
-package de.steamwar.chunk;
+package de.steamwar.core;
+import net.minecraft.server.v1_8_R3.MinecraftServer;
import net.minecraft.server.v1_8_R3.PacketPlayOutMapChunk;
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
-public class Chunk_8 {
- private Chunk_8(){}
+public class CraftbukkitWrapper8 implements CraftbukkitWrapper.ICraftbukkitWrapper {
- public static void sendChunk(Player p, int chunkX, int chunkZ){
+ @Override
+ public void sendChunk(Player p, int chunkX, int chunkZ) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), true, 65535));
}
+
+ @Override
+ public double[] getSpigotTPS() {
+ return MinecraftServer.getServer().recentTps;
+ }
}
diff --git a/SpigotCore_8/src/de/steamwar/inventory/SWItem_8.java b/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java
similarity index 54%
rename from SpigotCore_8/src/de/steamwar/inventory/SWItem_8.java
rename to SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java
index 746134f..371c799 100644
--- a/SpigotCore_8/src/de/steamwar/inventory/SWItem_8.java
+++ b/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java
@@ -1,6 +1,6 @@
-/*
+/*
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
@@ -17,16 +17,33 @@
along with this program. If not, see .
*/
-package de.steamwar.inventory;
+package de.steamwar.core;
+import com.comphenix.tinyprotocol.Reflection;
+import de.steamwar.scoreboard.SWScoreboard;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
-class SWItem_8 {
- private SWItem_8(){}
+public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper {
- static Material getMaterial(String material){
+ private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(SWScoreboard.scoreboardObjective, String.class, 1);
+ private static final Class> scoreActionEnum = Reflection.getClass("{nms}.PacketPlayOutScoreboardScore$EnumScoreboardAction");
+ private static final Reflection.FieldAccessor> scoreAction = Reflection.getField(SWScoreboard.scoreboardScore, scoreActionEnum, 0);
+ private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
+
+ @Override
+ public void setScoreboardTitle(Object packet, String title) {
+ scoreboardName.set(packet, title);
+ }
+
+ @Override
+ public void setScoreAction(Object packet) {
+ scoreAction.set(packet, scoreActionChange);
+ }
+
+ @Override
+ public Material getMaterial(String material) {
try{
return Material.valueOf(material);
}catch(IllegalArgumentException e){
@@ -34,11 +51,13 @@ class SWItem_8 {
}
}
- static Material getDye(){
+ @Override
+ public Material getDye(int colorCode) {
return Material.INK_SACK;
}
- static ItemStack setSkullOwner(String player){
+ @Override
+ public ItemStack setSkullOwner(String player) {
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta headmeta = (SkullMeta) head.getItemMeta();
headmeta.setOwner(player);
diff --git a/SpigotCore_8/src/de/steamwar/sql/IDConverter.java b/SpigotCore_8/src/de/steamwar/core/IDConverter8.java
similarity index 90%
rename from SpigotCore_8/src/de/steamwar/sql/IDConverter.java
rename to SpigotCore_8/src/de/steamwar/core/IDConverter8.java
index b503bde..fdbf70b 100644
--- a/SpigotCore_8/src/de/steamwar/sql/IDConverter.java
+++ b/SpigotCore_8/src/de/steamwar/core/IDConverter8.java
@@ -17,7 +17,7 @@
along with this program. If not, see .
*/
-package de.steamwar.sql;
+package de.steamwar.core;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -26,12 +26,12 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
-class IDConverter {
- private IDConverter(){}
+class IDConverter8 {
+ private IDConverter8(){}
static Map getMap(){
Map ids = new HashMap<>();
- YamlConfiguration legacy = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects.requireNonNull(IDConverter.class.getClassLoader().getResourceAsStream("legacy.yml"))));
+ YamlConfiguration legacy = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects.requireNonNull(IDConverter8.class.getClassLoader().getResourceAsStream("legacy.yml"))));
for(String blockString : legacy.getKeys(false)){
String blockNum = legacy.getString(blockString);
String[] block = blockNum.split(":");
diff --git a/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java
deleted file mode 100644
index aeb94d1..0000000
--- a/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java
+++ /dev/null
@@ -1,32 +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 .
-*/
-
-package de.steamwar.core;
-
-import net.minecraft.server.v1_8_R3.MinecraftServer;
-
-public class SpigotTPS_8 {
-
- private SpigotTPS_8(){}
-
- static double[] getTps(){
- return MinecraftServer.getServer().recentTps;
- }
-
-}
diff --git a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java b/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java
similarity index 83%
rename from SpigotCore_8/src/de/steamwar/sql/Schematic_8.java
rename to SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java
index 87afb82..3e243bd 100644
--- a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java
+++ b/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java
@@ -1,23 +1,4 @@
-/*
- 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 .
-*/
-
-package de.steamwar.sql;
+package de.steamwar.core;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
@@ -25,20 +6,19 @@ import com.sk89q.jnbt.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld;
-import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
+import com.sk89q.worldedit.extent.clipboard.io.SchematicReader;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.registry.WorldData;
-import org.bukkit.Bukkit;
+import de.steamwar.sql.NoClipboardException;
import org.bukkit.entity.Player;
-import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -47,15 +27,14 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import java.util.zip.GZIPInputStream;
-class Schematic_8 {
- private Schematic_8(){}
+public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
- static byte[] getPlayerClipboard(Player player) {
+ @Override
+ public byte[] getPlayerClipboard(Player player, boolean schemFormat) {
ClipboardHolder clipboardHolder;
try {
- clipboardHolder = getWorldEditPlugin().getSession(player).getClipboard();
+ clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
} catch (EmptyClipboardException e) {
throw new NoClipboardException();
}
@@ -73,7 +52,8 @@ class Schematic_8 {
return outputStream.toByteArray();
}
- static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) {
+ @Override
+ public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) {
WorldData world = new BukkitWorld(player.getWorld()).getWorldData();
Clipboard clipboard;
try {
@@ -82,22 +62,19 @@ class Schematic_8 {
throw new RuntimeException(e);
}
- Actor actor = getWorldEditPlugin().wrapCommandSender(player);
- getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard, world));
+ Actor actor = WorldEditWrapper.getWorldEditPlugin().wrapCommandSender(player);
+ WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard, world));
}
- static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
+ @Override
+ public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
if(schemFormat)
- return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
+ return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
else
- return ClipboardFormat.SCHEMATIC.getReader(is).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
+ return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
}
- private static WorldEditPlugin getWorldEditPlugin() {
- return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
- }
-
- public static class SpongeSchematicReader implements ClipboardReader {
+ private static class SpongeSchematicReader implements ClipboardReader {
private final NBTInputStream inputStream;
private int schematicVersion = -1;
@@ -132,7 +109,7 @@ class Schematic_8 {
}
private BlockArrayClipboard readSchematic(CompoundTag schematicTag) throws IOException {
- final Map ids = IDConverter.getMap();
+ final Map ids = IDConverter8.getMap();
Map schematic = schematicTag.getValue();
int width = (requireTag(schematic, "Width", ShortTag.class)).getValue();
@@ -181,7 +158,7 @@ class Schematic_8 {
String palettePart = iterator.next();
id = requireTag(paletteObject, palettePart, IntTag.class).getValue();
- IDConverter.BlockTypeID blockID = ids.get(palettePart);
+ IDConverter8.BlockTypeID blockID = ids.get(palettePart);
if(blockID == null){
blockID = ids.get(palettePart.split("\\[")[0]);
}
@@ -277,7 +254,6 @@ class Schematic_8 {
}
}
- @Nullable
private static T getTag(Map items, String key, Class expected) {
if (!items.containsKey(key)) {
return null;
diff --git a/SpigotCore_8/src/de/steamwar/message/Message_8.java b/SpigotCore_8/src/de/steamwar/core/WorldOfColorWrapper8.java
similarity index 84%
rename from SpigotCore_8/src/de/steamwar/message/Message_8.java
rename to SpigotCore_8/src/de/steamwar/core/WorldOfColorWrapper8.java
index 61b897b..73cf7fd 100644
--- a/SpigotCore_8/src/de/steamwar/message/Message_8.java
+++ b/SpigotCore_8/src/de/steamwar/core/WorldOfColorWrapper8.java
@@ -17,16 +17,16 @@
along with this program. If not, see .
*/
-package de.steamwar.message;
+package de.steamwar.core;
import org.bukkit.entity.Player;
import java.util.Locale;
-class Message_8 {
- private Message_8(){}
+public class WorldOfColorWrapper8 implements WorldOfColorWrapper.IWorldOfColorWrapper {
- static Locale getLocale(Player player){
+ @Override
+ public Locale getLocale(Player player){
return Locale.forLanguageTag(player.spigot().getLocale());
}
}
diff --git a/SpigotCore_9/build.gradle b/SpigotCore_9/build.gradle
new file mode 100644
index 0000000..064f759
--- /dev/null
+++ b/SpigotCore_9/build.gradle
@@ -0,0 +1,49 @@
+/*
+ * 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 files("${project.rootDir}/lib/Spigot-1.9.jar")
+}
diff --git a/SpigotCore_9/pom.xml b/SpigotCore_9/pom.xml
deleted file mode 100644
index 2b9cb04..0000000
--- a/SpigotCore_9/pom.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
- 4.0.0
-
-
- steamwar
- SpigotCore
- 2.0
-
-
-
- ${project.basedir}/..
-
-
- SpigotCore_9
- 2.0
-
-
- src
-
-
- src
-
- **/*.java
- **/*.kt
-
-
-
-
-
-
-
- steamwar
- Spigot
- 1.9
- system
- ${main.basedir}/lib/Spigot-1.9.jar
-
-
- steamwar
- WorldEdit
- 1.12
- system
- ${main.basedir}/lib/WorldEdit-1.12.jar
-
-
- steamwar
- SpigotCore_API
- 2.0
-
-
- steamwar
- SpigotCore_8
- 2.0
-
-
-
\ No newline at end of file
diff --git a/SpigotCore_9/settings.gradle b/SpigotCore_9/settings.gradle
new file mode 100644
index 0000000..c55656e
--- /dev/null
+++ b/SpigotCore_9/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_9'
\ No newline at end of file
diff --git a/SpigotCore_9/src/de/steamwar/comms/BungeeReceiver_9.java b/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java
similarity index 69%
rename from SpigotCore_9/src/de/steamwar/comms/BungeeReceiver_9.java
rename to SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java
index 685b65a..d12a37d 100644
--- a/SpigotCore_9/src/de/steamwar/comms/BungeeReceiver_9.java
+++ b/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java
@@ -17,14 +17,22 @@
along with this program. If not, see .
*/
-package de.steamwar.comms;
+package de.steamwar.core;
+import net.md_5.bungee.api.ChatMessageType;
+import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
-public class BungeeReceiver_9 {
+public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
- public static void playpling(Player player) {
+ @Override
+ public void playPling(Player player) {
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
}
+
+ @Override
+ public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) {
+ player.spigot().sendMessage(type, msg);
+ }
}
diff --git a/SpigotCore_9/src/de/steamwar/chunk/Chunk_9.java b/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java
similarity index 74%
rename from SpigotCore_9/src/de/steamwar/chunk/Chunk_9.java
rename to SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java
index b4792fa..6cce09e 100644
--- a/SpigotCore_9/src/de/steamwar/chunk/Chunk_9.java
+++ b/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java
@@ -1,6 +1,6 @@
-/*
+/*
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
@@ -17,17 +17,24 @@
along with this program. If not, see .
*/
-package de.steamwar.chunk;
+package de.steamwar.core;
+import net.minecraft.server.v1_9_R2.MinecraftServer;
import net.minecraft.server.v1_9_R2.PacketPlayOutMapChunk;
import org.bukkit.craftbukkit.v1_9_R2.CraftChunk;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
-public class Chunk_9 {
- private Chunk_9(){}
+public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapper {
- public static void sendChunk(Player p, int chunkX, int chunkZ){
+ @Override
+ public void sendChunk(Player p, int chunkX, int chunkZ) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunkX, chunkZ)).getHandle(), 65535));
}
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public double[] getSpigotTPS() {
+ return MinecraftServer.getServer().recentTps;
+ }
}
diff --git a/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java
deleted file mode 100644
index 6a0ba28..0000000
--- a/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java
+++ /dev/null
@@ -1,32 +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 .
-*/
-
-package de.steamwar.core;
-
-import net.minecraft.server.v1_9_R2.MinecraftServer;
-
-public class SpigotTPS_9 {
-
- private SpigotTPS_9(){}
-
- static double[] getTps(){
- return MinecraftServer.getServer().recentTps;
- }
-
-}
diff --git a/SpigotCore_API/pom.xml b/SpigotCore_API/pom.xml
deleted file mode 100644
index 3d316be..0000000
--- a/SpigotCore_API/pom.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
- 4.0.0
-
-
- steamwar
- SpigotCore
- 2.0
-
-
-
- ${project.basedir}/..
-
-
- SpigotCore_API
- 2.0
-
-
- src
-
-
- src
-
- **/*.java
- **/*.kt
-
-
-
-
-
\ No newline at end of file
diff --git a/SpigotCore_Main/build.gradle b/SpigotCore_Main/build.gradle
new file mode 100644
index 0000000..59c9f89
--- /dev/null
+++ b/SpigotCore_Main/build.gradle
@@ -0,0 +1,55 @@
+/*
+ * 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 {
+ compileOnly files("${project.rootDir}/lib/Spigot-1.15.jar")
+ compileOnly files("${project.rootDir}/lib/WorldEdit-1.12.jar")
+ implementation 'net.wesjd:anvilgui:1.4.0-SNAPSHOT'
+}
+
+processResources {
+ from("build/classes/java/main/META-INF/annotations/") {
+ into("de.steamwar.bausystem")
+ }
+}
diff --git a/SpigotCore_Main/pom.xml b/SpigotCore_Main/pom.xml
deleted file mode 100644
index 0d23f6f..0000000
--- a/SpigotCore_Main/pom.xml
+++ /dev/null
@@ -1,128 +0,0 @@
-
-
- 4.0.0
-
-
- steamwar
- SpigotCore
- 2.0
-
-
-
- ${project.basedir}/..
-
-
-
-
- codemc-snapshots
- https://repo.codemc.io/repository/maven-snapshots/
-
-
-
- SpigotCore_Main
- 2.0
- jar
-
-
- src
-
-
- src
-
- **/*.java
- **/*.kt
-
-
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.2.1
-
-
- package
-
- shade
-
-
-
-
-
- spigotcore
-
-
-
-
- steamwar
- Spigot
- 1.15
- system
- ${main.basedir}/lib/Spigot-1.15.jar
-
-
- steamwar
- WorldEdit
- 1.12
- system
- ${main.basedir}/lib/WorldEdit-1.12.jar
-
-
- steamwar
- ProtocolLib
- 1.0
- system
- ${main.basedir}/lib/ProtocolLib.jar
-
-
- net.wesjd
- anvilgui
- 1.4.0-SNAPSHOT
- compile
-
-
- steamwar
- SpigotCore_API
- 2.0
- compile
-
-
- steamwar
- SpigotCore_8
- 2.0
- compile
-
-
- steamwar
- SpigotCore_9
- 2.0
- compile
-
-
- steamwar
- SpigotCore_10
- 2.0
- compile
-
-
- steamwar
- SpigotCore_12
- 2.0
- compile
-
-
- steamwar
- SpigotCore_14
- 2.0
- compile
-
-
- steamwar
- SpigotCore_15
- 2.0
- compile
-
-
-
\ No newline at end of file
diff --git a/SpigotCore_Main/settings.gradle b/SpigotCore_Main/settings.gradle
new file mode 100644
index 0000000..2d1bf48
--- /dev/null
+++ b/SpigotCore_Main/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_Main'
\ No newline at end of file
diff --git a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java
new file mode 100644
index 0000000..1e18232
--- /dev/null
+++ b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java
@@ -0,0 +1,411 @@
+package com.comphenix.tinyprotocol;
+
+import org.bukkit.Bukkit;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * An utility class that simplifies reflection in Bukkit plugins.
+ *
+ * @author Kristian
+ */
+public final class Reflection {
+ /**
+ * An interface for invoking a specific constructor.
+ */
+ public interface ConstructorInvoker {
+ /**
+ * Invoke a constructor for a specific class.
+ *
+ * @param arguments - the arguments to pass to the constructor.
+ * @return The constructed object.
+ */
+ public Object invoke(Object... arguments);
+ }
+
+ /**
+ * An interface for invoking a specific method.
+ */
+ public interface MethodInvoker {
+ /**
+ * Invoke a method on a specific target object.
+ *
+ * @param target - the target object, or NULL for a static method.
+ * @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);
+ }
+
+ /**
+ * An interface for retrieving the field content.
+ *
+ * @param - field type.
+ */
+ public interface FieldAccessor {
+ /**
+ * Retrieve the content of a field.
+ *
+ * @param target - the target object, or NULL for a static field.
+ * @return The value of the field.
+ */
+ public T get(Object target);
+
+ /**
+ * Set the content of a field.
+ *
+ * @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);
+
+ /**
+ * Determine if the given object has this field.
+ *
+ * @param target - the object to test.
+ * @return TRUE if it does, FALSE otherwise.
+ */
+ public 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(".", "");
+
+ // Variable replacement
+ private static Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}");
+
+ private Reflection() {
+ // Seal class
+ }
+
+ /**
+ * Retrieve a field accessor for a specific field type and name.
+ *
+ * @param target - the target type.
+ * @param name - the name of the field, or NULL to ignore.
+ * @param fieldType - a compatible field type.
+ * @return The field accessor.
+ */
+ public static FieldAccessor getField(Class> target, String name, Class fieldType) {
+ return getField(target, name, fieldType, 0);
+ }
+
+ /**
+ * Retrieve a field accessor for a specific field type and name.
+ *
+ * @param className - lookup name of the class, see {@link #getClass(String)}.
+ * @param name - the name of the field, or NULL to ignore.
+ * @param fieldType - a compatible field type.
+ * @return The field accessor.
+ */
+ public static FieldAccessor getField(String className, String name, Class fieldType) {
+ return getField(getClass(className), name, fieldType, 0);
+ }
+
+ /**
+ * Retrieve a field accessor for a specific field type and name.
+ *
+ * @param target - the target type.
+ * @param fieldType - a compatible field type.
+ * @param index - the number of compatible fields to skip.
+ * @return The field accessor.
+ */
+ public static FieldAccessor getField(Class> target, Class fieldType, int index) {
+ return getField(target, null, fieldType, index);
+ }
+
+ /**
+ * Retrieve a field accessor for a specific field type and name.
+ *
+ * @param className - lookup name of the class, see {@link #getClass(String)}.
+ * @param fieldType - a compatible field type.
+ * @param index - the number of compatible fields to skip.
+ * @return The field accessor.
+ */
+ public static FieldAccessor getField(String className, Class fieldType, int index) {
+ return getField(getClass(className), fieldType, index);
+ }
+
+ // Common method
+ private static FieldAccessor getField(Class> target, String name, Class fieldType, int index) {
+ for (final Field field : target.getDeclaredFields()) {
+ if ((name == null || field.getName().equals(name)) && fieldType.isAssignableFrom(field.getType()) && index-- <= 0) {
+ field.setAccessible(true);
+
+ // A function for retrieving a specific field value
+ return new FieldAccessor() {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public T get(Object target) {
+ try {
+ return (T) field.get(target);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Cannot access reflection.", e);
+ }
+ }
+
+ @Override
+ public void set(Object target, Object value) {
+ try {
+ field.set(target, value);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Cannot access reflection.", e);
+ }
+ }
+
+ @Override
+ public boolean hasField(Object target) {
+ // target instanceof DeclaringClass
+ return field.getDeclaringClass().isAssignableFrom(target.getClass());
+ }
+ };
+ }
+ }
+
+ // Search in parent classes
+ if (target.getSuperclass() != null)
+ return getField(target.getSuperclass(), name, fieldType, index);
+
+ throw new IllegalArgumentException("Cannot find field with type " + fieldType);
+ }
+
+ /**
+ * Search for the first publicly and privately defined method of the given name and parameter count.
+ *
+ * @param className - lookup name of the class, see {@link #getClass(String)}.
+ * @param methodName - the method name, or NULL to skip.
+ * @param params - the expected parameters.
+ * @return An object that invokes this specific method.
+ * @throws IllegalStateException If we cannot find this method.
+ */
+ public static MethodInvoker getMethod(String className, String methodName, Class>... params) {
+ return getTypedMethod(getClass(className), methodName, null, params);
+ }
+
+ /**
+ * Search for the first publicly and privately defined method of the given name and parameter count.
+ *
+ * @param clazz - a class to start with.
+ * @param methodName - the method name, or NULL to skip.
+ * @param params - the expected parameters.
+ * @return An object that invokes this specific method.
+ * @throws IllegalStateException If we cannot find this method.
+ */
+ public static MethodInvoker getMethod(Class> clazz, String methodName, Class>... params) {
+ return getTypedMethod(clazz, methodName, null, params);
+ }
+
+ /**
+ * Search for the first publicly and privately defined method of the given name and parameter count.
+ *
+ * @param clazz - a class to start with.
+ * @param methodName - the method name, or NULL to skip.
+ * @param returnType - the expected return type, or NULL to ignore.
+ * @param params - the expected parameters.
+ * @return An object that invokes this specific method.
+ * @throws IllegalStateException If we cannot find this method.
+ */
+ public static MethodInvoker getTypedMethod(Class> clazz, String methodName, Class> returnType, Class>... params) {
+ for (final Method method : clazz.getDeclaredMethods()) {
+ if ((methodName == null || method.getName().equals(methodName))
+ && (returnType == null || method.getReturnType().equals(returnType))
+ && 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);
+ }
+ }
+
+ };
+ }
+ }
+
+ // Search in every superclass
+ if (clazz.getSuperclass() != null)
+ return getMethod(clazz.getSuperclass(), methodName, params);
+
+ throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params)));
+ }
+
+ /**
+ * Search for the first publically and privately defined constructor of the given name and parameter count.
+ *
+ * @param className - lookup name of the class, see {@link #getClass(String)}.
+ * @param params - the expected parameters.
+ * @return An object that invokes this constructor.
+ * @throws IllegalStateException If we cannot find this method.
+ */
+ public static ConstructorInvoker getConstructor(String className, Class>... params) {
+ return getConstructor(getClass(className), params);
+ }
+
+ /**
+ * Search for the first publically and privately defined constructor of the given name and parameter count.
+ *
+ * @param clazz - a class to start with.
+ * @param params - the expected parameters.
+ * @return An object that invokes this constructor.
+ * @throws IllegalStateException If we cannot find this method.
+ */
+ public static ConstructorInvoker getConstructor(Class> clazz, Class>... params) {
+ for (final Constructor> constructor : clazz.getDeclaredConstructors()) {
+ 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);
+ }
+ }
+
+ };
+ }
+ }
+
+ throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params)));
+ }
+
+ /**
+ * Retrieve a class from its full name, without knowing its type on compile time.
+ *
+ * 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.
+ */
+ public static Class