From 237071c8e32de9a73ab3f8e7f86fbc2d12ff56b2 Mon Sep 17 00:00:00 2001 From: BarraR3port Date: Tue, 9 Nov 2021 19:48:19 -0300 Subject: [PATCH] Changed all to 1.8.8 --- pom.xml | 11 +- slimeworldmanager-classmodifier/pom.xml | 4 +- slimeworldmanager-importer/pom.xml | 6 +- slimeworldmanager-nms-common/pom.xml | 4 +- slimeworldmanager-nms-v1_10_R1/pom.xml | 42 --- .../swm/nms/v1_10_R1/Converter.java | 111 ------ .../swm/nms/v1_10_R1/CraftCLSMBridge.java | 45 --- .../swm/nms/v1_10_R1/CustomChunkLoader.java | 208 ----------- .../swm/nms/v1_10_R1/CustomDataManager.java | 142 -------- .../swm/nms/v1_10_R1/CustomWorldData.java | 33 -- .../swm/nms/v1_10_R1/CustomWorldServer.java | 98 ----- .../swm/nms/v1_10_R1/NMSSlimeChunk.java | 124 ------- .../swm/nms/v1_10_R1/v1_10_R1SlimeNMS.java | 145 -------- slimeworldmanager-nms-v1_11_R1/pom.xml | 43 --- .../swm/nms/v1_11_R1/Converter.java | 110 ------ .../swm/nms/v1_11_R1/CraftCLSMBridge.java | 45 --- .../swm/nms/v1_11_R1/CustomChunkLoader.java | 208 ----------- .../swm/nms/v1_11_R1/CustomDataManager.java | 142 -------- .../swm/nms/v1_11_R1/CustomWorldData.java | 33 -- .../swm/nms/v1_11_R1/CustomWorldServer.java | 98 ----- .../swm/nms/v1_11_R1/NMSSlimeChunk.java | 124 ------- .../swm/nms/v1_11_R1/v1_11_R1SlimeNMS.java | 145 -------- slimeworldmanager-nms-v1_12_R1/pom.xml | 42 --- .../swm/nms/v1_12_R1/Converter.java | 110 ------ .../swm/nms/v1_12_R1/CraftCLSMBridge.java | 45 --- .../swm/nms/v1_12_R1/CustomChunkLoader.java | 208 ----------- .../swm/nms/v1_12_R1/CustomDataManager.java | 142 -------- .../swm/nms/v1_12_R1/CustomWorldData.java | 33 -- .../swm/nms/v1_12_R1/CustomWorldServer.java | 104 ------ .../swm/nms/v1_12_R1/NMSSlimeChunk.java | 124 ------- .../swm/nms/v1_12_R1/v1_12_R1SlimeNMS.java | 144 -------- slimeworldmanager-nms-v1_13_R1/pom.xml | 42 --- .../swm/nms/v1_13_R1/Converter.java | 223 ------------ .../swm/nms/v1_13_R1/CraftCLSMBridge.java | 45 --- .../swm/nms/v1_13_R1/CustomChunkLoader.java | 265 -------------- .../swm/nms/v1_13_R1/CustomDataManager.java | 134 ------- .../swm/nms/v1_13_R1/CustomWorldData.java | 33 -- .../swm/nms/v1_13_R1/CustomWorldServer.java | 91 ----- .../swm/nms/v1_13_R1/NMSSlimeChunk.java | 123 ------- .../swm/nms/v1_13_R1/v1_13_R1SlimeNMS.java | 146 -------- slimeworldmanager-nms-v1_13_R2/pom.xml | 42 --- .../swm/nms/v1_13_R2/Converter.java | 114 ------ .../swm/nms/v1_13_R2/CraftCLSMBridge.java | 45 --- .../swm/nms/v1_13_R2/CustomChunkLoader.java | 340 ------------------ .../swm/nms/v1_13_R2/CustomDataManager.java | 134 ------- .../swm/nms/v1_13_R2/CustomWorldData.java | 33 -- .../swm/nms/v1_13_R2/CustomWorldServer.java | 97 ----- .../swm/nms/v1_13_R2/NMSSlimeChunk.java | 124 ------- .../swm/nms/v1_13_R2/v1_13_R2SlimeNMS.java | 159 -------- slimeworldmanager-nms-v1_14_R1/pom.xml | 41 --- .../swm/nms/v1_14_R1/Converter.java | 119 ------ .../swm/nms/v1_14_R1/CraftCLSMBridge.java | 87 ----- .../swm/nms/v1_14_R1/CustomNBTStorage.java | 75 ---- .../swm/nms/v1_14_R1/CustomWorldData.java | 37 -- .../swm/nms/v1_14_R1/CustomWorldServer.java | 330 ----------------- .../swm/nms/v1_14_R1/NMSSlimeChunk.java | 124 ------- .../swm/nms/v1_14_R1/v1_14_R1SlimeNMS.java | 141 -------- slimeworldmanager-nms-v1_15_R1/pom.xml | 41 --- .../swm/nms/v1_15_R1/Converter.java | 119 ------ .../swm/nms/v1_15_R1/CraftCLSMBridge.java | 87 ----- .../swm/nms/v1_15_R1/CustomNBTStorage.java | 75 ---- .../swm/nms/v1_15_R1/CustomWorldData.java | 37 -- .../swm/nms/v1_15_R1/CustomWorldServer.java | 316 ---------------- .../swm/nms/v1_15_R1/NMSSlimeChunk.java | 119 ------ .../swm/nms/v1_15_R1/v1_15_R1SlimeNMS.java | 143 -------- slimeworldmanager-nms-v1_9_R1/pom.xml | 42 --- .../swm/nms/v1_9_R1/Converter.java | 111 ------ .../swm/nms/v1_9_R1/CraftCLSMBridge.java | 45 --- .../swm/nms/v1_9_R1/CustomChunkLoader.java | 208 ----------- .../swm/nms/v1_9_R1/CustomDataManager.java | 142 -------- .../swm/nms/v1_9_R1/CustomWorldData.java | 32 -- .../swm/nms/v1_9_R1/CustomWorldServer.java | 92 ----- .../swm/nms/v1_9_R1/NMSSlimeChunk.java | 124 ------- .../swm/nms/v1_9_R1/v1_9_R1SlimeNMS.java | 131 ------- slimeworldmanager-nms-v1_9_R2/pom.xml | 42 --- .../swm/nms/v1_9_R2/Converter.java | 111 ------ .../swm/nms/v1_9_R2/CraftCLSMBridge.java | 45 --- .../swm/nms/v1_9_R2/CustomChunkLoader.java | 208 ----------- .../swm/nms/v1_9_R2/CustomDataManager.java | 142 -------- .../swm/nms/v1_9_R2/CustomWorldData.java | 33 -- .../swm/nms/v1_9_R2/CustomWorldServer.java | 92 ----- .../swm/nms/v1_9_R2/NMSSlimeChunk.java | 124 ------- .../swm/nms/v1_9_R2/v1_9_R2SlimeNMS.java | 132 ------- slimeworldmanager-plugin/pom.xml | 65 +--- .../com/grinderwolf/swm/plugin/SWMPlugin.java | 29 +- 85 files changed, 24 insertions(+), 8880 deletions(-) delete mode 100644 slimeworldmanager-nms-v1_10_R1/pom.xml delete mode 100644 slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/Converter.java delete mode 100644 slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomChunkLoader.java delete mode 100644 slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomDataManager.java delete mode 100644 slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/v1_10_R1SlimeNMS.java delete mode 100644 slimeworldmanager-nms-v1_11_R1/pom.xml delete mode 100644 slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/Converter.java delete mode 100644 slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomChunkLoader.java delete mode 100644 slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomDataManager.java delete mode 100644 slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/v1_11_R1SlimeNMS.java delete mode 100644 slimeworldmanager-nms-v1_12_R1/pom.xml delete mode 100644 slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/Converter.java delete mode 100644 slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomChunkLoader.java delete mode 100644 slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomDataManager.java delete mode 100644 slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/v1_12_R1SlimeNMS.java delete mode 100644 slimeworldmanager-nms-v1_13_R1/pom.xml delete mode 100644 slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/Converter.java delete mode 100644 slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomChunkLoader.java delete mode 100644 slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomDataManager.java delete mode 100644 slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/v1_13_R1SlimeNMS.java delete mode 100644 slimeworldmanager-nms-v1_13_R2/pom.xml delete mode 100644 slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/Converter.java delete mode 100644 slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomChunkLoader.java delete mode 100644 slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomDataManager.java delete mode 100644 slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/v1_13_R2SlimeNMS.java delete mode 100644 slimeworldmanager-nms-v1_14_R1/pom.xml delete mode 100644 slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/Converter.java delete mode 100644 slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomNBTStorage.java delete mode 100644 slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/v1_14_R1SlimeNMS.java delete mode 100644 slimeworldmanager-nms-v1_15_R1/pom.xml delete mode 100644 slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/Converter.java delete mode 100644 slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomNBTStorage.java delete mode 100644 slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/v1_15_R1SlimeNMS.java delete mode 100644 slimeworldmanager-nms-v1_9_R1/pom.xml delete mode 100644 slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/Converter.java delete mode 100644 slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomChunkLoader.java delete mode 100644 slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomDataManager.java delete mode 100644 slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/v1_9_R1SlimeNMS.java delete mode 100644 slimeworldmanager-nms-v1_9_R2/pom.xml delete mode 100644 slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/Converter.java delete mode 100644 slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CraftCLSMBridge.java delete mode 100644 slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomChunkLoader.java delete mode 100644 slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomDataManager.java delete mode 100644 slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomWorldData.java delete mode 100644 slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomWorldServer.java delete mode 100644 slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/NMSSlimeChunk.java delete mode 100644 slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/v1_9_R2SlimeNMS.java diff --git a/pom.xml b/pom.xml index 4c0d7e9..4db3093 100644 --- a/pom.xml +++ b/pom.xml @@ -12,16 +12,7 @@ slimeworldmanager-nms-v1_8_R3 slimeworldmanager-plugin slimeworldmanager-importer - slimeworldmanager-nms-v1_9_R1 - slimeworldmanager-nms-v1_9_R2 - slimeworldmanager-nms-v1_10_R1 - slimeworldmanager-nms-v1_11_R1 - slimeworldmanager-nms-v1_12_R1 - slimeworldmanager-nms-v1_13_R1 - slimeworldmanager-nms-v1_13_R2 - slimeworldmanager-nms-v1_14_R1 slimeworldmanager-classmodifier - slimeworldmanager-nms-v1_15_R1 @@ -46,7 +37,7 @@ org.projectlombok lombok - 1.18.8 + 1.18.22 provided diff --git a/slimeworldmanager-classmodifier/pom.xml b/slimeworldmanager-classmodifier/pom.xml index 4c7e694..173b6f1 100644 --- a/slimeworldmanager-classmodifier/pom.xml +++ b/slimeworldmanager-classmodifier/pom.xml @@ -21,7 +21,7 @@ org.javassist javassist - 3.25.0-GA + 3.28.0-GA com.mojang @@ -38,7 +38,7 @@ org.yaml snakeyaml - 1.24 + 1.29 diff --git a/slimeworldmanager-importer/pom.xml b/slimeworldmanager-importer/pom.xml index 3db0057..b2a56aa 100644 --- a/slimeworldmanager-importer/pom.xml +++ b/slimeworldmanager-importer/pom.xml @@ -22,17 +22,17 @@ com.google.code.gson gson - 2.8.5 + 2.8.9 com.google.guava guava - 26.0-jre + 31.0.1-jre com.github.luben zstd-jni - 1.4.1-1 + 1.5.0-4 com.github.tomas-langer diff --git a/slimeworldmanager-nms-common/pom.xml b/slimeworldmanager-nms-common/pom.xml index cf8b99b..8d74e2b 100644 --- a/slimeworldmanager-nms-common/pom.xml +++ b/slimeworldmanager-nms-common/pom.xml @@ -21,13 +21,13 @@ com.github.luben zstd-jni - 1.4.1-1 + 1.5.0-4 provided org.spigotmc spigot-api - 1.13-R0.1-SNAPSHOT + 1.8.8-R0.1-SNAPSHOT provided diff --git a/slimeworldmanager-nms-v1_10_R1/pom.xml b/slimeworldmanager-nms-v1_10_R1/pom.xml deleted file mode 100644 index 6834b1a..0000000 --- a/slimeworldmanager-nms-v1_10_R1/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_10_R1 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - com.destroystokyo.paper - paper - 1.10.2-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/Converter.java b/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/Converter.java deleted file mode 100644 index e444931..0000000 --- a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/Converter.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.grinderwolf.swm.nms.v1_10_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import net.minecraft.server.v1_10_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_10_R1.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_10_R1.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_10_R1.NibbleArray array) { - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return new NBTTagByte(((ByteTag) tag).getValue()); - case TAG_SHORT: - return new NBTTagShort(((ShortTag) tag).getValue()); - case TAG_INT: - return new NBTTagInt(((IntTag) tag).getValue()); - case TAG_LONG: - return new NBTTagLong(((LongTag) tag).getValue()); - case TAG_FLOAT: - return new NBTTagFloat(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return new NBTTagDouble(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return new NBTTagString(((StringTag) tag).getValue()); - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).g()); - case 2: - return new ShortTag(name, ((NBTTagShort) base).f()); - case 3: - return new IntTag(name, ((NBTTagInt) base).e()); - case 4: - return new LongTag(name, ((NBTTagLong) base).d()); - case 5: - return new FloatTag(name, ((NBTTagFloat) base).i()); - case 6: - return new DoubleTag(name, ((NBTTagDouble) base).h()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).c()); - case 8: - return new StringTag(name, ((NBTTagString) base).c_()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (int i = 0; i < originalList.size(); i++) { - NBTBase entry = originalList.h(i); - list.add(convertTag("", entry)); - } - - return new ListTag(name, TagType.getById(originalList.g()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.c()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).d()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } - -} diff --git a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CraftCLSMBridge.java deleted file mode 100644 index d419b44..0000000 --- a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CraftCLSMBridge.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.grinderwolf.swm.nms.v1_10_R1; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_10_R1.WorldServer; - -@RequiredArgsConstructor -public class CraftCLSMBridge implements CLSMBridge { - - private final v1_10_R1SlimeNMS nmsInstance; - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_10_R1SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomChunkLoader.java b/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomChunkLoader.java deleted file mode 100644 index 7a01b7c..0000000 --- a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomChunkLoader.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.grinderwolf.swm.nms.v1_10_R1; - -import com.flowpowered.nbt.CompoundMap; -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_10_R1.Chunk; -import net.minecraft.server.v1_10_R1.ChunkSection; -import net.minecraft.server.v1_10_R1.Entity; -import net.minecraft.server.v1_10_R1.EntityTypes; -import net.minecraft.server.v1_10_R1.IChunkLoader; -import net.minecraft.server.v1_10_R1.NBTTagCompound; -import net.minecraft.server.v1_10_R1.TileEntity; -import net.minecraft.server.v1_10_R1.World; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.*; - -@RequiredArgsConstructor -public class CustomChunkLoader implements IChunkLoader { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final CraftSlimeWorld world; - - void loadAllChunks(CustomWorldServer server) { - for (SlimeChunk chunk : new ArrayList<>(world.getChunks().values())) { - Chunk nmsChunk = createChunk(server, chunk); - world.updateChunk(new NMSSlimeChunk(nmsChunk)); - } - } - - private Chunk createChunk(CustomWorldServer server, SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + world.getName()); - - Chunk nmsChunk = new Chunk(server, x, z); - - nmsChunk.d(true); - nmsChunk.e(true); - - CompoundTag heightMapsCompound = chunk.getHeightMaps(); - int[] heightMap = heightMapsCompound.getIntArrayValue("heightMap").get(); - - nmsChunk.a(heightMap); - - // Load chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + x + ", " + z + ") on world " + world.getName()); - ChunkSection[] sections = new ChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null) { - ChunkSection section = new ChunkSection(sectionId << 4, true); - NibbleArray data = slimeSection.getData(); - byte[] blocks = slimeSection.getBlocks(); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + x + ", " + z + ") - World " + world.getName() + ":"); - LOGGER.debug("Blocks:"); - LOGGER.debug(blocks); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - section.getBlocks().a(blocks, Converter.convertArray(data), new net.minecraft.server.v1_10_R1.NibbleArray()); - - if (slimeSection.getBlockLight() != null) { - section.a(Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - section.b(Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - nmsChunk.a(sections); - - // Biomes - nmsChunk.a(toByteArray(chunk.getBiomes())); - - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List tileEntities = chunk.getTileEntities(); - int loadedEntities = 0; - - if (tileEntities != null) { - for (CompoundTag tag : tileEntities) { - TileEntity entity = TileEntity.a(server, (NBTTagCompound) Converter.convertTag(tag)); - - if (entity != null) { - nmsChunk.a(entity); - loadedEntities++; - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List entities = chunk.getEntities(); - loadedEntities = 0; - - if (entities != null) { - for (CompoundTag tag : entities) { - loadEntity(tag, server, nmsChunk); - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - LOGGER.debug("Loaded chunk (" + x + ", " + z + ") on world " + world.getName()); - - return nmsChunk; - } - - private byte[] toByteArray(int[] ints) { - ByteBuffer buf = ByteBuffer.allocate(ints.length * 4).order(ByteOrder.LITTLE_ENDIAN); - buf.asIntBuffer().put(ints); - - return buf.array(); - } - - private Entity loadEntity(CompoundTag tag, World world, Chunk chunk) { - Entity entity = EntityTypes.a((NBTTagCompound) Converter.convertTag(tag), world); - chunk.g(true); - - if (entity != null) { - chunk.a(entity); - - CompoundMap map = tag.getValue(); - - if (map.containsKey("Passengers")) { - List passengersList = (List) map.get("Passengers").getValue(); - - for (CompoundTag passengerTag : passengersList) { - Entity passenger = loadEntity(passengerTag, world, chunk); - - if (passengerTag != null) { - passenger.a(entity, true); - } - } - } - } - - return entity; - } - - // Load chunk - @Override - public Chunk a(World nmsWorld, int x, int z) { - SlimeChunk slimeChunk = world.getChunk(x, z); - Chunk chunk; - - if (slimeChunk == null) { - chunk = new Chunk(nmsWorld, x, z); - - chunk.d(true); - chunk.e(true); - } else if (slimeChunk instanceof NMSSlimeChunk) { - chunk = ((NMSSlimeChunk) slimeChunk).getChunk(); - } else { // All SlimeChunk objects should be converted to NMSSlimeChunks when loading the world - throw new IllegalStateException("Chunk (" + x + ", " + z + ") has not been converted to a NMSSlimeChunk object!"); - } - - return chunk; - } - - // Save chunk - @Override - public void a(World world, Chunk chunk) { - SlimeChunk slimeChunk = this.world.getChunk(chunk.locX, chunk.locZ); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk(chunk); - } else { - this.world.updateChunk(new NMSSlimeChunk(chunk)); - } - } - - - // Save all chunks - @Override - public void b() { - - } - - // Does literally nothing - @Override - public void b(World world, Chunk chunk) { } - - // Does literally nothing - @Override - public void a() { } -} diff --git a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomDataManager.java b/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomDataManager.java deleted file mode 100644 index 43b0f11..0000000 --- a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomDataManager.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.grinderwolf.swm.nms.v1_10_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.StringTag; -import com.flowpowered.nbt.Tag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_10_R1.EntityHuman; -import net.minecraft.server.v1_10_R1.GameRules; -import net.minecraft.server.v1_10_R1.IChunkLoader; -import net.minecraft.server.v1_10_R1.NBTTagCompound; -import net.minecraft.server.v1_10_R1.WorldData; -import net.minecraft.server.v1_10_R1.WorldNBTStorage; -import net.minecraft.server.v1_10_R1.WorldProvider; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - -@Getter -public class CustomDataManager extends WorldNBTStorage { - - private static final Map defaultValues; - - static { - GameRules emptyRules = new GameRules(); - String[] rules = emptyRules.getGameRules(); - - defaultValues = Arrays.stream(rules).collect(Collectors.toMap((rule) -> rule, emptyRules::get)); - } - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private final CustomChunkLoader chunkLoader; - private WorldData worldData; - - // When unloading a world, Spigot tries to remove the region file from its cache. - // To do so, it casts the world's IDataManager to a WorldNBTStorage, to be able - // to use the getDirectory() method. Thanks to this, we have to create a custom - // WorldNBTStorage with a fake file instead of just implementing the IDataManager interface - // - // Thanks Spigot! - CustomDataManager(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), false, null); - - // The WorldNBTStorage automatically creates some files inside the base dir, so we have to delete them - // (Thanks again Spigot) - - // Can't just access the baseDir field inside WorldNBTStorage cause it's private :P - File baseDir = new File("temp_" + world.getName(), world.getName()); - new File(baseDir, "session.lock").delete(); - new File(baseDir, "data").delete(); - - baseDir.delete(); - baseDir.getParentFile().delete(); - - this.world = world; - this.chunkLoader = new CustomChunkLoader((CraftSlimeWorld) world); - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override public void checkSession() { } - - @Override - public IChunkLoader createChunkLoader(WorldProvider worldProvider) { - return chunkLoader; - } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.w().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - // Remove default values to save space - for (Map.Entry> entry : new ArrayList<>(gameRules.getValue().entrySet())) { - String rule = entry.getKey(); - StringTag valueTag = (StringTag) entry.getValue(); - String defaultValue = defaultValues.get(rule); - - if (valueTag.getValue().equalsIgnoreCase(defaultValue)) { - gameRules.getValue().remove(rule); - } - } - - // Maybe all the gamerules stored were the default values - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public void a() { - - } - - @Override - public File getDataFile(String s) { - return null; - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} diff --git a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomWorldData.java b/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomWorldData.java deleted file mode 100644 index 2c6aa96..0000000 --- a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomWorldData.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.grinderwolf.swm.nms.v1_10_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_10_R1.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.w().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } - -} diff --git a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomWorldServer.java b/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomWorldServer.java deleted file mode 100644 index 1cd86e9..0000000 --- a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/CustomWorldServer.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.grinderwolf.swm.nms.v1_10_R1; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_10_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, IDataManager dataManager, int dimension) { - super(MinecraftServer.getServer(), dataManager, dataManager.getWorldData(), dimension, MinecraftServer.getServer().methodProfiler, - World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()), null); - - b(); - this.slimeWorld = world; - this.tracker = new EntityTracker(this); - addIWorldAccess(new WorldManager(MinecraftServer.getServer(), this)); - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - // Load all chunks - CustomChunkLoader chunkLoader = ((CustomDataManager) this.getDataManager()).getChunkLoader(); - chunkLoader.loadAllChunks(this); - - // Disable auto save period as it's constantly saving the world - if (v1_10_R1SlimeNMS.IS_PAPER) { - this.paperConfig.autoSavePeriod = 0; - } - } - - @Override - public void save(boolean forceSave, IProgressUpdate progressUpdate) throws ExceptionWorldConflict { - if (!slimeWorld.isReadOnly()) { - super.save(forceSave, progressUpdate); - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the slimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - -} diff --git a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/NMSSlimeChunk.java deleted file mode 100644 index 6915d46..0000000 --- a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/NMSSlimeChunk.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.grinderwolf.swm.nms.v1_10_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_10_R1.*; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.locX; - } - - @Override - public int getZ() { - return chunk.locZ; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.a()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(section.getEmittedLightArray()); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(section.getSkyLightArray()); - - // Block Data - byte[] blocks = new byte[4096]; - - net.minecraft.server.v1_10_R1.NibbleArray minecraftBlockDataArray = new net.minecraft.server.v1_10_R1.NibbleArray(); - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - dataPaletteBlock.exportData(blocks, minecraftBlockDataArray); - - NibbleArray blockDataArray = Converter.convertArray(minecraftBlockDataArray); - - sections[sectionId] = new CraftSlimeChunkSection(blocks, blockDataArray, null, null, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - CompoundTag heightMapsCompound = new CompoundTag("", new CompoundMap()); - heightMapsCompound.getValue().put("heightMap", new IntArrayTag("heightMap", chunk.heightMap)); - - return heightMapsCompound; - } - - @Override - public int[] getBiomes() { - return toIntArray(chunk.getBiomeIndex()); - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.g(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } - - private static int[] toIntArray(byte[] buf) { - ByteBuffer buffer = ByteBuffer.wrap(buf).order(ByteOrder.BIG_ENDIAN); - int[] ret = new int[buf.length / 4]; - - buffer.asIntBuffer().get(ret); - - return ret; - } -} diff --git a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/v1_10_R1SlimeNMS.java b/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/v1_10_R1SlimeNMS.java deleted file mode 100644 index 70912b6..0000000 --- a/slimeworldmanager-nms-v1_10_R1/src/main/java/com/grinderwolf/swm/nms/v1_10_R1/v1_10_R1SlimeNMS.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.grinderwolf.swm.nms.v1_10_R1; - -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import lombok.Getter; -import net.minecraft.server.v1_10_R1.MinecraftServer; -import net.minecraft.server.v1_10_R1.WorldServer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_10_R1SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - public static final boolean IS_PAPER; - - static { - boolean paper = true; - - try { - Class.forName("com.destroystokyo.paper.PaperWorldConfig"); - } catch (ClassNotFoundException e) { - paper = false; - } - - IS_PAPER = paper; - } - - private final byte worldVersion = 0x02; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private WorldServer defaultWorld; - private WorldServer defaultNetherWorld; - private WorldServer defaultEndWorld; - - public v1_10_R1SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomDataManager(normalWorld), 0); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomDataManager(netherWorld), env.getId()); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomDataManager(endWorld), env.getId()); - } - - loadingDefaultWorlds = false; - } - - @Override - public Object createNMSWorld(SlimeWorld world) { - CustomDataManager dataManager = new CustomDataManager(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worlds.size(); - boolean used = false; - - do { - for (WorldServer server : mcServer.worlds) { - used = server.dimension == dimension; - - if (used) { - dimension++; - break; - } - } - } while (used); - - return new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimension); - } - - @Override - public void generateWorld(SlimeWorld world) { - addWorldToServerList(createNMSWorld(world)); - } - - @Override - public void addWorldToServerList(Object worldObject) { - if (!(worldObject instanceof WorldServer)) { - throw new IllegalArgumentException("World object must be an instance of WorldServer!"); - } - - CustomWorldServer server = (CustomWorldServer) worldObject; - String worldName = server.getWorldData().getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - MinecraftServer mcServer = MinecraftServer.getServer(); - - mcServer.server.addWorld(server.getWorld()); - mcServer.worlds.add(server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - - return worldServer.getSlimeWorld(); - } -} diff --git a/slimeworldmanager-nms-v1_11_R1/pom.xml b/slimeworldmanager-nms-v1_11_R1/pom.xml deleted file mode 100644 index 3d2e9df..0000000 --- a/slimeworldmanager-nms-v1_11_R1/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_11_R1 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - com.destroystokyo.paper - paper - 1.11.2-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/Converter.java b/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/Converter.java deleted file mode 100644 index dbe3da3..0000000 --- a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/Converter.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.grinderwolf.swm.nms.v1_11_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import net.minecraft.server.v1_11_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_11_R1.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_11_R1.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_11_R1.NibbleArray array) { - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return new NBTTagByte(((ByteTag) tag).getValue()); - case TAG_SHORT: - return new NBTTagShort(((ShortTag) tag).getValue()); - case TAG_INT: - return new NBTTagInt(((IntTag) tag).getValue()); - case TAG_LONG: - return new NBTTagLong(((LongTag) tag).getValue()); - case TAG_FLOAT: - return new NBTTagFloat(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return new NBTTagDouble(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return new NBTTagString(((StringTag) tag).getValue()); - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).g()); - case 2: - return new ShortTag(name, ((NBTTagShort) base).f()); - case 3: - return new IntTag(name, ((NBTTagInt) base).e()); - case 4: - return new LongTag(name, ((NBTTagLong) base).d()); - case 5: - return new FloatTag(name, ((NBTTagFloat) base).i()); - case 6: - return new DoubleTag(name, ((NBTTagDouble) base).asDouble()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).c()); - case 8: - return new StringTag(name, ((NBTTagString) base).c_()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (int i = 0; i < originalList.size(); i++) { - NBTBase entry = originalList.h(i); - list.add(convertTag("", entry)); - } - - return new ListTag<>(name, TagType.getById(originalList.g()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.c()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).d()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } -} diff --git a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CraftCLSMBridge.java deleted file mode 100644 index d6f8d75..0000000 --- a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CraftCLSMBridge.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.grinderwolf.swm.nms.v1_11_R1; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_11_R1.WorldServer; - -@RequiredArgsConstructor -public class CraftCLSMBridge implements CLSMBridge { - - private final v1_11_R1SlimeNMS nmsInstance; - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_11_R1SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomChunkLoader.java b/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomChunkLoader.java deleted file mode 100644 index 5efb10b..0000000 --- a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomChunkLoader.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.grinderwolf.swm.nms.v1_11_R1; - -import com.flowpowered.nbt.CompoundMap; -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_11_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; - -@RequiredArgsConstructor -public class CustomChunkLoader implements IChunkLoader { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final CraftSlimeWorld world; - - void loadAllChunks(CustomWorldServer server) { - for (SlimeChunk chunk : new ArrayList<>(world.getChunks().values())) { - Chunk nmsChunk = createChunk(server, chunk); - world.updateChunk(new NMSSlimeChunk(nmsChunk)); - } - } - - private Chunk createChunk(CustomWorldServer server, SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + world.getName()); - - Chunk nmsChunk = new Chunk(server, x, z); - - nmsChunk.d(true); - nmsChunk.e(true); - - CompoundTag heightMapsCompound = chunk.getHeightMaps(); - int[] heightMap = heightMapsCompound.getIntArrayValue("heightMap").get(); - - nmsChunk.a(heightMap); - - // Load chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + x + ", " + z + ") on world " + world.getName()); - ChunkSection[] sections = new ChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null) { - ChunkSection section = new ChunkSection(sectionId << 4, true); - NibbleArray data = slimeSection.getData(); - byte[] blocks = slimeSection.getBlocks(); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + x + ", " + z + ") - World " + world.getName() + ":"); - LOGGER.debug("Blocks:"); - LOGGER.debug(blocks); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - section.getBlocks().a(blocks, Converter.convertArray(data), new net.minecraft.server.v1_11_R1.NibbleArray()); - - if (slimeSection.getBlockLight() != null) { - section.a(Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - section.b(Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - nmsChunk.a(sections); - - // Biomes - nmsChunk.a(toByteArray(chunk.getBiomes())); - - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List tileEntities = chunk.getTileEntities(); - int loadedEntities = 0; - - if (tileEntities != null) { - for (CompoundTag tag : tileEntities) { - TileEntity entity = TileEntity.a(server, (NBTTagCompound) Converter.convertTag(tag)); - - if (entity != null) { - nmsChunk.a(entity); - loadedEntities++; - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List entities = chunk.getEntities(); - loadedEntities = 0; - - if (entities != null) { - for (CompoundTag tag : entities) { - loadEntity(tag, server, nmsChunk); - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - LOGGER.debug("Loaded chunk (" + x + ", " + z + ") on world " + world.getName()); - - return nmsChunk; - } - - private byte[] toByteArray(int[] ints) { - ByteBuffer buf = ByteBuffer.allocate(ints.length * 4).order(ByteOrder.LITTLE_ENDIAN); - buf.asIntBuffer().put(ints); - - return buf.array(); - } - - private Entity loadEntity(CompoundTag tag, World world, Chunk chunk) { - Entity entity = EntityTypes.a((NBTTagCompound) Converter.convertTag(tag), world); - chunk.g(true); - - if (entity != null) { - chunk.a(entity); - - CompoundMap map = tag.getValue(); - - if (map.containsKey("Passengers")) { - List passengersList = (List) map.get("Passengers").getValue(); - - for (CompoundTag passengerTag : passengersList) { - Entity passenger = loadEntity(passengerTag, world, chunk); - - if (passengerTag != null) { - passenger.a(entity, true); - } - } - } - } - - return entity; - } - - // Load chunk - @Override - public Chunk a(World nmsWorld, int x, int z) { - SlimeChunk slimeChunk = world.getChunk(x, z); - Chunk chunk; - - if (slimeChunk == null) { - chunk = new Chunk(nmsWorld, x, z); - - chunk.d(true); - chunk.e(true); - } else if (slimeChunk instanceof NMSSlimeChunk) { - chunk = ((NMSSlimeChunk) slimeChunk).getChunk(); - } else { // All SlimeChunk objects should be converted to NMSSlimeChunks when loading the world - throw new IllegalStateException("Chunk (" + x + ", " + z + ") has not been converted to a NMSSlimeChunk object!"); - } - - return chunk; - } - - // Save chunk - @Override - public void a(World world, Chunk chunk) { - SlimeChunk slimeChunk = this.world.getChunk(chunk.locX, chunk.locZ); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk(chunk); - } else { - this.world.updateChunk(new NMSSlimeChunk(chunk)); - } - } - - - // Save all chunks - @Override - public void b() { - - } - - // Chunk exists - @Override - public boolean a(int i, int i1) { - return true; - } - - // Does literally nothing - @Override - public void b(World world, Chunk chunk) { } - - // Does literally nothing - @Override - public void a() { } -} diff --git a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomDataManager.java b/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomDataManager.java deleted file mode 100644 index 4c26f8c..0000000 --- a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomDataManager.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.grinderwolf.swm.nms.v1_11_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.StringTag; -import com.flowpowered.nbt.Tag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_11_R1.EntityHuman; -import net.minecraft.server.v1_11_R1.GameRules; -import net.minecraft.server.v1_11_R1.IChunkLoader; -import net.minecraft.server.v1_11_R1.NBTTagCompound; -import net.minecraft.server.v1_11_R1.WorldData; -import net.minecraft.server.v1_11_R1.WorldNBTStorage; -import net.minecraft.server.v1_11_R1.WorldProvider; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - -@Getter -public class CustomDataManager extends WorldNBTStorage { - - private static final Map defaultValues; - - static { - GameRules emptyRules = new GameRules(); - String[] rules = emptyRules.getGameRules(); - - defaultValues = Arrays.stream(rules).collect(Collectors.toMap((rule) -> rule, emptyRules::get)); - } - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private final CustomChunkLoader chunkLoader; - private WorldData worldData; - - // When unloading a world, Spigot tries to remove the region file from its cache. - // To do so, it casts the world's IDataManager to a WorldNBTStorage, to be able - // to use the getDirectory() method. Thanks to this, we have to create a custom - // WorldNBTStorage with a fake file instead of just implementing the IDataManager interface - // - // Thanks Spigot! - CustomDataManager(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), false, null); - - // The WorldNBTStorage automatically creates some files inside the base dir, so we have to delete them - // (Thanks again Spigot) - - // Can't just access the baseDir field inside WorldNBTStorage cause it's private :P - File baseDir = new File("temp_" + world.getName(), world.getName()); - new File(baseDir, "session.lock").delete(); - new File(baseDir, "data").delete(); - - baseDir.delete(); - baseDir.getParentFile().delete(); - - this.world = world; - this.chunkLoader = new CustomChunkLoader((CraftSlimeWorld) world); - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override public void checkSession() { } - - @Override - public IChunkLoader createChunkLoader(WorldProvider worldProvider) { - return chunkLoader; - } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.w().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - // Remove default values to save space - for (Map.Entry> entry : new ArrayList<>(gameRules.getValue().entrySet())) { - String rule = entry.getKey(); - StringTag valueTag = (StringTag) entry.getValue(); - String defaultValue = defaultValues.get(rule); - - if (valueTag.getValue().equalsIgnoreCase(defaultValue)) { - gameRules.getValue().remove(rule); - } - } - - // Maybe all the gamerules stored were the default values - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public void a() { - - } - - @Override - public File getDataFile(String s) { - return null; - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} diff --git a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomWorldData.java b/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomWorldData.java deleted file mode 100644 index 490145c..0000000 --- a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomWorldData.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.grinderwolf.swm.nms.v1_11_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_11_R1.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.w().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } - -} diff --git a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomWorldServer.java b/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomWorldServer.java deleted file mode 100644 index a4fa5bd..0000000 --- a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/CustomWorldServer.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.grinderwolf.swm.nms.v1_11_R1; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_11_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, IDataManager dataManager, int dimension) { - super(MinecraftServer.getServer(), dataManager, dataManager.getWorldData(), dimension, MinecraftServer.getServer().methodProfiler, - World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()), null); - - b(); - this.slimeWorld = world; - this.tracker = new EntityTracker(this); - addIWorldAccess(new WorldManager(MinecraftServer.getServer(), this)); - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - // Load all chunks - CustomChunkLoader chunkLoader = ((CustomDataManager) this.getDataManager()).getChunkLoader(); - chunkLoader.loadAllChunks(this); - - // Disable auto save period as it's constantly saving the world - if (v1_11_R1SlimeNMS.IS_PAPER) { - this.paperConfig.autoSavePeriod = 0; - } - } - - @Override - public void save(boolean forceSave, IProgressUpdate progressUpdate) throws ExceptionWorldConflict { - if (!slimeWorld.isReadOnly()) { - super.save(forceSave, progressUpdate); - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the slimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - -} diff --git a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/NMSSlimeChunk.java deleted file mode 100644 index 27e7896..0000000 --- a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/NMSSlimeChunk.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.grinderwolf.swm.nms.v1_11_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_11_R1.*; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.locX; - } - - @Override - public int getZ() { - return chunk.locZ; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.a()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(section.getEmittedLightArray()); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(section.getSkyLightArray()); - - // Block Data - byte[] blocks = new byte[4096]; - - net.minecraft.server.v1_11_R1.NibbleArray minecraftBlockDataArray = new net.minecraft.server.v1_11_R1.NibbleArray(); - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - dataPaletteBlock.exportData(blocks, minecraftBlockDataArray); - - NibbleArray blockDataArray = Converter.convertArray(minecraftBlockDataArray); - - sections[sectionId] = new CraftSlimeChunkSection(blocks, blockDataArray, null, null, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - CompoundTag heightMapsCompound = new CompoundTag("", new CompoundMap()); - heightMapsCompound.getValue().put("heightMap", new IntArrayTag("heightMap", chunk.heightMap)); - - return heightMapsCompound; - } - - @Override - public int[] getBiomes() { - return toIntArray(chunk.getBiomeIndex()); - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.g(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } - - private static int[] toIntArray(byte[] buf) { - ByteBuffer buffer = ByteBuffer.wrap(buf).order(ByteOrder.BIG_ENDIAN); - int[] ret = new int[buf.length / 4]; - - buffer.asIntBuffer().get(ret); - - return ret; - } -} diff --git a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/v1_11_R1SlimeNMS.java b/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/v1_11_R1SlimeNMS.java deleted file mode 100644 index 7994f21..0000000 --- a/slimeworldmanager-nms-v1_11_R1/src/main/java/com/grinderwolf/swm/nms/v1_11_R1/v1_11_R1SlimeNMS.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.grinderwolf.swm.nms.v1_11_R1; - -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import lombok.Getter; -import net.minecraft.server.v1_11_R1.MinecraftServer; -import net.minecraft.server.v1_11_R1.WorldServer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_11_R1SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - public static final boolean IS_PAPER; - - static { - boolean paper = true; - - try { - Class.forName("com.destroystokyo.paper.PaperWorldConfig"); - } catch (ClassNotFoundException e) { - paper = false; - } - - IS_PAPER = paper; - } - - private final byte worldVersion = 0x03; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private WorldServer defaultWorld; - private WorldServer defaultNetherWorld; - private WorldServer defaultEndWorld; - - public v1_11_R1SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomDataManager(normalWorld), 0); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomDataManager(netherWorld), env.getId()); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomDataManager(endWorld), env.getId()); - } - - loadingDefaultWorlds = false; - } - - @Override - public Object createNMSWorld(SlimeWorld world) { - CustomDataManager dataManager = new CustomDataManager(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worlds.size(); - boolean used = false; - - do { - for (WorldServer server : mcServer.worlds) { - used = server.dimension == dimension; - - if (used) { - dimension++; - break; - } - } - } while (used); - - return new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimension); - } - - @Override - public void generateWorld(SlimeWorld world) { - addWorldToServerList(createNMSWorld(world)); - } - - @Override - public void addWorldToServerList(Object worldObject) { - if (!(worldObject instanceof WorldServer)) { - throw new IllegalArgumentException("World object must be an instance of WorldServer!"); - } - - CustomWorldServer server = (CustomWorldServer) worldObject; - String worldName = server.getWorldData().getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - MinecraftServer mcServer = MinecraftServer.getServer(); - - mcServer.server.addWorld(server.getWorld()); - mcServer.worlds.add(server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - - return worldServer.getSlimeWorld(); - } -} diff --git a/slimeworldmanager-nms-v1_12_R1/pom.xml b/slimeworldmanager-nms-v1_12_R1/pom.xml deleted file mode 100644 index f79e91c..0000000 --- a/slimeworldmanager-nms-v1_12_R1/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_12_R1 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - com.destroystokyo.paper - paper - 1.12.2-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/Converter.java b/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/Converter.java deleted file mode 100644 index cfad79c..0000000 --- a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/Converter.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.grinderwolf.swm.nms.v1_12_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import net.minecraft.server.v1_12_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_12_R1.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_12_R1.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_12_R1.NibbleArray array) { - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return new NBTTagByte(((ByteTag) tag).getValue()); - case TAG_SHORT: - return new NBTTagShort(((ShortTag) tag).getValue()); - case TAG_INT: - return new NBTTagInt(((IntTag) tag).getValue()); - case TAG_LONG: - return new NBTTagLong(((LongTag) tag).getValue()); - case TAG_FLOAT: - return new NBTTagFloat(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return new NBTTagDouble(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return new NBTTagString(((StringTag) tag).getValue()); - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).g()); - case 2: - return new ShortTag(name, ((NBTTagShort) base).f()); - case 3: - return new IntTag(name, ((NBTTagInt) base).e()); - case 4: - return new LongTag(name, ((NBTTagLong) base).d()); - case 5: - return new FloatTag(name, ((NBTTagFloat) base).i()); - case 6: - return new DoubleTag(name, ((NBTTagDouble) base).asDouble()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).c()); - case 8: - return new StringTag(name, ((NBTTagString) base).c_()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (int i = 0; i < originalList.size(); i++) { - NBTBase entry = originalList.i(i); - list.add(convertTag("", entry)); - } - - return new ListTag(name, TagType.getById(originalList.g()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.c()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).d()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } -} diff --git a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CraftCLSMBridge.java deleted file mode 100644 index 7ea9d14..0000000 --- a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CraftCLSMBridge.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.grinderwolf.swm.nms.v1_12_R1; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_12_R1.WorldServer; - -@RequiredArgsConstructor -public class CraftCLSMBridge implements CLSMBridge { - - private final v1_12_R1SlimeNMS nmsInstance; - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_12_R1SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomChunkLoader.java b/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomChunkLoader.java deleted file mode 100644 index 0b9e8d3..0000000 --- a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomChunkLoader.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.grinderwolf.swm.nms.v1_12_R1; - -import com.flowpowered.nbt.CompoundMap; -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_12_R1.Chunk; -import net.minecraft.server.v1_12_R1.ChunkSection; -import net.minecraft.server.v1_12_R1.Entity; -import net.minecraft.server.v1_12_R1.EntityTypes; -import net.minecraft.server.v1_12_R1.IChunkLoader; -import net.minecraft.server.v1_12_R1.NBTTagCompound; -import net.minecraft.server.v1_12_R1.TileEntity; -import net.minecraft.server.v1_12_R1.World; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.*; - -@RequiredArgsConstructor -public class CustomChunkLoader implements IChunkLoader { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final CraftSlimeWorld world; - - void loadAllChunks(CustomWorldServer server) { - for (SlimeChunk chunk : new ArrayList<>(world.getChunks().values())) { - Chunk nmsChunk = createChunk(server, chunk); - world.updateChunk(new NMSSlimeChunk(nmsChunk)); - } - } - - private Chunk createChunk(CustomWorldServer server, SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + world.getName()); - - Chunk nmsChunk = new Chunk(server, x, z); - - nmsChunk.d(true); - nmsChunk.e(true); - - CompoundTag heightMapsCompound = chunk.getHeightMaps(); - int[] heightMap = heightMapsCompound.getIntArrayValue("heightMap").get(); - - nmsChunk.a(heightMap); - - // Load chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + x + ", " + z + ") on world " + world.getName()); - ChunkSection[] sections = new ChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null) { - ChunkSection section = new ChunkSection(sectionId << 4, true); - NibbleArray data = slimeSection.getData(); - byte[] blocks = slimeSection.getBlocks(); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + x + ", " + z + ") - World " + world.getName() + ":"); - LOGGER.debug("Blocks:"); - LOGGER.debug(blocks); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - section.getBlocks().a(blocks, Converter.convertArray(data), new net.minecraft.server.v1_12_R1.NibbleArray()); - - if (slimeSection.getBlockLight() != null) { - section.a(Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - section.b(Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - nmsChunk.a(sections); - - // Biomes - nmsChunk.a(toByteArray(chunk.getBiomes())); - - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List tileEntities = chunk.getTileEntities(); - int loadedEntities = 0; - - if (tileEntities != null) { - for (CompoundTag tag : tileEntities) { - TileEntity entity = TileEntity.create(server, (NBTTagCompound) Converter.convertTag(tag)); - - if (entity != null) { - nmsChunk.a(entity); - loadedEntities++; - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List entities = chunk.getEntities(); - loadedEntities = 0; - - if (entities != null) { - for (CompoundTag tag : entities) { - loadEntity(tag, server, nmsChunk); - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - LOGGER.debug("Loaded chunk (" + x + ", " + z + ") on world " + world.getName()); - - return nmsChunk; - } - - private byte[] toByteArray(int[] ints) { - ByteBuffer buf = ByteBuffer.allocate(ints.length * 4).order(ByteOrder.LITTLE_ENDIAN); - buf.asIntBuffer().put(ints); - - return buf.array(); - } - - private Entity loadEntity(CompoundTag tag, World world, Chunk chunk) { - Entity entity = EntityTypes.a((NBTTagCompound) Converter.convertTag(tag), world); - chunk.g(true); - - if (entity != null) { - chunk.a(entity); - - CompoundMap map = tag.getValue(); - - if (map.containsKey("Passengers")) { - List passengersList = (List) map.get("Passengers").getValue(); - - for (CompoundTag passengerTag : passengersList) { - Entity passenger = loadEntity(passengerTag, world, chunk); - - if (passengerTag != null) { - passenger.a(entity, true); - } - } - } - } - - return entity; - } - - // Load chunk - @Override - public Chunk a(World nmsWorld, int x, int z) { - SlimeChunk slimeChunk = world.getChunk(x, z); - Chunk chunk; - - if (slimeChunk == null) { - chunk = new Chunk(nmsWorld, x, z); - - chunk.d(true); - chunk.e(true); - } else if (slimeChunk instanceof NMSSlimeChunk) { - chunk = ((NMSSlimeChunk) slimeChunk).getChunk(); - } else { // All SlimeChunk objects should be converted to NMSSlimeChunks when loading the world - throw new IllegalStateException("Chunk (" + x + ", " + z + ") has not been converted to a NMSSlimeChunk object!"); - } - - return chunk; - } - - @Override - public void saveChunk(World world, Chunk chunk, boolean unloaded) { - SlimeChunk slimeChunk = this.world.getChunk(chunk.locX, chunk.locZ); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk(chunk); - } else { - this.world.updateChunk(new NMSSlimeChunk(chunk)); - } - } - - - // Save all chunks - @Override - public void c() { - - } - - @Override - public boolean chunkExists(int x, int z) { - return true; - } - - // Does literally nothing - @Override - public void b() { } -} diff --git a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomDataManager.java b/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomDataManager.java deleted file mode 100644 index 2dc8f5e..0000000 --- a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomDataManager.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.grinderwolf.swm.nms.v1_12_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.StringTag; -import com.flowpowered.nbt.Tag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_12_R1.EntityHuman; -import net.minecraft.server.v1_12_R1.GameRules; -import net.minecraft.server.v1_12_R1.IChunkLoader; -import net.minecraft.server.v1_12_R1.NBTTagCompound; -import net.minecraft.server.v1_12_R1.WorldData; -import net.minecraft.server.v1_12_R1.WorldNBTStorage; -import net.minecraft.server.v1_12_R1.WorldProvider; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - -@Getter -public class CustomDataManager extends WorldNBTStorage { - - private static final Map defaultValues; - - static { - GameRules emptyRules = new GameRules(); - String[] rules = emptyRules.getGameRules(); - - defaultValues = Arrays.stream(rules).collect(Collectors.toMap((rule) -> rule, emptyRules::get)); - } - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private final CustomChunkLoader chunkLoader; - private WorldData worldData; - - // When unloading a world, Spigot tries to remove the region file from its cache. - // To do so, it casts the world's IDataManager to a WorldNBTStorage, to be able - // to use the getDirectory() method. Thanks to this, we have to create a custom - // WorldNBTStorage with a fake file instead of just implementing the IDataManager interface - // - // Thanks Spigot! - CustomDataManager(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), false, null); - - // The WorldNBTStorage automatically creates some files inside the base dir, so we have to delete them - // (Thanks again Spigot) - - // Can't just access the baseDir field inside WorldNBTStorage cause it's private :P - File baseDir = new File("temp_" + world.getName(), world.getName()); - new File(baseDir, "session.lock").delete(); - new File(baseDir, "data").delete(); - - baseDir.delete(); - baseDir.getParentFile().delete(); - - this.world = world; - this.chunkLoader = new CustomChunkLoader((CraftSlimeWorld) world); - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override public void checkSession() { } - - @Override - public IChunkLoader createChunkLoader(WorldProvider worldProvider) { - return chunkLoader; - } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.w().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - // Remove default values to save space - for (Map.Entry> entry : new ArrayList<>(gameRules.getValue().entrySet())) { - String rule = entry.getKey(); - StringTag valueTag = (StringTag) entry.getValue(); - String defaultValue = defaultValues.get(rule); - - if (valueTag.getValue().equalsIgnoreCase(defaultValue)) { - gameRules.getValue().remove(rule); - } - } - - // Maybe all the gamerules stored were the default values - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public void a() { - - } - - @Override - public File getDataFile(String s) { - return null; - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} diff --git a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomWorldData.java b/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomWorldData.java deleted file mode 100644 index 689f1f9..0000000 --- a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomWorldData.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.grinderwolf.swm.nms.v1_12_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_12_R1.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.w().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } - -} diff --git a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomWorldServer.java b/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomWorldServer.java deleted file mode 100644 index 8d7855f..0000000 --- a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/CustomWorldServer.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.grinderwolf.swm.nms.v1_12_R1; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_12_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, IDataManager dataManager, int dimension) { - super(MinecraftServer.getServer(), dataManager, dataManager.getWorldData(), dimension, MinecraftServer.getServer().methodProfiler, - World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()), null); - - this.D = new CustomFunctionData(null, MinecraftServer.getServer()); - this.slimeWorld = world; - this.tracker = new EntityTracker(this); - addIWorldAccess(new WorldManager(MinecraftServer.getServer(), this)); - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - // Load all chunks - CustomChunkLoader chunkLoader = ((CustomDataManager) this.getDataManager()).getChunkLoader(); - chunkLoader.loadAllChunks(this); - - // Disable auto save period as it's constantly saving the world - if (v1_12_R1SlimeNMS.IS_PAPER) { - this.paperConfig.autoSavePeriod = 0; - } - } - - CustomWorldServer(CraftSlimeWorld world, IDataManager dataManager, AdvancementDataWorld advancementData) { - this(world, dataManager, 0); - - this.C = advancementData; - } - - @Override - public void save(boolean forceSave, IProgressUpdate progressUpdate) throws ExceptionWorldConflict { - if (!slimeWorld.isReadOnly()) { - super.save(forceSave, progressUpdate); - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the slimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - -} diff --git a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/NMSSlimeChunk.java deleted file mode 100644 index baf5c32..0000000 --- a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/NMSSlimeChunk.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.grinderwolf.swm.nms.v1_12_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_12_R1.*; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.locX; - } - - @Override - public int getZ() { - return chunk.locZ; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.a()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(section.getEmittedLightArray()); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(section.getSkyLightArray()); - - // Block Data - byte[] blocks = new byte[4096]; - - net.minecraft.server.v1_12_R1.NibbleArray minecraftBlockDataArray = new net.minecraft.server.v1_12_R1.NibbleArray(); - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - dataPaletteBlock.exportData(blocks, minecraftBlockDataArray); - - NibbleArray blockDataArray = Converter.convertArray(minecraftBlockDataArray); - - sections[sectionId] = new CraftSlimeChunkSection(blocks, blockDataArray, null, null, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - CompoundTag heightMapsCompound = new CompoundTag("", new CompoundMap()); - heightMapsCompound.getValue().put("heightMap", new IntArrayTag("heightMap", chunk.heightMap)); - - return heightMapsCompound; - } - - @Override - public int[] getBiomes() { - return toIntArray(chunk.getBiomeIndex()); - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.g(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } - - private static int[] toIntArray(byte[] buf) { - ByteBuffer buffer = ByteBuffer.wrap(buf).order(ByteOrder.BIG_ENDIAN); - int[] ret = new int[buf.length / 4]; - - buffer.asIntBuffer().get(ret); - - return ret; - } -} diff --git a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/v1_12_R1SlimeNMS.java b/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/v1_12_R1SlimeNMS.java deleted file mode 100644 index 79cf046..0000000 --- a/slimeworldmanager-nms-v1_12_R1/src/main/java/com/grinderwolf/swm/nms/v1_12_R1/v1_12_R1SlimeNMS.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.grinderwolf.swm.nms.v1_12_R1; - -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import lombok.Getter; -import net.minecraft.server.v1_12_R1.MinecraftServer; -import net.minecraft.server.v1_12_R1.WorldServer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_12_R1SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - public static final boolean IS_PAPER; - - static { - boolean paper = true; - - try { - Class.forName("com.destroystokyo.paper.PaperWorldConfig"); - } catch (ClassNotFoundException e) { - paper = false; - } - - IS_PAPER = paper; - } - - private final byte worldVersion = 0x03; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private WorldServer defaultWorld; - private WorldServer defaultNetherWorld; - private WorldServer defaultEndWorld; - - public v1_12_R1SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomDataManager(normalWorld), 0); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomDataManager(netherWorld), env.getId()); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomDataManager(endWorld), env.getId()); - } - - loadingDefaultWorlds = false; - } - - @Override - public Object createNMSWorld(SlimeWorld world) { - CustomDataManager dataManager = new CustomDataManager(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worlds.size(); - boolean used = false; - - do { - for (WorldServer server : mcServer.worlds) { - used = server.dimension == dimension; - - if (used) { - dimension++; - break; - } - } - } while (used); - - return new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimension).b(); - } - - @Override - public void generateWorld(SlimeWorld world) { - addWorldToServerList(createNMSWorld(world)); - } - - @Override - public void addWorldToServerList(Object worldObject) { - if (!(worldObject instanceof WorldServer)) { - throw new IllegalArgumentException("World object must be an instance of WorldServer!"); - } - - CustomWorldServer server = (CustomWorldServer) worldObject; - String worldName = server.getWorldData().getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - MinecraftServer mcServer = MinecraftServer.getServer(); - - mcServer.server.addWorld(server.getWorld()); - mcServer.worlds.add(server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - return worldServer.getSlimeWorld(); - } -} diff --git a/slimeworldmanager-nms-v1_13_R1/pom.xml b/slimeworldmanager-nms-v1_13_R1/pom.xml deleted file mode 100644 index f8d56a3..0000000 --- a/slimeworldmanager-nms-v1_13_R1/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_13_R1 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - org.spigotmc - spigot - 1.13-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/Converter.java b/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/Converter.java deleted file mode 100644 index bf20dd7..0000000 --- a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/Converter.java +++ /dev/null @@ -1,223 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R1; - -import com.flowpowered.nbt.ByteArrayTag; -import com.flowpowered.nbt.ByteTag; -import com.flowpowered.nbt.CompoundMap; -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.DoubleTag; -import com.flowpowered.nbt.FloatTag; -import com.flowpowered.nbt.IntArrayTag; -import com.flowpowered.nbt.IntTag; -import com.flowpowered.nbt.ListTag; -import com.flowpowered.nbt.LongArrayTag; -import com.flowpowered.nbt.LongTag; -import com.flowpowered.nbt.ShortTag; -import com.flowpowered.nbt.StringTag; -import com.flowpowered.nbt.Tag; -import com.flowpowered.nbt.TagType; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunk; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import net.minecraft.server.v1_13_R1.BiomeBase; -import net.minecraft.server.v1_13_R1.Chunk; -import net.minecraft.server.v1_13_R1.ChunkSection; -import net.minecraft.server.v1_13_R1.DataPaletteBlock; -import net.minecraft.server.v1_13_R1.Entity; -import net.minecraft.server.v1_13_R1.HeightMap; -import net.minecraft.server.v1_13_R1.NBTBase; -import net.minecraft.server.v1_13_R1.NBTTagByte; -import net.minecraft.server.v1_13_R1.NBTTagByteArray; -import net.minecraft.server.v1_13_R1.NBTTagCompound; -import net.minecraft.server.v1_13_R1.NBTTagDouble; -import net.minecraft.server.v1_13_R1.NBTTagFloat; -import net.minecraft.server.v1_13_R1.NBTTagInt; -import net.minecraft.server.v1_13_R1.NBTTagIntArray; -import net.minecraft.server.v1_13_R1.NBTTagList; -import net.minecraft.server.v1_13_R1.NBTTagLong; -import net.minecraft.server.v1_13_R1.NBTTagLongArray; -import net.minecraft.server.v1_13_R1.NBTTagShort; -import net.minecraft.server.v1_13_R1.NBTTagString; -import net.minecraft.server.v1_13_R1.TileEntity; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_13_R1.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_13_R1.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_13_R1.NibbleArray array) { - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return new NBTTagByte(((ByteTag) tag).getValue()); - case TAG_SHORT: - return new NBTTagShort(((ShortTag) tag).getValue()); - case TAG_INT: - return new NBTTagInt(((IntTag) tag).getValue()); - case TAG_LONG: - return new NBTTagLong(((LongTag) tag).getValue()); - case TAG_FLOAT: - return new NBTTagFloat(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return new NBTTagDouble(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return new NBTTagString(((StringTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LONG_ARRAY: - return new NBTTagLongArray(((LongArrayTag) tag).getValue()); - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).g()); - case 2: - return new ShortTag(name, ((NBTTagShort) base).f()); - case 3: - return new IntTag(name, ((NBTTagInt) base).e()); - case 4: - return new LongTag(name, ((NBTTagLong) base).d()); - case 5: - return new FloatTag(name, ((NBTTagFloat) base).i()); - case 6: - return new DoubleTag(name, ((NBTTagDouble) base).asDouble()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).c()); - case 8: - return new StringTag(name, ((NBTTagString) base).b_()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (NBTBase entry : originalList) { - list.add(convertTag("", entry)); - } - - return new ListTag(name, TagType.getById(originalList.d()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.getKeys()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).d()); - case 12: - return new LongArrayTag("", ((NBTTagLongArray) base).d()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } - - static SlimeChunk convertChunk(Chunk chunk) { - // Chunk sections - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.a()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = convertArray(section.getEmittedLightArray()); - - // Sky light Nibble Array - NibbleArray skyLightArray = convertArray(section.getSkyLightArray()); - - // Block Data - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - NBTTagCompound blocksCompound = new NBTTagCompound(); - dataPaletteBlock.b(blocksCompound, "Palette", "BlockStates"); - NBTTagList paletteList = blocksCompound.getList("Palette", 10); - ListTag palette = (ListTag) Converter.convertTag("", paletteList); - long[] blockStates = blocksCompound.o("BlockStates"); - - sections[sectionId] = new CraftSlimeChunkSection(null, null, palette, blockStates, blockLightArray, skyLightArray); - } - } - } - - // Tile Entities - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) convertTag("", entityNbt)); - } - - // Entities - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.f(true); - entities.add((CompoundTag) convertTag("", entityNbt)); - } - } - } - - // Biomes - BiomeBase[] biomeBases = chunk.getBiomeIndex(); - int[] biomes = new int[biomeBases.length]; - - for (int i = 0; i < biomeBases.length; i++) { - biomes[i] = BiomeBase.REGISTRY_ID.a(biomeBases[i]); - } - - // HeightMap - CompoundMap heightMaps = new CompoundMap(); - - for (HeightMap.Type type : chunk.heightMap.keySet()) { - heightMaps.put(type.b(), new LongArrayTag(type.b(), chunk.b(type).b())); - } - - CompoundTag heightMapCompound = new CompoundTag("", heightMaps); - - return new CraftSlimeChunk(chunk.world.worldData.getName(), chunk.locX, chunk.locZ, sections, heightMapCompound, biomes, tileEntities, entities); - } -} diff --git a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CraftCLSMBridge.java deleted file mode 100644 index 24dd292..0000000 --- a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CraftCLSMBridge.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R1; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_13_R1.WorldServer; - -@RequiredArgsConstructor -public class CraftCLSMBridge implements CLSMBridge { - - private final v1_13_R1SlimeNMS nmsInstance; - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_13_R1SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomChunkLoader.java b/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomChunkLoader.java deleted file mode 100644 index b08e1c9..0000000 --- a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomChunkLoader.java +++ /dev/null @@ -1,265 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunk; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_13_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; - -@RequiredArgsConstructor -public class CustomChunkLoader implements IChunkLoader { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final CraftSlimeWorld world; - - void loadAllChunks(CustomWorldServer server) { - for (SlimeChunk chunk : new ArrayList<>(world.getChunks().values())) { - Chunk nmsChunk = createChunk(server, chunk); - world.updateChunk(new NMSSlimeChunk(nmsChunk)); - } - } - - private Chunk createChunk(CustomWorldServer server, SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + world.getName()); - - BlockPosition.MutableBlockPosition mutableBlockPosition = new BlockPosition.MutableBlockPosition(); - - // ProtoChunkTickLists - ProtoChunkTickList airChunkTickList = new ProtoChunkTickList<>((block) -> block.getBlockData().isAir(), Block.REGISTRY::b, Block.REGISTRY::get, new ChunkCoordIntPair(x, z)); - ProtoChunkTickList fluidChunkTickList = new ProtoChunkTickList<>((fluidType) -> fluidType == FluidTypes.a, FluidType.c::b, FluidType.c::get, new ChunkCoordIntPair(x, z)); - - // Biomes - BiomeBase[] biomeBaseArray = new BiomeBase[256]; - int[] biomeIntArray = chunk.getBiomes(); - - for (int i = 0; i < biomeIntArray.length; i++) { - biomeBaseArray[i] = BiomeBase.a(biomeIntArray[i]); - - if (biomeBaseArray[i] == null) { - biomeBaseArray[i] = server.getChunkProvider().getChunkGenerator().getWorldChunkManager().getBiome(mutableBlockPosition - .c((i & 15) + (x << 4), 0, (i >> 4 & 15) + (z << 4)), Biomes.c); - } - } - - CompoundTag upgradeDataTag = ((CraftSlimeChunk) chunk).getUpgradeData(); - Chunk nmsChunk = new Chunk(server, x, z, biomeBaseArray, upgradeDataTag == null ? ChunkConverter.a - : new ChunkConverter((NBTTagCompound) Converter.convertTag(upgradeDataTag)), airChunkTickList, fluidChunkTickList, 0L); - - // Chunk status - nmsChunk.c("postprocessed"); - - // Chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + x + ", " + z + ") on world " + world.getName()); - ChunkSection[] sections = new ChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null && slimeSection.getBlockStates().length > 0) { // If block states array is empty, it's just a fake chunk made by the createEmptyWorld method - ChunkSection section = new ChunkSection(sectionId, true); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + x + ", " + z + ") - World " + world.getName() + ":"); - LOGGER.debug("Block palette:"); - LOGGER.debug(slimeSection.getPalette().toString()); - LOGGER.debug("Block states array:"); - LOGGER.debug(slimeSection.getBlockStates()); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - NBTTagCompound sectionCompound = new NBTTagCompound(); - - sectionCompound.set("Palette", Converter.convertTag(slimeSection.getPalette())); - sectionCompound.a("BlockStates", slimeSection.getBlockStates()); - - section.getBlocks().a(sectionCompound, "Palette", "BlockStates"); - - if (slimeSection.getBlockLight() != null) { - section.a(Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - section.b(Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - nmsChunk.a(sections); - - // Height Maps - HeightMap.Type[] heightMapTypes = HeightMap.Type.values(); - CompoundMap heightMaps = chunk.getHeightMaps().getValue(); - - for (HeightMap.Type type : heightMapTypes) { - if (type.c() == HeightMap.Use.LIVE_WORLD) { - String name = type.b(); - - if (heightMaps.containsKey(name)) { - LongArrayTag heightMap = (LongArrayTag) heightMaps.get(name); - - nmsChunk.a(type, heightMap.getValue()); - } else { - nmsChunk.b(type).a(); - } - } - } - - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List tileEntities = chunk.getTileEntities(); - int loadedEntities = 0; - - if (tileEntities != null) { - for (CompoundTag tag : tileEntities) { - TileEntity entity = TileEntity.create((NBTTagCompound) Converter.convertTag(tag)); - - if (entity != null) { - nmsChunk.a(entity); - loadedEntities++; - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List entities = chunk.getEntities(); - loadedEntities = 0; - - if (entities != null) { - for (CompoundTag tag : entities) { - loadEntity(tag, server.getMinecraftWorld(), nmsChunk); - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - LOGGER.debug("Loaded chunk (" + x + ", " + z + ") on world " + world.getName()); - - return nmsChunk; - } - - private Entity loadEntity(CompoundTag tag, World world, Chunk chunk) { - Entity entity = EntityTypes.a((NBTTagCompound) Converter.convertTag(tag), world); - chunk.f(true); - - if (entity != null) { - chunk.a(entity); - - CompoundMap map = tag.getValue(); - - if (map.containsKey("Passengers")) { - List passengersList = (List) map.get("Passengers").getValue(); - - for (CompoundTag passengerTag : passengersList) { - Entity passenger = loadEntity(passengerTag, world, chunk); - - if (passengerTag != null) { - passenger.a(entity, true); - } - } - } - } - - return entity; - } - - @Nullable - @Override - public ProtoChunk b(GeneratorAccess generatorAccess, int x, int z, Consumer consumer) { - Chunk chunk = this.a(generatorAccess, x, z, null); - consumer.accept(chunk); - - return null; - } - - // Load full chunk - @Override - public Chunk a(GeneratorAccess generatorAccess, int x, int z, Consumer consumer) { - SlimeChunk slimeChunk = world.getChunk(x, z); - Chunk chunk; - - if (slimeChunk == null) { - BlockPosition.MutableBlockPosition mutableBlockPosition = new BlockPosition.MutableBlockPosition(); - - // Biomes - BiomeBase[] biomeBaseArray = new BiomeBase[256]; - - for (int i = 0; i < biomeBaseArray.length; i++) { - biomeBaseArray[i] = generatorAccess.getChunkProvider().getChunkGenerator().getWorldChunkManager().getBiome(mutableBlockPosition - .c((i & 15) + (x << 4), 0, (i >> 4 & 15) + (z << 4)), Biomes.c); - } - - // ProtoChunkTickLists - ProtoChunkTickList airChunkTickList = new ProtoChunkTickList<>((block) -> block.getBlockData().isAir(), Block.REGISTRY::b, Block.REGISTRY::get, new ChunkCoordIntPair(x, z)); - ProtoChunkTickList fluidChunkTickList = new ProtoChunkTickList<>((fluidType) -> fluidType == FluidTypes.a, FluidType.c::b, FluidType.c::get, new ChunkCoordIntPair(x, z)); - - chunk = new Chunk(generatorAccess.getMinecraftWorld(), x, z, biomeBaseArray, ChunkConverter.a, airChunkTickList, fluidChunkTickList, 0L); - chunk.c("postprocessed"); - } else if (slimeChunk instanceof NMSSlimeChunk) { - chunk = ((NMSSlimeChunk) slimeChunk).getChunk(); - } else { // All SlimeChunk objects should be converted to NMSSlimeChunks when loading the world - throw new IllegalStateException("Chunk (" + x + ", " + z + ") has not been converted to a NMSSlimeChunk object!"); - } - - - // Chunk consumer - if (consumer != null) { - consumer.accept(chunk); - } - - return chunk; - } - - @Override - public void saveChunk(World world, IChunkAccess chunkAccess) { - this.saveChunk(world, chunkAccess, false); - } - - @Override - public void saveChunk(World world, IChunkAccess chunkAccess, boolean unloaded) { - if (chunkAccess.i().d() == ChunkStatus.Type.PROTOCHUNK) { - return; // Not saving protochunks, only full chunks - } - - SlimeChunk slimeChunk = this.world.getChunk(chunkAccess.getPos().x, chunkAccess.getPos().z); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk((Chunk) chunkAccess); - } else { - this.world.updateChunk(new NMSSlimeChunk((Chunk) chunkAccess)); - } - } - - // Save all chunks - @Override - public void c() { - - } - - @Override - public boolean chunkExists(int x, int z) { - return true; - } - - // Does literally nothing - @Override - public void b() { } -} diff --git a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomDataManager.java b/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomDataManager.java deleted file mode 100644 index 580dce8..0000000 --- a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomDataManager.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.StringTag; -import com.flowpowered.nbt.Tag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_13_R1.EntityHuman; -import net.minecraft.server.v1_13_R1.GameRules; -import net.minecraft.server.v1_13_R1.IChunkLoader; -import net.minecraft.server.v1_13_R1.NBTTagCompound; -import net.minecraft.server.v1_13_R1.WorldData; -import net.minecraft.server.v1_13_R1.WorldNBTStorage; -import net.minecraft.server.v1_13_R1.WorldProvider; - -import java.io.File; -import java.util.ArrayList; -import java.util.Map; -import java.util.TreeMap; -import java.util.UUID; - -@Getter -public class CustomDataManager extends WorldNBTStorage { - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private final CustomChunkLoader chunkLoader; - private WorldData worldData; - - // When unloading a world, Spigot tries to remove the region file from its cache. - // To do so, it casts the world's IDataManager to a WorldNBTStorage, to be able - // to use the getDirectory() method. Thanks to this, we have to create a custom - // WorldNBTStorage with a fake file instead of just implementing the IDataManager interface - // - // Thanks Spigot! - CustomDataManager(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), null, null); - - // The WorldNBTStorage automatically creates some files inside the base dir, so we have to delete them - // (Thanks again Spigot) - - // Can't just access the baseDir field inside WorldNBTStorage cause it's private :P - File baseDir = new File("temp_" + world.getName(), world.getName()); - new File(baseDir, "session.lock").delete(); - new File(baseDir, "data").delete(); - - baseDir.delete(); - baseDir.getParentFile().delete(); - - this.world = world; - this.chunkLoader = new CustomChunkLoader((CraftSlimeWorld) world); - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override - public IChunkLoader createChunkLoader(WorldProvider worldProvider) { - return chunkLoader; - } - - @Override public void checkSession() { } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.w().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - // Remove default values to save space - TreeMap defaultValues = GameRules.getGameRules(); - - for (Map.Entry> entry : new ArrayList<>(gameRules.getValue().entrySet())) { - String rule = entry.getKey(); - StringTag valueTag = (StringTag) entry.getValue(); - GameRules.b defaultValue = defaultValues.get(rule); - - if (defaultValue != null && defaultValue.a().a().equalsIgnoreCase(valueTag.getValue())) { - gameRules.getValue().remove(rule); - } - } - - // Maybe all the gamerules stored were the default values - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public void a() { - - } - - @Override - public File getDataFile(String s) { - return null; - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} diff --git a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomWorldData.java b/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomWorldData.java deleted file mode 100644 index 16b985f..0000000 --- a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomWorldData.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_13_R1.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.w().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } - -} diff --git a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomWorldServer.java b/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomWorldServer.java deleted file mode 100644 index 90e51f0..0000000 --- a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/CustomWorldServer.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R1; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_13_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, IDataManager dataManager, int dimension) { - super(MinecraftServer.getServer(), dataManager, dataManager.getWorldData(), dimension, MinecraftServer.getServer().methodProfiler, World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()), null); - b(); - this.slimeWorld = world; - this.tracker = new EntityTracker(this); - addIWorldAccess(new WorldManager(MinecraftServer.getServer(), this)); - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - // Load all chunks - CustomChunkLoader chunkLoader = ((CustomDataManager) this.getDataManager()).getChunkLoader(); - chunkLoader.loadAllChunks(this); - } - - @Override - public void save(boolean forceSave, IProgressUpdate progressUpdate) throws ExceptionWorldConflict { - if (!slimeWorld.isReadOnly()) { - super.save(forceSave, progressUpdate); - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the SlimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - -} diff --git a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/NMSSlimeChunk.java deleted file mode 100644 index 5407b2e..0000000 --- a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/NMSSlimeChunk.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_13_R1.*; - -import java.util.ArrayList; -import java.util.List; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.getPos().x; - } - - @Override - public int getZ() { - return chunk.getPos().z; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.a()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(section.getEmittedLightArray()); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(section.getSkyLightArray()); - - // Block Data - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - NBTTagCompound blocksCompound = new NBTTagCompound(); - dataPaletteBlock.b(blocksCompound, "Palette", "BlockStates"); - NBTTagList paletteList = blocksCompound.getList("Palette", 10); - ListTag palette = (ListTag) Converter.convertTag("", paletteList); - long[] blockStates = blocksCompound.o("BlockStates"); - - sections[sectionId] = new CraftSlimeChunkSection(null, null, palette, blockStates, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - // HeightMap - CompoundMap heightMaps = new CompoundMap(); - - for (HeightMap.Type type : chunk.heightMap.keySet()) { - heightMaps.put(type.b(), new LongArrayTag(type.b(), chunk.b(type).b())); - } - - return new CompoundTag("", heightMaps); - } - - @Override - public int[] getBiomes() { - BiomeBase[] biomeBases = chunk.getBiomeIndex(); - int[] biomes = new int[biomeBases.length]; - - for (int i = 0; i < biomeBases.length; i++) { - biomes[i] = BiomeBase.REGISTRY_ID.a(biomeBases[i]); - } - - return biomes; - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.f(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } -} diff --git a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/v1_13_R1SlimeNMS.java b/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/v1_13_R1SlimeNMS.java deleted file mode 100644 index 9108b35..0000000 --- a/slimeworldmanager-nms-v1_13_R1/src/main/java/com/grinderwolf/swm/nms/v1_13_R1/v1_13_R1SlimeNMS.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import com.mojang.datafixers.DataFixTypes; -import lombok.Getter; -import net.minecraft.server.v1_13_R1.DataConverterRegistry; -import net.minecraft.server.v1_13_R1.GameProfileSerializer; -import net.minecraft.server.v1_13_R1.MinecraftServer; -import net.minecraft.server.v1_13_R1.NBTTagCompound; -import net.minecraft.server.v1_13_R1.WorldServer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_13_R1.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_13_R1SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - - private final byte worldVersion = 0x04; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private WorldServer defaultWorld; - private WorldServer defaultNetherWorld; - private WorldServer defaultEndWorld; - - public v1_13_R1SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomDataManager(normalWorld), 0); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomDataManager(netherWorld), env.getId()); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomDataManager(endWorld), env.getId()); - } - - loadingDefaultWorlds = false; - } - - @Override - public Object createNMSWorld(SlimeWorld world) { - CustomDataManager dataManager = new CustomDataManager(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worlds.size(); - boolean used = false; - - do { - for (WorldServer server : mcServer.worlds) { - used = server.dimension == dimension; - - if (used) { - dimension++; - break; - } - } - } while (used); - - return new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimension).b(); - } - - @Override - public void generateWorld(SlimeWorld world) { - addWorldToServerList(createNMSWorld(world)); - } - - @Override - public void addWorldToServerList(Object worldObject) { - if (!(worldObject instanceof WorldServer)) { - throw new IllegalArgumentException("World object must be an instance of WorldServer!"); - } - - CustomWorldServer server = (CustomWorldServer) worldObject; - String worldName = server.getWorldData().getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - MinecraftServer mcServer = MinecraftServer.getServer(); - - mcServer.server.addWorld(server.getWorld()); - mcServer.worlds.add(server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - return worldServer.getSlimeWorld(); - } - - @Override - public CompoundTag convertChunk(CompoundTag tag) { - NBTTagCompound nmsTag = (NBTTagCompound) Converter.convertTag(tag); - int version = nmsTag.getInt("DataVersion"); - - NBTTagCompound newNmsTag = GameProfileSerializer.a(DataConverterRegistry.a(), DataFixTypes.CHUNK, nmsTag, version); - - return (CompoundTag) Converter.convertTag("", newNmsTag); - } -} diff --git a/slimeworldmanager-nms-v1_13_R2/pom.xml b/slimeworldmanager-nms-v1_13_R2/pom.xml deleted file mode 100644 index 5d2ee3d..0000000 --- a/slimeworldmanager-nms-v1_13_R2/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_13_R2 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - com.destroystokyo.paper - paper - 1.13.2-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/Converter.java b/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/Converter.java deleted file mode 100644 index 8fa5c11..0000000 --- a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/Converter.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R2; - -import com.flowpowered.nbt.Tag; -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import net.minecraft.server.v1_13_R2.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_13_R2.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_13_R2.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_13_R2.NibbleArray array) { - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return new NBTTagByte(((ByteTag) tag).getValue()); - case TAG_SHORT: - return new NBTTagShort(((ShortTag) tag).getValue()); - case TAG_INT: - return new NBTTagInt(((IntTag) tag).getValue()); - case TAG_LONG: - return new NBTTagLong(((LongTag) tag).getValue()); - case TAG_FLOAT: - return new NBTTagFloat(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return new NBTTagDouble(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return new NBTTagString(((StringTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LONG_ARRAY: - return new NBTTagLongArray(((LongArrayTag) tag).getValue()); - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).asByte()); - case 2: - return new ShortTag(name, ((NBTTagShort) base).asShort()); - case 3: - return new IntTag(name, ((NBTTagInt) base).asInt()); - case 4: - return new LongTag(name, ((NBTTagLong) base).asLong()); - case 5: - return new FloatTag(name, ((NBTTagFloat) base).asFloat()); - case 6: - return new DoubleTag(name, ((NBTTagDouble) base).asDouble()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).c()); - case 8: - return new StringTag(name, ((NBTTagString) base).asString()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (NBTBase entry : originalList) { - list.add(convertTag("", entry)); - } - - return new ListTag(name, TagType.getById(originalList.d()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.getKeys()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).d()); - case 12: - return new LongArrayTag("", ((NBTTagLongArray) base).d()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } -} diff --git a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CraftCLSMBridge.java deleted file mode 100644 index 4003045..0000000 --- a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CraftCLSMBridge.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R2; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_13_R2.WorldServer; - -@RequiredArgsConstructor -public class CraftCLSMBridge implements CLSMBridge { - - private final v1_13_R2SlimeNMS nmsInstance; - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_13_R2SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomChunkLoader.java b/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomChunkLoader.java deleted file mode 100644 index b624e9b..0000000 --- a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomChunkLoader.java +++ /dev/null @@ -1,340 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R2; - -import com.flowpowered.nbt.CompoundMap; -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.LongArrayTag; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunk; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_13_R2.BiomeBase; -import net.minecraft.server.v1_13_R2.Biomes; -import net.minecraft.server.v1_13_R2.Block; -import net.minecraft.server.v1_13_R2.BlockPosition; -import net.minecraft.server.v1_13_R2.Chunk; -import net.minecraft.server.v1_13_R2.ChunkConverter; -import net.minecraft.server.v1_13_R2.ChunkCoordIntPair; -import net.minecraft.server.v1_13_R2.ChunkSection; -import net.minecraft.server.v1_13_R2.ChunkStatus; -import net.minecraft.server.v1_13_R2.DimensionManager; -import net.minecraft.server.v1_13_R2.Entity; -import net.minecraft.server.v1_13_R2.EntityTypes; -import net.minecraft.server.v1_13_R2.FluidType; -import net.minecraft.server.v1_13_R2.FluidTypes; -import net.minecraft.server.v1_13_R2.GeneratorAccess; -import net.minecraft.server.v1_13_R2.HeightMap; -import net.minecraft.server.v1_13_R2.IChunkAccess; -import net.minecraft.server.v1_13_R2.IChunkLoader; -import net.minecraft.server.v1_13_R2.IRegistry; -import net.minecraft.server.v1_13_R2.NBTBase; -import net.minecraft.server.v1_13_R2.NBTTagCompound; -import net.minecraft.server.v1_13_R2.NBTTagList; -import net.minecraft.server.v1_13_R2.PersistentCollection; -import net.minecraft.server.v1_13_R2.ProtoChunk; -import net.minecraft.server.v1_13_R2.ProtoChunkTickList; -import net.minecraft.server.v1_13_R2.TileEntity; -import net.minecraft.server.v1_13_R2.World; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.annotation.Nullable; -import java.util.*; -import java.util.function.Consumer; - -@RequiredArgsConstructor -public class CustomChunkLoader implements IChunkLoader { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final NBTTagCompound emptyWorldCompound = new NBTTagCompound(); - private final CraftSlimeWorld world; - - { - emptyWorldCompound.set("Level", new NBTTagCompound()); - } - - void loadAllChunks(CustomWorldServer server) { - for (SlimeChunk chunk : new ArrayList<>(world.getChunks().values())) { - Object[] data = createChunk(server, chunk); - world.updateChunk(new NMSSlimeChunk((Chunk) data[0], (NBTTagCompound) data[1])); - } - } - - private Object[] createChunk(CustomWorldServer server, SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + world.getName()); - Object[] data = new Object[2]; - - // Fake level compound - NBTTagCompound levelCompound = new NBTTagCompound(); - NBTTagCompound globalCompound = new NBTTagCompound(); - - globalCompound.set("Level", levelCompound); - data[1] = globalCompound; - - BlockPosition.MutableBlockPosition mutableBlockPosition = new BlockPosition.MutableBlockPosition(); - - // ProtoChunkTickLists - ProtoChunkTickList airChunkTickList = new ProtoChunkTickList<>((block) -> block.getBlockData().isAir(), IRegistry.BLOCK::getKey, IRegistry.BLOCK::getOrDefault, new ChunkCoordIntPair(x, z)); - ProtoChunkTickList fluidChunkTickList = new ProtoChunkTickList<>((fluidType) -> fluidType == FluidTypes.EMPTY, IRegistry.FLUID::getKey, IRegistry.FLUID::getOrDefault, new ChunkCoordIntPair(x, z)); - - // Biomes - BiomeBase[] biomeBaseArray = new BiomeBase[256]; - int[] biomeIntArray = chunk.getBiomes(); - - for (int i = 0; i < biomeIntArray.length; i++) { - biomeBaseArray[i] = IRegistry.BIOME.fromId(biomeIntArray[i]); - - if (biomeBaseArray[i] == null) { - biomeBaseArray[i] = server.getChunkProvider().getChunkGenerator().getWorldChunkManager().getBiome(mutableBlockPosition - .c((i & 15) + (x << 4), 0, (i >> 4 & 15) + (z << 4)), Biomes.PLAINS); - } - } - - CompoundTag upgradeDataTag = ((CraftSlimeChunk) chunk).getUpgradeData(); - Chunk nmsChunk = new Chunk(server.getMinecraftWorld(), x, z, biomeBaseArray, upgradeDataTag == null ? ChunkConverter.a - : new ChunkConverter((NBTTagCompound) Converter.convertTag(upgradeDataTag)), airChunkTickList, fluidChunkTickList, 0L); - - // Chunk status - nmsChunk.c("postprocessed"); - - // Chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + x + ", " + z + ") on world " + world.getName()); - ChunkSection[] sections = new ChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null && slimeSection.getBlockStates().length > 0) { // If block states array is empty, it's just a fake chunk made by the createEmptyWorld method - ChunkSection section = new ChunkSection(sectionId << 4, true); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + x + ", " + z + ") - World " + world.getName() + ":"); - LOGGER.debug("Block palette:"); - LOGGER.debug(slimeSection.getPalette().toString()); - LOGGER.debug("Block states array:"); - LOGGER.debug(slimeSection.getBlockStates()); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - NBTTagCompound sectionCompound = new NBTTagCompound(); - - sectionCompound.set("Palette", Converter.convertTag(slimeSection.getPalette())); - sectionCompound.a("BlockStates", slimeSection.getBlockStates()); - - section.getBlocks().a(sectionCompound, "Palette", "BlockStates"); - - if (slimeSection.getBlockLight() != null) { - section.a(Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - section.b(Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - nmsChunk.a(sections); - - // Height Maps - HeightMap.Type[] heightMapTypes = HeightMap.Type.values(); - CompoundMap heightMaps = chunk.getHeightMaps().getValue(); - - for (HeightMap.Type type : heightMapTypes) { - if (type.c() == HeightMap.Use.LIVE_WORLD) { - String name = type.b(); - - if (heightMaps.containsKey(name)) { - LongArrayTag heightMap = (LongArrayTag) heightMaps.get(name); - - nmsChunk.a(type, heightMap.getValue()); - } else { - nmsChunk.b(type).a(); - } - } - } - - // Tile Entities - if (chunk.getTileEntities() != null) { - NBTTagList tileEntities = new NBTTagList(); - - for (CompoundTag tileEntityTag : chunk.getTileEntities()) { - tileEntities.add(Converter.convertTag(tileEntityTag)); - } - - levelCompound.set("TileEntities", tileEntities); - } - - // Entities - if (chunk.getEntities() != null) { - NBTTagList entities = new NBTTagList(); - - for (CompoundTag entityTag : chunk.getEntities()) { - entities.add(Converter.convertTag(entityTag)); - } - - levelCompound.set("Entities", entities); - } - - LOGGER.debug("Loaded chunk (" + x + ", " + z + ") on world " + world.getName()); - data[0] = nmsChunk; - - return data; - } - - @Nullable - @Override - public ProtoChunk b(GeneratorAccess generatorAccess, int x, int z, Consumer consumer) { - Chunk chunk = this.a(generatorAccess, x, z, null); - consumer.accept(chunk); - - return null; - } - - // Load full chunk - @Override - public Chunk a(GeneratorAccess generatorAccess, int x, int z, Consumer consumer) { - Object[] chunkData = loadChunk(generatorAccess, x, z, consumer); - Chunk chunk = (Chunk) chunkData[0]; - - // Chunk consumer - NBTTagCompound compound = (NBTTagCompound) chunkData[1]; - - if (consumer != null) { - consumer.accept(chunk); - } - - loadEntities(compound.getCompound("Level"), chunk); - return chunk; - } - - // PaperSpigot adds these methods to the IChunkLoader interface, so they have to be implemented as well - - public Object[] loadChunk(GeneratorAccess generatorAccess, int x, int z, Consumer consumer) { // Paper method - SlimeChunk slimeChunk = world.getChunk(x, z); - Object[] data; - - if (slimeChunk == null) { - data = new Object[2]; - BlockPosition.MutableBlockPosition mutableBlockPosition = new BlockPosition.MutableBlockPosition(); - - // Biomes - BiomeBase[] biomeBaseArray = new BiomeBase[256]; - - for (int i = 0; i < biomeBaseArray.length; i++) { - biomeBaseArray[i] = generatorAccess.getChunkProvider().getChunkGenerator().getWorldChunkManager().getBiome(mutableBlockPosition - .c((i & 15) + (x << 4), 0, (i >> 4 & 15) + (z << 4)), Biomes.PLAINS); - } - - // ProtoChunkTickLists - ProtoChunkTickList airChunkTickList = new ProtoChunkTickList<>((block) -> block.getBlockData().isAir(), IRegistry.BLOCK::getKey, IRegistry.BLOCK::getOrDefault, new ChunkCoordIntPair(x, z)); - ProtoChunkTickList fluidChunkTickList = new ProtoChunkTickList<>((fluidType) -> fluidType == FluidTypes.EMPTY, IRegistry.FLUID::getKey, IRegistry.FLUID::getOrDefault, new ChunkCoordIntPair(x, z)); - - Chunk nmsChunk = new Chunk(generatorAccess.getMinecraftWorld(), x, z, biomeBaseArray, ChunkConverter.a, airChunkTickList, fluidChunkTickList, 0L); - nmsChunk.c("postprocessed"); - - data[0] = nmsChunk; - data[1] = emptyWorldCompound; - } else if (slimeChunk instanceof NMSSlimeChunk) { - NMSSlimeChunk nmsSlimeChunk = (NMSSlimeChunk) slimeChunk; - data = new Object[] { nmsSlimeChunk.getChunk(), nmsSlimeChunk.getCompound() }; - } else { // All SlimeChunk objects should be converted to NMSSlimeChunks when loading the world - throw new IllegalStateException("Chunk (" + x + ", " + z + ") has not been converted to a NMSSlimeChunk object!"); - } - - return data; - } - - public void getPersistentStructureLegacy(DimensionManager manager, PersistentCollection collection) { } // Paper method - - public void loadEntities(NBTTagCompound compound, Chunk chunk) { // Paper method - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + chunk.locX + ", " + chunk.locZ + ") on world " + world.getName()); - int loadedEntities = 0; - - if (compound.hasKeyOfType("TileEntities", 9)) { - NBTTagList tileEntities = compound.getList("TileEntities", 10); - - for (NBTBase tileEntity : tileEntities) { - TileEntity entity = TileEntity.create((NBTTagCompound) tileEntity); - - if (entity != null) { - chunk.a(entity); - loadedEntities++; - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + chunk.locX + ", " + chunk.locZ + ") on world " + world.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + chunk.locX + ", " + chunk.locZ + ") on world " + world.getName()); - loadedEntities = 0; - - if (compound.hasKeyOfType("Entities", 9)) { - NBTTagList entities = compound.getList("Entities", 10); - - for (NBTBase entity : entities) { - loadEntity((NBTTagCompound) entity, chunk); - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + chunk.locX + ", " + chunk.locZ + ") on world " + world.getName()); - } - - private Entity loadEntity(NBTTagCompound tag, Chunk chunk) { - Entity entity = EntityTypes.a(tag, chunk.getWorld()); - chunk.f(true); - - if (entity != null) { - chunk.a(entity); - - if (tag.hasKeyOfType("Passengers", 9)) { - NBTTagList passengersList = tag.getList("Passengers", 10); - - for (NBTBase passengerTag : passengersList) { - Entity passenger = loadEntity((NBTTagCompound) passengerTag, chunk); - - if (passengerTag != null) { - passenger.a(entity, true); - } - } - } - } - - return entity; - } - - @Override - public void saveChunk(World world, IChunkAccess chunkAccess) { - this.saveChunk(world, chunkAccess, false); - } - - @Override - public void saveChunk(World world, IChunkAccess chunkAccess, boolean unloaded) { - if (chunkAccess.i().d() == ChunkStatus.Type.PROTOCHUNK) { - return; // Not saving protochunks, only full chunks - } - - SlimeChunk slimeChunk = this.world.getChunk(chunkAccess.getPos().x, chunkAccess.getPos().z); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk((Chunk) chunkAccess); - } else { - this.world.updateChunk(new NMSSlimeChunk((Chunk) chunkAccess, emptyWorldCompound)); - } - } - - // Save all chunks - @Override - public void b() { - - } -} diff --git a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomDataManager.java b/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomDataManager.java deleted file mode 100644 index d347922..0000000 --- a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomDataManager.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R2; - -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.StringTag; -import com.flowpowered.nbt.Tag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_13_R2.DimensionManager; -import net.minecraft.server.v1_13_R2.EntityHuman; -import net.minecraft.server.v1_13_R2.GameRules; -import net.minecraft.server.v1_13_R2.IChunkLoader; -import net.minecraft.server.v1_13_R2.NBTTagCompound; -import net.minecraft.server.v1_13_R2.WorldData; -import net.minecraft.server.v1_13_R2.WorldNBTStorage; -import net.minecraft.server.v1_13_R2.WorldProvider; - -import java.io.File; -import java.util.ArrayList; -import java.util.Map; -import java.util.UUID; - -@Getter -public class CustomDataManager extends WorldNBTStorage { - - private static final GameRules EMPTY_GAMERULES = new GameRules(); - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private final CustomChunkLoader chunkLoader; - private WorldData worldData; - - // When unloading a world, Spigot tries to remove the region file from its cache. - // To do so, it casts the world's IDataManager to a WorldNBTStorage, to be able - // to use the getDirectory() method. Thanks to this, we have to create a custom - // WorldNBTStorage with a fake file instead of just implementing the IDataManager interface - // - // Thanks Spigot! - CustomDataManager(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), null, null); - - // The WorldNBTStorage automatically creates some files inside the base dir, so we have to delete them - // (Thanks again Spigot) - - // Can't just access the baseDir field inside WorldNBTStorage cause it's private :P - File baseDir = new File("temp_" + world.getName(), world.getName()); - new File(baseDir, "session.lock").delete(); - new File(baseDir, "data").delete(); - - baseDir.delete(); - baseDir.getParentFile().delete(); - - this.world = world; - this.chunkLoader = new CustomChunkLoader((CraftSlimeWorld) world); - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override - public IChunkLoader createChunkLoader(WorldProvider worldProvider) { - return chunkLoader; - } - - @Override public void checkSession() { } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.w().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - // Remove default values to save space - for (Map.Entry> entry : new ArrayList<>(gameRules.getValue().entrySet())) { - String rule = entry.getKey(); - StringTag valueTag = (StringTag) entry.getValue(); - String defaultValue = EMPTY_GAMERULES.get(rule).a(); - - if (defaultValue != null && defaultValue.equalsIgnoreCase(valueTag.getValue())) { - gameRules.getValue().remove(rule); - } - } - - // Maybe all the gamerules stored were the default values - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public void a() { - - } - - @Override - public File getDataFile(DimensionManager manager, String s) { - return null; - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} diff --git a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomWorldData.java b/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomWorldData.java deleted file mode 100644 index c3579c3..0000000 --- a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomWorldData.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R2; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_13_R2.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.w().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } - -} diff --git a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomWorldServer.java b/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomWorldServer.java deleted file mode 100644 index 032b78a..0000000 --- a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/CustomWorldServer.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R2; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_13_R2.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, IDataManager dataManager, DimensionManager dimensionManager, World.Environment env) { - super(MinecraftServer.getServer(), dataManager, new PersistentCollection(dataManager), dataManager.getWorldData(), dimensionManager, - MinecraftServer.getServer().methodProfiler, env, null); - i_(); - this.slimeWorld = world; - this.tracker = new EntityTracker(this); - addIWorldAccess(new WorldManager(MinecraftServer.getServer(), this)); - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - // Load all chunks - CustomChunkLoader chunkLoader = ((CustomDataManager) this.getDataManager()).getChunkLoader(); - chunkLoader.loadAllChunks(this); - - // Disable auto save period as it's constantly saving the world - if (v1_13_R2SlimeNMS.IS_PAPER) { - this.paperConfig.autoSavePeriod = 0; - } - } - - @Override - public void save(boolean forceSave, IProgressUpdate progressUpdate) throws ExceptionWorldConflict { - if (!slimeWorld.isReadOnly()) { - super.save(forceSave, progressUpdate); - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the slimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - -} diff --git a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/NMSSlimeChunk.java deleted file mode 100644 index 14077ff..0000000 --- a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/NMSSlimeChunk.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R2; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_13_R2.*; - -import java.util.ArrayList; -import java.util.List; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - private NBTTagCompound compound; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.getPos().x; - } - - @Override - public int getZ() { - return chunk.getPos().z; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.a()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(section.getEmittedLightArray()); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(section.getSkyLightArray()); - - // Block Data - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - NBTTagCompound blocksCompound = new NBTTagCompound(); - dataPaletteBlock.b(blocksCompound, "Palette", "BlockStates"); - NBTTagList paletteList = blocksCompound.getList("Palette", 10); - ListTag palette = (ListTag) Converter.convertTag("", paletteList); - long[] blockStates = blocksCompound.o("BlockStates"); - - sections[sectionId] = new CraftSlimeChunkSection(null, null, palette, blockStates, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - // HeightMap - CompoundMap heightMaps = new CompoundMap(); - - for (HeightMap.Type type : chunk.heightMap.keySet()) { - heightMaps.put(type.b(), new LongArrayTag(type.b(), chunk.b(type).b())); - } - - return new CompoundTag("", heightMaps); - } - - @Override - public int[] getBiomes() { - BiomeBase[] biomeBases = chunk.getBiomeIndex(); - int[] biomes = new int[biomeBases.length]; - - for (int i = 0; i < biomeBases.length; i++) { - biomes[i] = IRegistry.BIOME.a(biomeBases[i]); - } - - return biomes; - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.f(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } -} diff --git a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/v1_13_R2SlimeNMS.java b/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/v1_13_R2SlimeNMS.java deleted file mode 100644 index a0d725e..0000000 --- a/slimeworldmanager-nms-v1_13_R2/src/main/java/com/grinderwolf/swm/nms/v1_13_R2/v1_13_R2SlimeNMS.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.grinderwolf.swm.nms.v1_13_R2; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import com.mojang.datafixers.DataFixTypes; -import lombok.Getter; -import net.minecraft.server.v1_13_R2.DataConverterRegistry; -import net.minecraft.server.v1_13_R2.DimensionManager; -import net.minecraft.server.v1_13_R2.GameProfileSerializer; -import net.minecraft.server.v1_13_R2.MinecraftServer; -import net.minecraft.server.v1_13_R2.NBTTagCompound; -import net.minecraft.server.v1_13_R2.WorldServer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_13_R2SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - public static final boolean IS_PAPER; - - static { - boolean paper = true; - - try { - Class.forName("com.destroystokyo.paper.PaperWorldConfig"); - } catch (ClassNotFoundException e) { - paper = false; - } - - IS_PAPER = paper; - } - - private final byte worldVersion = 0x04; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private WorldServer defaultWorld; - private WorldServer defaultNetherWorld; - private WorldServer defaultEndWorld; - - public v1_13_R2SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomDataManager(normalWorld), DimensionManager.OVERWORLD, World.Environment.NORMAL); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomDataManager(netherWorld), DimensionManager.a(env.getId()), env); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomDataManager(endWorld), DimensionManager.a(env.getId()), env); - } - - loadingDefaultWorlds = false; - } - - @Override - public Object createNMSWorld(SlimeWorld world) { - CustomDataManager dataManager = new CustomDataManager(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worldServer.size(); - - for (WorldServer server : mcServer.getWorlds()) { - if (server.dimension.getDimensionID() + 1 == dimension) { // getDimensionID() returns the dimension - 1 - dimension++; - } - } - - String worldName = world.getName(); - World.Environment env = World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - DimensionManager dimensionManager = new DimensionManager(dimension, worldName, worldName, () -> DimensionManager.a(env.getId()).e()); - - return new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimensionManager, env); - } - - @Override - public void generateWorld(SlimeWorld world) { - addWorldToServerList(createNMSWorld(world)); - } - - @Override - public void addWorldToServerList(Object worldObject) { - if (!(worldObject instanceof WorldServer)) { - throw new IllegalArgumentException("World object must be an instance of WorldServer!"); - } - - CustomWorldServer server = (CustomWorldServer) worldObject; - String worldName = server.getWorldData().getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - MinecraftServer mcServer = MinecraftServer.getServer(); - - mcServer.server.addWorld(server.getWorld()); - MinecraftServer.getServer().worldServer.put(server.dimension, server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - - return worldServer.getSlimeWorld(); - } - - @Override - public CompoundTag convertChunk(CompoundTag tag) { - NBTTagCompound nmsTag = (NBTTagCompound) Converter.convertTag(tag); - int version = nmsTag.getInt("DataVersion"); - - NBTTagCompound newNmsTag = GameProfileSerializer.a(DataConverterRegistry.a(), DataFixTypes.CHUNK, nmsTag, version); - - return (CompoundTag) Converter.convertTag("", newNmsTag); - } -} diff --git a/slimeworldmanager-nms-v1_14_R1/pom.xml b/slimeworldmanager-nms-v1_14_R1/pom.xml deleted file mode 100644 index 1b5794d..0000000 --- a/slimeworldmanager-nms-v1_14_R1/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_14_R1 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - org.spigotmc - spigot - 1.14.4-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/Converter.java b/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/Converter.java deleted file mode 100644 index 6fc6486..0000000 --- a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/Converter.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.grinderwolf.swm.nms.v1_14_R1; - -import com.flowpowered.nbt.Tag; -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import net.minecraft.server.v1_14_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_14_R1.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_14_R1.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_14_R1.NibbleArray array) { - if (array == null) { - return null; - } - - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return new NBTTagByte(((ByteTag) tag).getValue()); - case TAG_SHORT: - return new NBTTagShort(((ShortTag) tag).getValue()); - case TAG_INT: - return new NBTTagInt(((IntTag) tag).getValue()); - case TAG_LONG: - return new NBTTagLong(((LongTag) tag).getValue()); - case TAG_FLOAT: - return new NBTTagFloat(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return new NBTTagDouble(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return new NBTTagString(((StringTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LONG_ARRAY: - return new NBTTagLongArray(((LongArrayTag) tag).getValue()); - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).asByte()); - case 2: - return new ShortTag(name, ((NBTTagShort) base).asShort()); - case 3: - return new IntTag(name, ((NBTTagInt) base).asInt()); - case 4: - return new LongTag(name, ((NBTTagLong) base).asLong()); - case 5: - return new FloatTag(name, ((NBTTagFloat) base).asFloat()); - case 6: - return new DoubleTag(name, ((NBTTagDouble) base).asDouble()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).getBytes()); - case 8: - return new StringTag(name, ((NBTTagString) base).asString()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (NBTBase entry : originalList) { - list.add(convertTag("", entry)); - } - - return new ListTag(name, TagType.getById(originalList.a_()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.getKeys()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).getInts()); - case 12: - return new LongArrayTag("", ((NBTTagLongArray) base).getLongs()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } - -} \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CraftCLSMBridge.java deleted file mode 100644 index 75d1398..0000000 --- a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CraftCLSMBridge.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.grinderwolf.swm.nms.v1_14_R1; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_14_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class CraftCLSMBridge implements CLSMBridge { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final v1_14_R1SlimeNMS nmsInstance; - - @Override - public Object getChunk(Object worldObject, int x, int z) { - if (!(worldObject instanceof CustomWorldServer)) { - return null; // Returning null will just run the original getChunk method - } - - CustomWorldServer world = (CustomWorldServer) worldObject; - - return world.getChunk(x, z); - } - - @Override - public boolean saveChunk(Object world, Object chunkAccess) { - if (!(world instanceof CustomWorldServer)) { - return false; // Returning false will just run the original saveChunk method - } - - if (!(chunkAccess instanceof ProtoChunkExtension || chunkAccess instanceof Chunk) || !((IChunkAccess) chunkAccess).isNeedsSaving()) { - // We're only storing fully-loaded chunks that need to be saved - return true; - } - - Chunk chunk; - - if (chunkAccess instanceof ProtoChunkExtension) { - chunk = ((ProtoChunkExtension) chunkAccess).u(); - } else { - chunk = (Chunk) chunkAccess; - } - - - ((CustomWorldServer) world).saveChunk(chunk); - chunk.setNeedsSaving(false); - - return true; - } - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_14_R1SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomNBTStorage.java b/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomNBTStorage.java deleted file mode 100644 index 3064e60..0000000 --- a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomNBTStorage.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.grinderwolf.swm.nms.v1_14_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_14_R1.*; - -import java.io.File; -import java.util.UUID; - -@Getter -public class CustomNBTStorage extends WorldNBTStorage { - - private static final GameRules EMPTY_GAMERULES = new GameRules(); - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private WorldData worldData; - - public CustomNBTStorage(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), null, null); - - this.world = world; - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override public void checkSession() { } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.v().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomWorldData.java b/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomWorldData.java deleted file mode 100644 index bdad0e9..0000000 --- a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomWorldData.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.grinderwolf.swm.nms.v1_14_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_14_R1.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.v().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } - - @Override - public boolean u() { - return true; - } -} \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomWorldServer.java b/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomWorldServer.java deleted file mode 100644 index 093cd95..0000000 --- a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/CustomWorldServer.java +++ /dev/null @@ -1,330 +0,0 @@ -package com.grinderwolf.swm.nms.v1_14_R1; - -import com.flowpowered.nbt.*; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeChunk; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_14_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Consumer; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - private final List maps = new ArrayList<>(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, WorldNBTStorage nbtStorage, DimensionManager dimensionManager, World.Environment env) { - super(MinecraftServer.getServer(), MinecraftServer.getServer().executorService, nbtStorage, nbtStorage.getWorldData(), - dimensionManager, MinecraftServer.getServer().getMethodProfiler(), MinecraftServer.getServer().worldLoadListenerFactory.create(11), env, null); - - this.slimeWorld = world; - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - new File(nbtStorage.getDirectory(), "session.lock").delete(); - new File(nbtStorage.getDirectory(), "data").delete(); - - nbtStorage.getDirectory().delete(); - nbtStorage.getDirectory().getParentFile().delete(); - - for (CompoundTag mapTag : world.getWorldMaps()) { - int id = mapTag.getIntValue("id").get(); - WorldMap map = new WorldMap("map_" + id); - map.a((NBTTagCompound) Converter.convertTag(mapTag)); - a(map); - } - } - - @Override - public void save(IProgressUpdate progressUpdate, boolean forceSave, boolean flag1) { - if (!slimeWorld.isReadOnly()) { - org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit - this.getChunkProvider().save(forceSave); - this.getDataManager().saveWorldData(worldData, null); - - // Update the map compound list - slimeWorld.getWorldMaps().clear(); - - for (WorldMap map : maps) { - NBTTagCompound compound = map.b(new NBTTagCompound()); - int id = Integer.parseInt(map.getId().substring(4)); - compound.setInt("id", id); - - slimeWorld.getWorldMaps().add((CompoundTag) Converter.convertTag("", compound)); - } - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the SlimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - - ProtoChunkExtension getChunk(int x, int z) { - SlimeChunk slimeChunk = slimeWorld.getChunk(x, z); - Chunk chunk; - - if (slimeChunk == null) { - BiomeBase[] biomeBaseArray = new BiomeBase[256]; - BlockPosition.MutableBlockPosition mutableBlockPosition = new BlockPosition.MutableBlockPosition(); - - for (int i = 0; i < biomeBaseArray.length; i++) { - biomeBaseArray[i] = getChunkProvider().getChunkGenerator().getWorldChunkManager().getBiome(mutableBlockPosition - .d((i & 15) + (x << 4), 0, (i >> 4 & 15) + (z << 4))); - } - - // Tick lists - TickListChunk airChunkTickList = new TickListChunk<>(IRegistry.BLOCK::getKey, new ArrayList<>()); - TickListChunk fluidChunkTickList = new TickListChunk<>(IRegistry.FLUID::getKey, new ArrayList<>()); - - ChunkCoordIntPair pos = new ChunkCoordIntPair(x, z); - chunk = new Chunk(this, pos, biomeBaseArray, ChunkConverter.a, airChunkTickList, fluidChunkTickList, 0L, null, null); - HeightMap.a(chunk, chunk.getChunkStatus().h()); - - getChunkProvider().getLightEngine().b(pos, true); - } else if (slimeChunk instanceof NMSSlimeChunk) { - chunk = ((NMSSlimeChunk) slimeChunk).getChunk(); - } else { - chunk = createChunk(slimeChunk); - slimeWorld.updateChunk(new NMSSlimeChunk(chunk)); - } - - return new ProtoChunkExtension(chunk); - } - - private Chunk createChunk(SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + slimeWorld.getName()); - - ChunkCoordIntPair pos = new ChunkCoordIntPair(x, z); - BlockPosition.MutableBlockPosition mutableBlockPosition = new BlockPosition.MutableBlockPosition(); - - // Tick lists - TickListChunk airChunkTickList = new TickListChunk<>(IRegistry.BLOCK::getKey, new ArrayList<>()); - TickListChunk fluidChunkTickList = new TickListChunk<>(IRegistry.FLUID::getKey, new ArrayList<>()); - - // Biomes - BiomeBase[] biomeBaseArray = new BiomeBase[256]; - int[] biomeIntArray = chunk.getBiomes(); - - for (int i = 0; i < biomeIntArray.length; i++) { - biomeBaseArray[i] = IRegistry.BIOME.fromId(biomeIntArray[i]); - - if (biomeBaseArray[i] == null) { - biomeBaseArray[i] = getChunkProvider().getChunkGenerator().getWorldChunkManager().getBiome(mutableBlockPosition - .c((i & 15) + (pos.x << 4), 0, (i >> 4 & 15) + (pos.z << 4))); - } - } - - // Chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - ChunkSection[] sections = new ChunkSection[16]; - LightEngine lightEngine = getChunkProvider().getLightEngine(); - - lightEngine.b(pos, true); - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null && slimeSection.getBlockStates().length > 0) { // If block states array is empty, it's just a fake chunk made by the createEmptyWorld method - ChunkSection section = new ChunkSection(sectionId << 4); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + pos.x + ", " + pos.z + ") - World " + slimeWorld.getName() + ":"); - LOGGER.debug("Block palette:"); - LOGGER.debug(slimeSection.getPalette().toString()); - LOGGER.debug("Block states array:"); - LOGGER.debug(slimeSection.getBlockStates()); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - section.getBlocks().a((NBTTagList) Converter.convertTag(slimeSection.getPalette()), slimeSection.getBlockStates()); - - if (slimeSection.getBlockLight() != null) { - lightEngine.a(EnumSkyBlock.BLOCK, SectionPosition.a(pos, sectionId), Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - lightEngine.a(EnumSkyBlock.SKY, SectionPosition.a(pos, sectionId), Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - Consumer loadEntities = (nmsChunk) -> { - - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - List tileEntities = chunk.getTileEntities(); - int loadedEntities = 0; - - if (tileEntities != null) { - for (CompoundTag tag : tileEntities) { - Optional type = tag.getStringValue("id"); - - // Sometimes null tile entities are saved - if (type.isPresent()) { - TileEntity entity = TileEntity.create((NBTTagCompound) Converter.convertTag(tag)); - - if (entity != null) { - nmsChunk.a(entity); - loadedEntities++; - } - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - List entities = chunk.getEntities(); - loadedEntities = 0; - - if (entities != null) { - for (CompoundTag tag : entities) { - EntityTypes.a((NBTTagCompound) Converter.convertTag(tag), nmsChunk.world, (entity) -> { - - nmsChunk.a(entity); - return entity; - - }); - - nmsChunk.d(true); - loadedEntities++; - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - - }; - - CompoundTag upgradeDataTag = ((CraftSlimeChunk) chunk).getUpgradeData(); - Chunk nmsChunk = new Chunk(this, pos, biomeBaseArray, upgradeDataTag == null ? ChunkConverter.a : new ChunkConverter((NBTTagCompound) - Converter.convertTag(upgradeDataTag)), airChunkTickList, fluidChunkTickList, 0L, sections, loadEntities); - - // Height Maps - EnumSet heightMapTypes = nmsChunk.getChunkStatus().h(); - CompoundMap heightMaps = chunk.getHeightMaps().getValue(); - EnumSet unsetHeightMaps = EnumSet.noneOf(HeightMap.Type.class); - - for (HeightMap.Type type : heightMapTypes) { - String name = type.a(); - - if (heightMaps.containsKey(name)) { - LongArrayTag heightMap = (LongArrayTag) heightMaps.get(name); - nmsChunk.a(type, heightMap.getValue()); - } else { - unsetHeightMaps.add(type); - } - } - - HeightMap.a(nmsChunk, unsetHeightMaps); - LOGGER.debug("Loaded chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - - return nmsChunk; - } - - void saveChunk(Chunk chunk) { - SlimeChunk slimeChunk = slimeWorld.getChunk(chunk.getPos().x, chunk.getPos().z); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk(chunk); - } else { - slimeWorld.updateChunk(new NMSSlimeChunk(chunk)); - } - } - - @Override - public WorldMap a(String name) { - int id = Integer.parseInt(name.substring(4)); - - if (id >= maps.size()) { - return null;//super.a(name); - } - - return maps.get(id); - } - - @Override - public void a(WorldMap map) { - int id = Integer.parseInt(map.getId().substring(4)); - - if (maps.size() > id) { - maps.set(id, map); - } else { - while (maps.size() < id) { - maps.add(null); - } - - maps.add(id, map); - } - } - - @Override - public int getWorldMapCount() { - return maps.size(); - } -} \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/NMSSlimeChunk.java deleted file mode 100644 index 86eabf5..0000000 --- a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/NMSSlimeChunk.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.grinderwolf.swm.nms.v1_14_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_14_R1.*; - -import java.util.ArrayList; -import java.util.List; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.getPos().x; - } - - @Override - public int getZ() { - return chunk.getPos().z; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - LightEngine lightEngine = chunk.world.getChunkProvider().getLightEngine(); - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.c()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(lightEngine.a(EnumSkyBlock.BLOCK).a(SectionPosition.a(chunk.getPos(), sectionId))); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(lightEngine.a(EnumSkyBlock.SKY).a(SectionPosition.a(chunk.getPos(), sectionId))); - - // Block Data - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - NBTTagCompound blocksCompound = new NBTTagCompound(); - dataPaletteBlock.a(blocksCompound, "Palette", "BlockStates"); - NBTTagList paletteList = blocksCompound.getList("Palette", 10); - ListTag palette = (ListTag) Converter.convertTag("", paletteList); - long[] blockStates = blocksCompound.getLongArray("BlockStates"); - - sections[sectionId] = new CraftSlimeChunkSection(null, null, palette, blockStates, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - // HeightMap - CompoundMap heightMaps = new CompoundMap(); - - for (HeightMap.Type type : chunk.heightMap.keySet()) { - heightMaps.put(type.a(), new LongArrayTag(type.a(), chunk.b(type).a())); - } - - return new CompoundTag("", heightMaps); - } - - @Override - public int[] getBiomes() { - BiomeBase[] biomeBases = chunk.getBiomeIndex(); - int[] biomes = new int[biomeBases.length]; - - for (int i = 0; i < biomeBases.length; i++) { - biomes[i] = IRegistry.BIOME.a(biomeBases[i]); - } - - return biomes; - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.d(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } -} diff --git a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/v1_14_R1SlimeNMS.java b/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/v1_14_R1SlimeNMS.java deleted file mode 100644 index 7807bf1..0000000 --- a/slimeworldmanager-nms-v1_14_R1/src/main/java/com/grinderwolf/swm/nms/v1_14_R1/v1_14_R1SlimeNMS.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.grinderwolf.swm.nms.v1_14_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import lombok.Getter; -import net.minecraft.server.v1_14_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_14_R1SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - - private final byte worldVersion = 0x05; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private CustomWorldServer defaultWorld; - private CustomWorldServer defaultNetherWorld; - private CustomWorldServer defaultEndWorld; - - public v1_14_R1SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomNBTStorage(normalWorld), DimensionManager.OVERWORLD, World.Environment.NORMAL); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomNBTStorage(netherWorld), DimensionManager.a(env.getId()), env); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomNBTStorage(endWorld), DimensionManager.a(env.getId()), env); - } - - loadingDefaultWorlds = false; - } - - @Override - public void generateWorld(SlimeWorld world) { - String worldName = world.getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - CustomNBTStorage dataManager = new CustomNBTStorage(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worldServer.size(); - boolean used = false; - - do { - for (WorldServer server : mcServer.getWorlds()) { - used = server.getWorldProvider().getDimensionManager().getDimensionID() + 1 == dimension; - - if (used) { // getDimensionID() returns the dimension - 1 - dimension++; - break; - } - } - } while (used); - - World.Environment env = World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - DimensionManager actualDimension = DimensionManager.a(env.getId()); - DimensionManager dimensionManager = DimensionManager.register(worldName, new DimensionManager(dimension, actualDimension.getSuffix(), - actualDimension.folder, actualDimension.providerFactory, actualDimension.hasSkyLight(), actualDimension)); - CustomWorldServer server = new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimensionManager, env); - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - mcServer.initWorld(server, dataManager.getWorldData(), new WorldSettings(dataManager.getWorldData())); - - mcServer.server.addWorld(server.getWorld()); - mcServer.worldServer.put(dimensionManager, server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - - if (server.getWorld().getKeepSpawnInMemory()) { - LOGGER.debug("Preparing start region for dimension '{}'/{}", worldName, DimensionManager.a(0)); - BlockPosition spawn = server.getSpawn(); - ChunkProviderServer provider = server.getChunkProvider(); - provider.addTicket(TicketType.START, new ChunkCoordIntPair(spawn), 11, Unit.INSTANCE); - } - - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - return worldServer.getSlimeWorld(); - } - - @Override - public CompoundTag convertChunk(CompoundTag tag) { - NBTTagCompound nmsTag = (NBTTagCompound) Converter.convertTag(tag); - int version = nmsTag.getInt("DataVersion"); - - NBTTagCompound newNmsTag = GameProfileSerializer.a(DataConverterRegistry.a(), DataFixTypes.CHUNK, nmsTag, version); - - return (CompoundTag) Converter.convertTag("", newNmsTag); - } -} diff --git a/slimeworldmanager-nms-v1_15_R1/pom.xml b/slimeworldmanager-nms-v1_15_R1/pom.xml deleted file mode 100644 index 72a3ebc..0000000 --- a/slimeworldmanager-nms-v1_15_R1/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_15_R1 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - org.spigotmc - spigot - 1.15.1-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/Converter.java b/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/Converter.java deleted file mode 100644 index 175137e..0000000 --- a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/Converter.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.grinderwolf.swm.nms.v1_15_R1; - -import com.flowpowered.nbt.Tag; -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import net.minecraft.server.v1_15_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_15_R1.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_15_R1.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_15_R1.NibbleArray array) { - if (array == null) { - return null; - } - - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return NBTTagByte.a(((ByteTag) tag).getValue()); - case TAG_SHORT: - return NBTTagShort.a(((ShortTag) tag).getValue()); - case TAG_INT: - return NBTTagInt.a(((IntTag) tag).getValue()); - case TAG_LONG: - return NBTTagLong.a(((LongTag) tag).getValue()); - case TAG_FLOAT: - return NBTTagFloat.a(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return NBTTagDouble.a(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return NBTTagString.a(((StringTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LONG_ARRAY: - return new NBTTagLongArray(((LongArrayTag) tag).getValue()); - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).asByte()); - case 2: - return new ShortTag(name, ((NBTTagShort) base).asShort()); - case 3: - return new IntTag(name, ((NBTTagInt) base).asInt()); - case 4: - return new LongTag(name, ((NBTTagLong) base).asLong()); - case 5: - return new FloatTag(name, ((NBTTagFloat) base).asFloat()); - case 6: - return new DoubleTag(name, ((NBTTagDouble) base).asDouble()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).getBytes()); - case 8: - return new StringTag(name, ((NBTTagString) base).asString()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (NBTBase entry : originalList) { - list.add(convertTag("", entry)); - } - - return new ListTag<>(name, TagType.getById(originalList.a_()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.getKeys()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).getInts()); - case 12: - return new LongArrayTag("", ((NBTTagLongArray) base).getLongs()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } - -} \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CraftCLSMBridge.java deleted file mode 100644 index c767d32..0000000 --- a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CraftCLSMBridge.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.grinderwolf.swm.nms.v1_15_R1; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_15_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class CraftCLSMBridge implements CLSMBridge { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final v1_15_R1SlimeNMS nmsInstance; - - @Override - public Object getChunk(Object worldObject, int x, int z) { - if (!(worldObject instanceof CustomWorldServer)) { - return null; // Returning null will just run the original getChunk method - } - - CustomWorldServer world = (CustomWorldServer) worldObject; - - return world.getChunk(x, z); - } - - @Override - public boolean saveChunk(Object world, Object chunkAccess) { - if (!(world instanceof CustomWorldServer)) { - return false; // Returning false will just run the original saveChunk method - } - - if (!(chunkAccess instanceof ProtoChunkExtension || chunkAccess instanceof Chunk) || !((IChunkAccess) chunkAccess).isNeedsSaving()) { - // We're only storing fully-loaded chunks that need to be saved - return true; - } - - Chunk chunk; - - if (chunkAccess instanceof ProtoChunkExtension) { - chunk = ((ProtoChunkExtension) chunkAccess).u(); - } else { - chunk = (Chunk) chunkAccess; - } - - - ((CustomWorldServer) world).saveChunk(chunk); - chunk.setNeedsSaving(false); - - return true; - } - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_15_R1SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomNBTStorage.java b/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomNBTStorage.java deleted file mode 100644 index 0637fb0..0000000 --- a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomNBTStorage.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.grinderwolf.swm.nms.v1_15_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_15_R1.*; - -import java.io.File; -import java.util.UUID; - -@Getter -public class CustomNBTStorage extends WorldNBTStorage { - - private static final GameRules EMPTY_GAMERULES = new GameRules(); - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private WorldData worldData; - - public CustomNBTStorage(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), null, null); - - this.world = world; - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override public void checkSession() { } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.v().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomWorldData.java b/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomWorldData.java deleted file mode 100644 index 804ccc6..0000000 --- a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomWorldData.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.grinderwolf.swm.nms.v1_15_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_15_R1.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.v().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } - - @Override - public boolean u() { - return true; - } -} \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomWorldServer.java b/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomWorldServer.java deleted file mode 100644 index 7eafa55..0000000 --- a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/CustomWorldServer.java +++ /dev/null @@ -1,316 +0,0 @@ -package com.grinderwolf.swm.nms.v1_15_R1; - -import com.flowpowered.nbt.*; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeChunk; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_15_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Consumer; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - private final List maps = new ArrayList<>(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, WorldNBTStorage nbtStorage, DimensionManager dimensionManager, World.Environment env) { - super(MinecraftServer.getServer(), MinecraftServer.getServer().executorService, nbtStorage, nbtStorage.getWorldData(), - dimensionManager, MinecraftServer.getServer().getMethodProfiler(), MinecraftServer.getServer().worldLoadListenerFactory.create(11), env, null); - - this.slimeWorld = world; - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - new File(nbtStorage.getDirectory(), "session.lock").delete(); - new File(nbtStorage.getDirectory(), "data").delete(); - - nbtStorage.getDirectory().delete(); - nbtStorage.getDirectory().getParentFile().delete(); - - for (CompoundTag mapTag : world.getWorldMaps()) { - int id = mapTag.getIntValue("id").get(); - WorldMap map = new WorldMap("map_" + id); - map.a((NBTTagCompound) Converter.convertTag(mapTag)); - a(map); - } - } - - @Override - public void save(IProgressUpdate progressUpdate, boolean forceSave, boolean flag1) { - if (!slimeWorld.isReadOnly()) { - org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit - this.getChunkProvider().save(forceSave); - this.getDataManager().saveWorldData(worldData, null); - - // Update the map compound list - slimeWorld.getWorldMaps().clear(); - - for (WorldMap map : maps) { - NBTTagCompound compound = map.b(new NBTTagCompound()); - int id = Integer.parseInt(map.getId().substring(4)); - compound.setInt("id", id); - - slimeWorld.getWorldMaps().add((CompoundTag) Converter.convertTag("", compound)); - } - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the SlimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - - ProtoChunkExtension getChunk(int x, int z) { - SlimeChunk slimeChunk = slimeWorld.getChunk(x, z); - Chunk chunk; - - if (slimeChunk == null) { - ChunkCoordIntPair pos = new ChunkCoordIntPair(x, z); - - // Biomes - BiomeStorage biomeStorage = new BiomeStorage(pos, getChunkProvider().getChunkGenerator().getWorldChunkManager(), null); - - // Tick lists - TickListChunk airChunkTickList = new TickListChunk<>(IRegistry.BLOCK::getKey, new ArrayList<>()); - TickListChunk fluidChunkTickList = new TickListChunk<>(IRegistry.FLUID::getKey, new ArrayList<>()); - - chunk = new Chunk(this, pos, biomeStorage, ChunkConverter.a, airChunkTickList, fluidChunkTickList, 0L, null, null); - HeightMap.a(chunk, chunk.getChunkStatus().h()); - - getChunkProvider().getLightEngine().b(pos, true); - } else if (slimeChunk instanceof NMSSlimeChunk) { - chunk = ((NMSSlimeChunk) slimeChunk).getChunk(); - } else { - chunk = createChunk(slimeChunk); - slimeWorld.updateChunk(new NMSSlimeChunk(chunk)); - } - - return new ProtoChunkExtension(chunk); - } - - private Chunk createChunk(SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + slimeWorld.getName()); - - ChunkCoordIntPair pos = new ChunkCoordIntPair(x, z); - - // Biomes - int[] biomeIntArray = chunk.getBiomes(); - BiomeStorage biomeStorage = new BiomeStorage(pos, getChunkProvider().getChunkGenerator().getWorldChunkManager(), biomeIntArray); - - // Tick lists - TickListChunk airChunkTickList = new TickListChunk<>(IRegistry.BLOCK::getKey, new ArrayList<>()); - TickListChunk fluidChunkTickList = new TickListChunk<>(IRegistry.FLUID::getKey, new ArrayList<>()); - - // Chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - ChunkSection[] sections = new ChunkSection[16]; - LightEngine lightEngine = getChunkProvider().getLightEngine(); - - lightEngine.b(pos, true); - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null) { - ChunkSection section = new ChunkSection(sectionId << 4); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + pos.x + ", " + pos.z + ") - World " + slimeWorld.getName() + ":"); - LOGGER.debug("Block palette:"); - LOGGER.debug(slimeSection.getPalette().toString()); - LOGGER.debug("Block states array:"); - LOGGER.debug(slimeSection.getBlockStates()); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - section.getBlocks().a((NBTTagList) Converter.convertTag(slimeSection.getPalette()), slimeSection.getBlockStates()); - - if (slimeSection.getBlockLight() != null) { - lightEngine.a(EnumSkyBlock.BLOCK, SectionPosition.a(pos, sectionId), Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - lightEngine.a(EnumSkyBlock.SKY, SectionPosition.a(pos, sectionId), Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - Consumer loadEntities = (nmsChunk) -> { - - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - List tileEntities = chunk.getTileEntities(); - int loadedEntities = 0; - - if (tileEntities != null) { - for (CompoundTag tag : tileEntities) { - Optional type = tag.getStringValue("id"); - - // Sometimes null tile entities are saved - if (type.isPresent()) { - TileEntity entity = TileEntity.create((NBTTagCompound) Converter.convertTag(tag)); - - if (entity != null) { - nmsChunk.a(entity); - loadedEntities++; - } - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - List entities = chunk.getEntities(); - loadedEntities = 0; - - if (entities != null) { - for (CompoundTag tag : entities) { - EntityTypes.a((NBTTagCompound) Converter.convertTag(tag), nmsChunk.world, (entity) -> { - - nmsChunk.a(entity); - return entity; - - }); - - nmsChunk.d(true); - loadedEntities++; - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - - }; - - CompoundTag upgradeDataTag = ((CraftSlimeChunk) chunk).getUpgradeData(); - Chunk nmsChunk = new Chunk(this, pos, biomeStorage, upgradeDataTag == null ? ChunkConverter.a : new ChunkConverter((NBTTagCompound) - Converter.convertTag(upgradeDataTag)), airChunkTickList, fluidChunkTickList, 0L, sections, loadEntities); - - // Height Maps - EnumSet heightMapTypes = nmsChunk.getChunkStatus().h(); - CompoundMap heightMaps = chunk.getHeightMaps().getValue(); - EnumSet unsetHeightMaps = EnumSet.noneOf(HeightMap.Type.class); - - for (HeightMap.Type type : heightMapTypes) { - String name = type.a(); - - if (heightMaps.containsKey(name)) { - LongArrayTag heightMap = (LongArrayTag) heightMaps.get(name); - nmsChunk.a(type, heightMap.getValue()); - } else { - unsetHeightMaps.add(type); - } - } - - HeightMap.a(nmsChunk, unsetHeightMaps); - LOGGER.debug("Loaded chunk (" + pos.x + ", " + pos.z + ") on world " + slimeWorld.getName()); - - return nmsChunk; - } - - void saveChunk(Chunk chunk) { - SlimeChunk slimeChunk = slimeWorld.getChunk(chunk.getPos().x, chunk.getPos().z); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk(chunk); - } else { - slimeWorld.updateChunk(new NMSSlimeChunk(chunk)); - } - } - - @Override - public WorldMap a(String name) { - int id = Integer.parseInt(name.substring(4)); - - if (id >= maps.size()) { - return null;//super.a(name); - } - - return maps.get(id); - } - - @Override - public void a(WorldMap map) { - int id = Integer.parseInt(map.getId().substring(4)); - - if (maps.size() > id) { - maps.set(id, map); - } else { - while (maps.size() < id) { - maps.add(null); - } - - maps.add(id, map); - } - } - - @Override - public int getWorldMapCount() { - return maps.size(); - } -} \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/NMSSlimeChunk.java deleted file mode 100644 index 67c428b..0000000 --- a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/NMSSlimeChunk.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.grinderwolf.swm.nms.v1_15_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_15_R1.*; - -import java.util.*; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.getPos().x; - } - - @Override - public int getZ() { - return chunk.getPos().z; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - LightEngine lightEngine = chunk.world.getChunkProvider().getLightEngine(); - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.c()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(lightEngine.a(EnumSkyBlock.BLOCK).a(SectionPosition.a(chunk.getPos(), sectionId))); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(lightEngine.a(EnumSkyBlock.SKY).a(SectionPosition.a(chunk.getPos(), sectionId))); - - // Block Data - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - NBTTagCompound blocksCompound = new NBTTagCompound(); - dataPaletteBlock.a(blocksCompound, "Palette", "BlockStates"); - NBTTagList paletteList = blocksCompound.getList("Palette", 10); - ListTag palette = (ListTag) Converter.convertTag("", paletteList); - long[] blockStates = blocksCompound.getLongArray("BlockStates"); - - sections[sectionId] = new CraftSlimeChunkSection(null, null, palette, blockStates, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - // HeightMap - CompoundMap heightMaps = new CompoundMap(); - - for (Map.Entry entry : chunk.heightMap.entrySet()) { - HeightMap.Type type = entry.getKey(); - HeightMap map = entry.getValue(); - - heightMaps.put(type.a(), new LongArrayTag(type.a(), map.a())); - } - - return new CompoundTag("", heightMaps); - } - - @Override - public int[] getBiomes() { - return chunk.getBiomeIndex().a(); - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.d(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } -} diff --git a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/v1_15_R1SlimeNMS.java b/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/v1_15_R1SlimeNMS.java deleted file mode 100644 index d9fddc1..0000000 --- a/slimeworldmanager-nms-v1_15_R1/src/main/java/com/grinderwolf/swm/nms/v1_15_R1/v1_15_R1SlimeNMS.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.grinderwolf.swm.nms.v1_15_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import lombok.Getter; -import net.minecraft.server.v1_15_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_15_R1SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - - private final byte worldVersion = 0x05; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private CustomWorldServer defaultWorld; - private CustomWorldServer defaultNetherWorld; - private CustomWorldServer defaultEndWorld; - - public v1_15_R1SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomNBTStorage(normalWorld), DimensionManager.OVERWORLD, World.Environment.NORMAL); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomNBTStorage(netherWorld), DimensionManager.a(env.getId()), env); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomNBTStorage(endWorld), DimensionManager.a(env.getId()), env); - } - - loadingDefaultWorlds = false; - } - - @Override - public void generateWorld(SlimeWorld world) { - String worldName = world.getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - CustomNBTStorage dataManager = new CustomNBTStorage(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worldServer.size(); - boolean used = false; - - do { - for (WorldServer server : mcServer.getWorlds()) { - used = server.getWorldProvider().getDimensionManager().getDimensionID() + 1 == dimension; - - if (used) { // getDimensionID() returns the dimension - 1 - dimension++; - break; - } - } - } while (used); - - World.Environment env = World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - DimensionManager actualDimension = DimensionManager.a(env.getId()); - DimensionManager dimensionManager = DimensionManager.register(worldName, new DimensionManager(dimension, actualDimension.getSuffix(), - actualDimension.folder, actualDimension.providerFactory::apply, actualDimension.hasSkyLight(), actualDimension - .getGenLayerZoomer(), actualDimension)); - - CustomWorldServer server = new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimensionManager, env); - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - mcServer.initWorld(server, dataManager.getWorldData(), new WorldSettings(dataManager.getWorldData())); - - mcServer.server.addWorld(server.getWorld()); - mcServer.worldServer.put(dimensionManager, server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - - if (server.getWorld().getKeepSpawnInMemory()) { - LOGGER.debug("Preparing start region for dimension '{}'/{}", worldName, DimensionManager.a(0)); - BlockPosition spawn = server.getSpawn(); - ChunkProviderServer provider = server.getChunkProvider(); - provider.addTicket(TicketType.START, new ChunkCoordIntPair(spawn), 11, Unit.INSTANCE); - } - - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - return worldServer.getSlimeWorld(); - } - - @Override - public CompoundTag convertChunk(CompoundTag tag) { - NBTTagCompound nmsTag = (NBTTagCompound) Converter.convertTag(tag); - int version = nmsTag.getInt("DataVersion"); - - NBTTagCompound newNmsTag = GameProfileSerializer.a(DataConverterRegistry.a(), DataFixTypes.CHUNK, nmsTag, version); - - return (CompoundTag) Converter.convertTag("", newNmsTag); - } -} diff --git a/slimeworldmanager-nms-v1_9_R1/pom.xml b/slimeworldmanager-nms-v1_9_R1/pom.xml deleted file mode 100644 index 782f6cd..0000000 --- a/slimeworldmanager-nms-v1_9_R1/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_9_R1 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - org.spigotmc - spigot - 1.9-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/Converter.java b/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/Converter.java deleted file mode 100644 index d2f916f..0000000 --- a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/Converter.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import net.minecraft.server.v1_9_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_9_R1.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_9_R1.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_9_R1.NibbleArray array) { - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return new NBTTagByte(((ByteTag) tag).getValue()); - case TAG_SHORT: - return new NBTTagShort(((ShortTag) tag).getValue()); - case TAG_INT: - return new NBTTagInt(((IntTag) tag).getValue()); - case TAG_LONG: - return new NBTTagLong(((LongTag) tag).getValue()); - case TAG_FLOAT: - return new NBTTagFloat(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return new NBTTagDouble(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return new NBTTagString(((StringTag) tag).getValue()); - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).f()); - case 2: - return new ShortTag(name, ((NBTBase.NBTNumber) base).e()); - case 3: - return new IntTag(name, ((NBTBase.NBTNumber) base).d()); - case 4: - return new LongTag(name, ((NBTBase.NBTNumber) base).c()); - case 5: - return new FloatTag(name, ((NBTBase.NBTNumber) base).h()); - case 6: - return new DoubleTag(name, ((NBTBase.NBTNumber) base).g()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).c()); - case 8: - return new StringTag(name, ((NBTTagString) base).a_()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (int i = 0; i < originalList.size(); i++) { - NBTBase entry = originalList.h(i); - list.add(convertTag("", entry)); - } - - return new ListTag<>(name, TagType.getById(originalList.d()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.c()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).c()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } - -} diff --git a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CraftCLSMBridge.java deleted file mode 100644 index 8b15a7f..0000000 --- a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CraftCLSMBridge.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R1; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_9_R1.WorldServer; - -@RequiredArgsConstructor -public class CraftCLSMBridge implements CLSMBridge { - - private final v1_9_R1SlimeNMS nmsInstance; - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_9_R1SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomChunkLoader.java b/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomChunkLoader.java deleted file mode 100644 index 7a5fe76..0000000 --- a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomChunkLoader.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R1; - -import com.flowpowered.nbt.CompoundMap; -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_9_R1.Chunk; -import net.minecraft.server.v1_9_R1.ChunkSection; -import net.minecraft.server.v1_9_R1.Entity; -import net.minecraft.server.v1_9_R1.EntityTypes; -import net.minecraft.server.v1_9_R1.IChunkLoader; -import net.minecraft.server.v1_9_R1.NBTTagCompound; -import net.minecraft.server.v1_9_R1.TileEntity; -import net.minecraft.server.v1_9_R1.World; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.*; - -@RequiredArgsConstructor -public class CustomChunkLoader implements IChunkLoader { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final CraftSlimeWorld world; - - void loadAllChunks(CustomWorldServer server) { - for (SlimeChunk chunk : new ArrayList<>(world.getChunks().values())) { - Chunk nmsChunk = createChunk(server, chunk); - world.updateChunk(new NMSSlimeChunk(nmsChunk)); - } - } - - private Chunk createChunk(CustomWorldServer server, SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + world.getName()); - - Chunk nmsChunk = new Chunk(server, x, z); - - nmsChunk.d(true); - nmsChunk.e(true); - - CompoundTag heightMapsCompound = chunk.getHeightMaps(); - int[] heightMap = heightMapsCompound.getIntArrayValue("heightMap").get(); - - nmsChunk.a(heightMap); - - // Load chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + x + ", " + z + ") on world " + world.getName()); - ChunkSection[] sections = new ChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null) { - ChunkSection section = new ChunkSection(sectionId << 4, true); - NibbleArray data = slimeSection.getData(); - byte[] blocks = slimeSection.getBlocks(); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + x + ", " + z + ") - World " + world.getName() + ":"); - LOGGER.debug("Blocks:"); - LOGGER.debug(blocks); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - section.getBlocks().a(blocks, Converter.convertArray(data), new net.minecraft.server.v1_9_R1.NibbleArray()); - - if (slimeSection.getBlockLight() != null) { - section.a(Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - section.b(Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - nmsChunk.a(sections); - - // Biomes - nmsChunk.a(toByteArray(chunk.getBiomes())); - - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List tileEntities = chunk.getTileEntities(); - int loadedEntities = 0; - - if (tileEntities != null) { - for (CompoundTag tag : tileEntities) { - TileEntity entity = TileEntity.a(server.getMinecraftServer(), (NBTTagCompound) Converter.convertTag(tag)); - - if (entity != null) { - nmsChunk.a(entity); - loadedEntities++; - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List entities = chunk.getEntities(); - loadedEntities = 0; - - if (entities != null) { - for (CompoundTag tag : entities) { - loadEntity(tag, server, nmsChunk); - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - LOGGER.debug("Loaded chunk (" + x + ", " + z + ") on world " + world.getName()); - - return nmsChunk; - } - - private byte[] toByteArray(int[] ints) { - ByteBuffer buf = ByteBuffer.allocate(ints.length * 4).order(ByteOrder.LITTLE_ENDIAN); - buf.asIntBuffer().put(ints); - - return buf.array(); - } - - private Entity loadEntity(CompoundTag tag, World world, Chunk chunk) { - Entity entity = EntityTypes.a((NBTTagCompound) Converter.convertTag(tag), world); - chunk.g(true); - - if (entity != null) { - chunk.a(entity); - - CompoundMap map = tag.getValue(); - - if (map.containsKey("Passengers")) { - List passengersList = (List) map.get("Passengers").getValue(); - - for (CompoundTag passengerTag : passengersList) { - Entity passenger = loadEntity(passengerTag, world, chunk); - - if (passengerTag != null) { - passenger.a(entity, true); - } - } - } - } - - return entity; - } - - // Load chunk - @Override - public Chunk a(World nmsWorld, int x, int z) { - SlimeChunk slimeChunk = world.getChunk(x, z); - Chunk chunk; - - if (slimeChunk == null) { - chunk = new Chunk(nmsWorld, x, z); - - chunk.d(true); - chunk.e(true); - } else if (slimeChunk instanceof NMSSlimeChunk) { - chunk = ((NMSSlimeChunk) slimeChunk).getChunk(); - } else { // All SlimeChunk objects should be converted to NMSSlimeChunks when loading the world - throw new IllegalStateException("Chunk (" + x + ", " + z + ") has not been converted to a NMSSlimeChunk object!"); - } - - return chunk; - } - - // Save chunk - @Override - public void a(World world, Chunk chunk) { - SlimeChunk slimeChunk = this.world.getChunk(chunk.locX, chunk.locZ); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk(chunk); - } else { - this.world.updateChunk(new NMSSlimeChunk(chunk)); - } - } - - - // Save all chunks - @Override - public void b() { - - } - - // Does literally nothing - @Override - public void b(World world, Chunk chunk) { } - - // Does literally nothing - @Override - public void a() { } -} diff --git a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomDataManager.java b/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomDataManager.java deleted file mode 100644 index 5e4b98a..0000000 --- a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomDataManager.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.StringTag; -import com.flowpowered.nbt.Tag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_9_R1.EntityHuman; -import net.minecraft.server.v1_9_R1.GameRules; -import net.minecraft.server.v1_9_R1.IChunkLoader; -import net.minecraft.server.v1_9_R1.NBTTagCompound; -import net.minecraft.server.v1_9_R1.WorldData; -import net.minecraft.server.v1_9_R1.WorldNBTStorage; -import net.minecraft.server.v1_9_R1.WorldProvider; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - -@Getter -public class CustomDataManager extends WorldNBTStorage { - - private static final Map defaultValues; - - static { - GameRules emptyRules = new GameRules(); - String[] rules = emptyRules.getGameRules(); - - defaultValues = Arrays.stream(rules).collect(Collectors.toMap((rule) -> rule, emptyRules::get)); - } - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private final CustomChunkLoader chunkLoader; - private WorldData worldData; - - // When unloading a world, Spigot tries to remove the region file from its cache. - // To do so, it casts the world's IDataManager to a WorldNBTStorage, to be able - // to use the getDirectory() method. Thanks to this, we have to create a custom - // WorldNBTStorage with a fake file instead of just implementing the IDataManager interface - // - // Thanks Spigot! - CustomDataManager(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), false, null); - - // The WorldNBTStorage automatically creates some files inside the base dir, so we have to delete them - // (Thanks again Spigot) - - // Can't just access the baseDir field inside WorldNBTStorage cause it's private :P - File baseDir = new File("temp_" + world.getName(), world.getName()); - new File(baseDir, "session.lock").delete(); - new File(baseDir, "data").delete(); - - baseDir.delete(); - baseDir.getParentFile().delete(); - - this.world = world; - this.chunkLoader = new CustomChunkLoader((CraftSlimeWorld) world); - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override public void checkSession() { } - - @Override - public IChunkLoader createChunkLoader(WorldProvider worldProvider) { - return chunkLoader; - } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.w().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - // Remove default values to save space - for (Map.Entry> entry : new ArrayList<>(gameRules.getValue().entrySet())) { - String rule = entry.getKey(); - StringTag valueTag = (StringTag) entry.getValue(); - String defaultValue = defaultValues.get(rule); - - if (valueTag.getValue().equalsIgnoreCase(defaultValue)) { - gameRules.getValue().remove(rule); - } - } - - // Maybe all the gamerules stored were the default values - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public void a() { - - } - - @Override - public File getDataFile(String s) { - return null; - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} diff --git a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomWorldData.java b/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomWorldData.java deleted file mode 100644 index c7c3d69..0000000 --- a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomWorldData.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R1; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_9_R1.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(WorldSettings.EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.w().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } -} diff --git a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomWorldServer.java b/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomWorldServer.java deleted file mode 100644 index 8d717c7..0000000 --- a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/CustomWorldServer.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R1; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_9_R1.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, IDataManager dataManager, int dimension) { - super(MinecraftServer.getServer(), dataManager, dataManager.getWorldData(), dimension, MinecraftServer.getServer().methodProfiler, - World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()), null); - - b(); - this.slimeWorld = world; - this.tracker = new EntityTracker(this); - addIWorldAccess(new WorldManager(MinecraftServer.getServer(), this)); - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - // Load all chunks - CustomChunkLoader chunkLoader = ((CustomDataManager) this.getDataManager()).getChunkLoader(); - chunkLoader.loadAllChunks(this); - } - - @Override - public void save(boolean forceSave, IProgressUpdate progressUpdate) throws ExceptionWorldConflict { - if (!slimeWorld.isReadOnly()) { - super.save(forceSave, progressUpdate); - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the slimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } -} diff --git a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/NMSSlimeChunk.java deleted file mode 100644 index c16535d..0000000 --- a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/NMSSlimeChunk.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R1; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_9_R1.*; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.locX; - } - - @Override - public int getZ() { - return chunk.locZ; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.a()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(section.getEmittedLightArray()); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(section.getSkyLightArray()); - - // Block Data - byte[] blocks = new byte[4096]; - - net.minecraft.server.v1_9_R1.NibbleArray minecraftBlockDataArray = new net.minecraft.server.v1_9_R1.NibbleArray(); - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - dataPaletteBlock.exportData(blocks, minecraftBlockDataArray); - - NibbleArray blockDataArray = Converter.convertArray(minecraftBlockDataArray); - - sections[sectionId] = new CraftSlimeChunkSection(blocks, blockDataArray, null, null, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - CompoundTag heightMapsCompound = new CompoundTag("", new CompoundMap()); - heightMapsCompound.getValue().put("heightMap", new IntArrayTag("heightMap", chunk.heightMap)); - - return heightMapsCompound; - } - - @Override - public int[] getBiomes() { - return toIntArray(chunk.getBiomeIndex()); - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.g(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } - - private static int[] toIntArray(byte[] buf) { - ByteBuffer buffer = ByteBuffer.wrap(buf).order(ByteOrder.BIG_ENDIAN); - int[] ret = new int[buf.length / 4]; - - buffer.asIntBuffer().get(ret); - - return ret; - } -} diff --git a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/v1_9_R1SlimeNMS.java b/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/v1_9_R1SlimeNMS.java deleted file mode 100644 index 2b2c282..0000000 --- a/slimeworldmanager-nms-v1_9_R1/src/main/java/com/grinderwolf/swm/nms/v1_9_R1/v1_9_R1SlimeNMS.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R1; - -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import lombok.Getter; -import net.minecraft.server.v1_9_R1.MinecraftServer; -import net.minecraft.server.v1_9_R1.WorldServer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_9_R1.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_9_R1SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - - private final byte worldVersion = 0x02; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private WorldServer defaultWorld; - private WorldServer defaultNetherWorld; - private WorldServer defaultEndWorld; - - public v1_9_R1SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomDataManager(normalWorld), 0); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomDataManager(netherWorld), env.getId()); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomDataManager(endWorld), env.getId()); - } - - loadingDefaultWorlds = false; - } - - @Override - public Object createNMSWorld(SlimeWorld world) { - CustomDataManager dataManager = new CustomDataManager(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worlds.size(); - boolean used = false; - - do { - for (WorldServer server : mcServer.worlds) { - used = server.dimension == dimension; - - if (used) { - dimension++; - break; - } - } - } while (used); - - return new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimension); - } - - @Override - public void generateWorld(SlimeWorld world) { - addWorldToServerList(createNMSWorld(world)); - } - - @Override - public void addWorldToServerList(Object worldObject) { - if (!(worldObject instanceof WorldServer)) { - throw new IllegalArgumentException("World object must be an instance of WorldServer!"); - } - - CustomWorldServer server = (CustomWorldServer) worldObject; - String worldName = server.getWorldData().getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - MinecraftServer mcServer = MinecraftServer.getServer(); - - mcServer.server.addWorld(server.getWorld()); - mcServer.worlds.add(server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - - return worldServer.getSlimeWorld(); - } -} diff --git a/slimeworldmanager-nms-v1_9_R2/pom.xml b/slimeworldmanager-nms-v1_9_R2/pom.xml deleted file mode 100644 index 0c9d983..0000000 --- a/slimeworldmanager-nms-v1_9_R2/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - slimeworldmanager - com.grinderwolf - 2.2.0-SNAPSHOT - - 4.0.0 - - true - - - slimeworldmanager-nms-v1_9_R2 - - - - com.grinderwolf - slimeworldmanager-nms-common - ${project.version} - provided - - - com.grinderwolf - slimeworldmanager-api - ${project.version} - provided - - - org.spigotmc - spigot - 1.9.4-R0.1-SNAPSHOT - provided - - - com.grinderwolf - slimeworldmanager-classmodifier - ${project.version} - provided - - - - \ No newline at end of file diff --git a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/Converter.java b/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/Converter.java deleted file mode 100644 index e44887a..0000000 --- a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/Converter.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R2; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import net.minecraft.server.v1_9_R2.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -public class Converter { - - private static final Logger LOGGER = LogManager.getLogger("SWM Converter"); - - static net.minecraft.server.v1_9_R2.NibbleArray convertArray(NibbleArray array) { - return new net.minecraft.server.v1_9_R2.NibbleArray(array.getBacking()); - } - - static NibbleArray convertArray(net.minecraft.server.v1_9_R2.NibbleArray array) { - return new NibbleArray(array.asBytes()); - } - - static NBTBase convertTag(Tag tag) { - try { - switch (tag.getType()) { - case TAG_BYTE: - return new NBTTagByte(((ByteTag) tag).getValue()); - case TAG_SHORT: - return new NBTTagShort(((ShortTag) tag).getValue()); - case TAG_INT: - return new NBTTagInt(((IntTag) tag).getValue()); - case TAG_LONG: - return new NBTTagLong(((LongTag) tag).getValue()); - case TAG_FLOAT: - return new NBTTagFloat(((FloatTag) tag).getValue()); - case TAG_DOUBLE: - return new NBTTagDouble(((DoubleTag) tag).getValue()); - case TAG_BYTE_ARRAY: - return new NBTTagByteArray(((ByteArrayTag) tag).getValue()); - case TAG_STRING: - return new NBTTagString(((StringTag) tag).getValue()); - case TAG_INT_ARRAY: - return new NBTTagIntArray(((IntArrayTag) tag).getValue()); - case TAG_LIST: - NBTTagList list = new NBTTagList(); - ((ListTag) tag).getValue().stream().map(Converter::convertTag).forEach(list::add); - - return list; - case TAG_COMPOUND: - NBTTagCompound compound = new NBTTagCompound(); - - ((CompoundTag) tag).getValue().forEach((key, value) -> compound.set(key, convertTag(value))); - - return compound; - default: - throw new IllegalArgumentException("Invalid tag type " + tag.getType().name()); - } - } catch (Exception ex) { - LOGGER.error("Failed to convert NBT object:"); - LOGGER.error(tag.toString()); - - throw ex; - } - } - - static Tag convertTag(String name, NBTBase base) { - switch (base.getTypeId()) { - case 1: - return new ByteTag(name, ((NBTTagByte) base).f()); - case 2: - return new ShortTag(name, ((NBTBase.NBTNumber) base).e()); - case 3: - return new IntTag(name, ((NBTBase.NBTNumber) base).d()); - case 4: - return new LongTag(name, ((NBTBase.NBTNumber) base).c()); - case 5: - return new FloatTag(name, ((NBTBase.NBTNumber) base).h()); - case 6: - return new DoubleTag(name, ((NBTBase.NBTNumber) base).g()); - case 7: - return new ByteArrayTag(name, ((NBTTagByteArray) base).c()); - case 8: - return new StringTag(name, ((NBTTagString) base).a_()); - case 9: - List list = new ArrayList<>(); - NBTTagList originalList = ((NBTTagList) base); - - for (int i = 0; i < originalList.size(); i++) { - NBTBase entry = originalList.h(i); - list.add(convertTag("", entry)); - } - - return new ListTag(name, TagType.getById(originalList.d()), list); - case 10: - NBTTagCompound originalCompound = ((NBTTagCompound) base); - CompoundTag compound = new CompoundTag(name, new CompoundMap()); - - for (String key : originalCompound.c()) { - compound.getValue().put(key, convertTag(key, originalCompound.get(key))); - } - - return compound; - case 11: - return new IntArrayTag("", ((NBTTagIntArray) base).c()); - default: - throw new IllegalArgumentException("Invalid tag type " + base.getTypeId()); - } - } - -} diff --git a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CraftCLSMBridge.java b/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CraftCLSMBridge.java deleted file mode 100644 index 7975ee3..0000000 --- a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CraftCLSMBridge.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R2; - -import com.grinderwolf.swm.clsm.CLSMBridge; -import com.grinderwolf.swm.clsm.ClassModifier; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_9_R2.WorldServer; - -@RequiredArgsConstructor -public class CraftCLSMBridge implements CLSMBridge { - - private final v1_9_R2SlimeNMS nmsInstance; - - @Override - public Object[] getDefaultWorlds() { - WorldServer defaultWorld = nmsInstance.getDefaultWorld(); - WorldServer netherWorld = nmsInstance.getDefaultNetherWorld(); - WorldServer endWorld = nmsInstance.getDefaultEndWorld(); - - if (defaultWorld != null || netherWorld != null || endWorld != null) { - return new WorldServer[] { defaultWorld, netherWorld, endWorld }; - } - - // Returning null will just run the original load world method - return null; - } - - @Override - public boolean isCustomWorld(Object world) { - return world instanceof CustomWorldServer; - } - - @Override - public boolean skipWorldAdd(Object world) { - if (!isCustomWorld(world) || nmsInstance.isLoadingDefaultWorlds()) { - return false; - } - - CustomWorldServer worldServer = (CustomWorldServer) world; - return !worldServer.isReady(); - } - - static void initialize(v1_9_R2SlimeNMS instance) { - ClassModifier.setLoader(new CraftCLSMBridge(instance)); - } -} diff --git a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomChunkLoader.java b/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomChunkLoader.java deleted file mode 100644 index ee2f0cf..0000000 --- a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomChunkLoader.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R2; - -import com.flowpowered.nbt.CompoundMap; -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.RequiredArgsConstructor; -import net.minecraft.server.v1_9_R2.Chunk; -import net.minecraft.server.v1_9_R2.ChunkSection; -import net.minecraft.server.v1_9_R2.Entity; -import net.minecraft.server.v1_9_R2.EntityTypes; -import net.minecraft.server.v1_9_R2.IChunkLoader; -import net.minecraft.server.v1_9_R2.NBTTagCompound; -import net.minecraft.server.v1_9_R2.TileEntity; -import net.minecraft.server.v1_9_R2.World; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.*; - -@RequiredArgsConstructor -public class CustomChunkLoader implements IChunkLoader { - - private static final Logger LOGGER = LogManager.getLogger("SWM Chunk Loader"); - - private final CraftSlimeWorld world; - - void loadAllChunks(CustomWorldServer server) { - for (SlimeChunk chunk : new ArrayList<>(world.getChunks().values())) { - Chunk nmsChunk = createChunk(server, chunk); - world.updateChunk(new NMSSlimeChunk(nmsChunk)); - } - } - - private Chunk createChunk(CustomWorldServer server, SlimeChunk chunk) { - int x = chunk.getX(); - int z = chunk.getZ(); - - LOGGER.debug("Loading chunk (" + x + ", " + z + ") on world " + world.getName()); - - Chunk nmsChunk = new Chunk(server, x, z); - - nmsChunk.d(true); - nmsChunk.e(true); - - CompoundTag heightMapsCompound = chunk.getHeightMaps(); - int[] heightMap = heightMapsCompound.getIntArrayValue("heightMap").get(); - - nmsChunk.a(heightMap); - - // Load chunk sections - LOGGER.debug("Loading chunk sections for chunk (" + x + ", " + z + ") on world " + world.getName()); - ChunkSection[] sections = new ChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - SlimeChunkSection slimeSection = chunk.getSections()[sectionId]; - - if (slimeSection != null) { - ChunkSection section = new ChunkSection(sectionId << 4, true); - NibbleArray data = slimeSection.getData(); - byte[] blocks = slimeSection.getBlocks(); - - LOGGER.debug("ChunkSection #" + sectionId + " - Chunk (" + x + ", " + z + ") - World " + world.getName() + ":"); - LOGGER.debug("Blocks:"); - LOGGER.debug(blocks); - LOGGER.debug("Block light array:"); - LOGGER.debug(slimeSection.getBlockLight() != null ? slimeSection.getBlockLight().getBacking() : "Not present"); - LOGGER.debug("Sky light array:"); - LOGGER.debug(slimeSection.getSkyLight() != null ? slimeSection.getSkyLight().getBacking() : "Not present"); - - section.getBlocks().a(blocks, Converter.convertArray(data), new net.minecraft.server.v1_9_R2.NibbleArray()); - - if (slimeSection.getBlockLight() != null) { - section.a(Converter.convertArray(slimeSection.getBlockLight())); - } - - if (slimeSection.getSkyLight() != null) { - section.b(Converter.convertArray(slimeSection.getSkyLight())); - } - - section.recalcBlockCounts(); - sections[sectionId] = section; - } - } - - nmsChunk.a(sections); - - // Biomes - nmsChunk.a(toByteArray(chunk.getBiomes())); - - // Load tile entities - LOGGER.debug("Loading tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List tileEntities = chunk.getTileEntities(); - int loadedEntities = 0; - - if (tileEntities != null) { - for (CompoundTag tag : tileEntities) { - TileEntity entity = TileEntity.c((NBTTagCompound) Converter.convertTag(tag)); - - if (entity != null) { - nmsChunk.a(entity); - loadedEntities++; - } - } - } - - LOGGER.debug("Loaded " + loadedEntities + " tile entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - - // Load entities - LOGGER.debug("Loading entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - List entities = chunk.getEntities(); - loadedEntities = 0; - - if (entities != null) { - for (CompoundTag tag : entities) { - loadEntity(tag, server, nmsChunk); - } - } - - LOGGER.debug("Loaded " + loadedEntities + " entities for chunk (" + x + ", " + z + ") on world " + world.getName()); - LOGGER.debug("Loaded chunk (" + x + ", " + z + ") on world " + world.getName()); - - return nmsChunk; - } - - private byte[] toByteArray(int[] ints) { - ByteBuffer buf = ByteBuffer.allocate(ints.length * 4).order(ByteOrder.LITTLE_ENDIAN); - buf.asIntBuffer().put(ints); - - return buf.array(); - } - - private Entity loadEntity(CompoundTag tag, World world, Chunk chunk) { - Entity entity = EntityTypes.a((NBTTagCompound) Converter.convertTag(tag), world); - chunk.g(true); - - if (entity != null) { - chunk.a(entity); - - CompoundMap map = tag.getValue(); - - if (map.containsKey("Passengers")) { - List passengersList = (List) map.get("Passengers").getValue(); - - for (CompoundTag passengerTag : passengersList) { - Entity passenger = loadEntity(passengerTag, world, chunk); - - if (passengerTag != null) { - passenger.a(entity, true); - } - } - } - } - - return entity; - } - - // Load chunk - @Override - public Chunk a(World nmsWorld, int x, int z) { - SlimeChunk slimeChunk = world.getChunk(x, z); - Chunk chunk; - - if (slimeChunk == null) { - chunk = new Chunk(nmsWorld, x, z); - - chunk.d(true); - chunk.e(true); - } else if (slimeChunk instanceof NMSSlimeChunk) { - chunk = ((NMSSlimeChunk) slimeChunk).getChunk(); - } else { // All SlimeChunk objects should be converted to NMSSlimeChunks when loading the world - throw new IllegalStateException("Chunk (" + x + ", " + z + ") has not been converted to a NMSSlimeChunk object!"); - } - - return chunk; - } - - // Save chunk - @Override - public void a(World world, Chunk chunk) { - SlimeChunk slimeChunk = this.world.getChunk(chunk.locX, chunk.locZ); - - if (slimeChunk instanceof NMSSlimeChunk) { // In case somehow the chunk object changes (might happen for some reason) - ((NMSSlimeChunk) slimeChunk).setChunk(chunk); - } else { - this.world.updateChunk(new NMSSlimeChunk(chunk)); - } - } - - - // Save all chunks - @Override - public void b() { - - } - - // Does literally nothing - @Override - public void b(World world, Chunk chunk) { } - - // Does literally nothing - @Override - public void a() { } -} diff --git a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomDataManager.java b/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomDataManager.java deleted file mode 100644 index aac12cd..0000000 --- a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomDataManager.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R2; - -import com.flowpowered.nbt.CompoundTag; -import com.flowpowered.nbt.StringTag; -import com.flowpowered.nbt.Tag; -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.AccessLevel; -import lombok.Getter; -import net.minecraft.server.v1_9_R2.EntityHuman; -import net.minecraft.server.v1_9_R2.GameRules; -import net.minecraft.server.v1_9_R2.IChunkLoader; -import net.minecraft.server.v1_9_R2.NBTTagCompound; -import net.minecraft.server.v1_9_R2.WorldData; -import net.minecraft.server.v1_9_R2.WorldNBTStorage; -import net.minecraft.server.v1_9_R2.WorldProvider; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - -@Getter -public class CustomDataManager extends WorldNBTStorage { - - private static final Map defaultValues; - - static { - GameRules emptyRules = new GameRules(); - String[] rules = emptyRules.getGameRules(); - - defaultValues = Arrays.stream(rules).collect(Collectors.toMap((rule) -> rule, emptyRules::get)); - } - - @Getter(value = AccessLevel.NONE) - private final UUID uuid = UUID.randomUUID(); - private final SlimeWorld world; - private final CustomChunkLoader chunkLoader; - private WorldData worldData; - - // When unloading a world, Spigot tries to remove the region file from its cache. - // To do so, it casts the world's IDataManager to a WorldNBTStorage, to be able - // to use the getDirectory() method. Thanks to this, we have to create a custom - // WorldNBTStorage with a fake file instead of just implementing the IDataManager interface - // - // Thanks Spigot! - CustomDataManager(SlimeWorld world) { - super(new File("temp_" + world.getName()), world.getName(), false, null); - - // The WorldNBTStorage automatically creates some files inside the base dir, so we have to delete them - // (Thanks again Spigot) - - // Can't just access the baseDir field inside WorldNBTStorage cause it's private :P - File baseDir = new File("temp_" + world.getName(), world.getName()); - new File(baseDir, "session.lock").delete(); - new File(baseDir, "data").delete(); - - baseDir.delete(); - baseDir.getParentFile().delete(); - - this.world = world; - this.chunkLoader = new CustomChunkLoader((CraftSlimeWorld) world); - } - - @Override - public WorldData getWorldData() { - if (worldData == null) { - worldData = new CustomWorldData((CraftSlimeWorld) world); - } - - return worldData; - } - - @Override public void checkSession() { } - - @Override - public IChunkLoader createChunkLoader(WorldProvider worldProvider) { - return chunkLoader; - } - - @Override - public void saveWorldData(WorldData worldData, NBTTagCompound nbtTagCompound) { - CompoundTag gameRules = (CompoundTag) Converter.convertTag("gamerules", worldData.w().a()).getAsCompoundTag().get(); - CompoundTag extraData = this.world.getExtraData(); - - extraData.getValue().remove("gamerules"); - - if (!gameRules.getValue().isEmpty()) { - // Remove default values to save space - for (Map.Entry> entry : new ArrayList<>(gameRules.getValue().entrySet())) { - String rule = entry.getKey(); - StringTag valueTag = (StringTag) entry.getValue(); - String defaultValue = defaultValues.get(rule); - - if (valueTag.getValue().equalsIgnoreCase(defaultValue)) { - gameRules.getValue().remove(rule); - } - } - - // Maybe all the gamerules stored were the default values - if (!gameRules.getValue().isEmpty()) { - extraData.getValue().put("gamerules", gameRules); - } - } - } - - @Override - public void saveWorldData(WorldData worldData) { - this.saveWorldData(worldData, null); - } - - @Override - public void a() { - - } - - @Override - public File getDataFile(String s) { - return null; - } - - @Override - public UUID getUUID() { - return uuid; - } - - @Override - public void save(EntityHuman entityHuman) { - - } - - @Override - public NBTTagCompound load(EntityHuman entityHuman) { - return null; - } - - @Override public String[] getSeenPlayers() { - return new String[0]; - } -} diff --git a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomWorldData.java b/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomWorldData.java deleted file mode 100644 index 16ac07a..0000000 --- a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomWorldData.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R2; - -import com.flowpowered.nbt.CompoundTag; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import net.minecraft.server.v1_9_R2.*; - -import java.util.Optional; - -@Getter -public class CustomWorldData extends WorldData { - - private final CraftSlimeWorld world; - private final WorldType type; - - CustomWorldData(CraftSlimeWorld world) { - this.world = world; - this.type = WorldType.getType(world.getPropertyMap().getString(SlimeProperties.WORLD_TYPE).toUpperCase()); - this.setGameType(WorldSettings.EnumGamemode.NOT_SET); - - // Game rules - CompoundTag extraData = world.getExtraData(); - Optional gameRules = extraData.getAsCompoundTag("gamerules"); - gameRules.ifPresent(compoundTag -> this.w().a((NBTTagCompound) Converter.convertTag(compoundTag))); - } - - @Override - public String getName() { - return world.getName(); - } - -} diff --git a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomWorldServer.java b/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomWorldServer.java deleted file mode 100644 index f12772d..0000000 --- a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/CustomWorldServer.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R2; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.grinderwolf.swm.api.exceptions.UnknownWorldException; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.server.v1_9_R2.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.World; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomWorldServer extends WorldServer { - - private static final Logger LOGGER = LogManager.getLogger("SWM World"); - private static final ExecutorService WORLD_SAVER_SERVICE = Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() - .setNameFormat("SWM Pool Thread #%1$d").build()); - - @Getter - private final CraftSlimeWorld slimeWorld; - private final Object saveLock = new Object(); - - @Getter - @Setter - private boolean ready = false; - - CustomWorldServer(CraftSlimeWorld world, IDataManager dataManager, int dimension) { - super(MinecraftServer.getServer(), dataManager, dataManager.getWorldData(), dimension, MinecraftServer.getServer().methodProfiler, World.Environment.valueOf(world.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()), null); - - b(); - this.slimeWorld = world; - this.tracker = new EntityTracker(this); - addIWorldAccess(new WorldManager(MinecraftServer.getServer(), this)); - - SlimePropertyMap propertyMap = world.getPropertyMap(); - - worldData.setDifficulty(EnumDifficulty.valueOf(propertyMap.getString(SlimeProperties.DIFFICULTY).toUpperCase())); - worldData.setSpawn(new BlockPosition(propertyMap.getInt(SlimeProperties.SPAWN_X), propertyMap.getInt(SlimeProperties.SPAWN_Y), propertyMap.getInt(SlimeProperties.SPAWN_Z))); - super.setSpawnFlags(propertyMap.getBoolean(SlimeProperties.ALLOW_MONSTERS), propertyMap.getBoolean(SlimeProperties.ALLOW_ANIMALS)); - - this.pvpMode = propertyMap.getBoolean(SlimeProperties.PVP); - - // Load all chunks - CustomChunkLoader chunkLoader = ((CustomDataManager) this.getDataManager()).getChunkLoader(); - chunkLoader.loadAllChunks(this); - } - - @Override - public void save(boolean forceSave, IProgressUpdate progressUpdate) throws ExceptionWorldConflict { - if (!slimeWorld.isReadOnly()) { - super.save(forceSave, progressUpdate); - - if (MinecraftServer.getServer().isStopped()) { // Make sure the slimeWorld gets saved before stopping the server by running it from the main thread - save(); - - // Have to manually unlock the world as well - try { - slimeWorld.getLoader().unlockWorld(slimeWorld.getName()); - } catch (IOException ex) { - LOGGER.error("Failed to unlock the world " + slimeWorld.getName() + ". Please unlock it manually by using the command /swm manualunlock. Stack trace:"); - - ex.printStackTrace(); - } catch (UnknownWorldException ignored) { - - } - } else { - WORLD_SAVER_SERVICE.execute(this::save); - } - } - } - - private void save() { - synchronized (saveLock) { // Don't want to save the slimeWorld from multiple threads simultaneously - try { - LOGGER.info("Saving world " + slimeWorld.getName() + "..."); - long start = System.currentTimeMillis(); - byte[] serializedWorld = slimeWorld.serialize(); - slimeWorld.getLoader().saveWorld(slimeWorld.getName(), serializedWorld, false); - LOGGER.info("World " + slimeWorld.getName() + " saved in " + (System.currentTimeMillis() - start) + "ms."); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - -} diff --git a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/NMSSlimeChunk.java b/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/NMSSlimeChunk.java deleted file mode 100644 index de8e4ba..0000000 --- a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/NMSSlimeChunk.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R2; - -import com.flowpowered.nbt.*; -import com.grinderwolf.swm.api.utils.NibbleArray; -import com.grinderwolf.swm.api.world.SlimeChunk; -import com.grinderwolf.swm.api.world.SlimeChunkSection; -import com.grinderwolf.swm.nms.CraftSlimeChunkSection; -import lombok.AllArgsConstructor; -import lombok.Data; -import net.minecraft.server.v1_9_R2.*; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; - -@Data -@AllArgsConstructor -public class NMSSlimeChunk implements SlimeChunk { - - private Chunk chunk; - - @Override - public String getWorldName() { - return chunk.getWorld().getWorldData().getName(); - } - - @Override - public int getX() { - return chunk.locX; - } - - @Override - public int getZ() { - return chunk.locZ; - } - - @Override - public SlimeChunkSection[] getSections() { - SlimeChunkSection[] sections = new SlimeChunkSection[16]; - - for (int sectionId = 0; sectionId < chunk.getSections().length; sectionId++) { - ChunkSection section = chunk.getSections()[sectionId]; - - if (section != null) { - section.recalcBlockCounts(); - - if (!section.a()) { // If the section is empty, just ignore it to save space - // Block Light Nibble Array - NibbleArray blockLightArray = Converter.convertArray(section.getEmittedLightArray()); - - // Sky light Nibble Array - NibbleArray skyLightArray = Converter.convertArray(section.getSkyLightArray()); - - // Block Data - byte[] blocks = new byte[4096]; - - net.minecraft.server.v1_9_R2.NibbleArray minecraftBlockDataArray = new net.minecraft.server.v1_9_R2.NibbleArray(); - DataPaletteBlock dataPaletteBlock = section.getBlocks(); - dataPaletteBlock.exportData(blocks, minecraftBlockDataArray); - - NibbleArray blockDataArray = Converter.convertArray(minecraftBlockDataArray); - - sections[sectionId] = new CraftSlimeChunkSection(blocks, blockDataArray, null, null, blockLightArray, skyLightArray); - } - } - } - - return sections; - } - - @Override - public CompoundTag getHeightMaps() { - CompoundTag heightMapsCompound = new CompoundTag("", new CompoundMap()); - heightMapsCompound.getValue().put("heightMap", new IntArrayTag("heightMap", chunk.heightMap)); - - return heightMapsCompound; - } - - @Override - public int[] getBiomes() { - return toIntArray(chunk.getBiomeIndex()); - } - - @Override - public List getTileEntities() { - List tileEntities = new ArrayList<>(); - - for (TileEntity entity : chunk.getTileEntities().values()) { - NBTTagCompound entityNbt = new NBTTagCompound(); - entity.save(entityNbt); - tileEntities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - - return tileEntities; - } - - @Override - public List getEntities() { - List entities = new ArrayList<>(); - - for (int i = 0; i < chunk.getEntitySlices().length; i++) { - for (Entity entity : chunk.getEntitySlices()[i]) { - NBTTagCompound entityNbt = new NBTTagCompound(); - - if (entity.d(entityNbt)) { - chunk.g(true); - entities.add((CompoundTag) Converter.convertTag("", entityNbt)); - } - } - } - - return entities; - } - - private static int[] toIntArray(byte[] buf) { - ByteBuffer buffer = ByteBuffer.wrap(buf).order(ByteOrder.BIG_ENDIAN); - int[] ret = new int[buf.length / 4]; - - buffer.asIntBuffer().get(ret); - - return ret; - } -} diff --git a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/v1_9_R2SlimeNMS.java b/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/v1_9_R2SlimeNMS.java deleted file mode 100644 index 532351e..0000000 --- a/slimeworldmanager-nms-v1_9_R2/src/main/java/com/grinderwolf/swm/nms/v1_9_R2/v1_9_R2SlimeNMS.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.grinderwolf.swm.nms.v1_9_R2; - -import com.grinderwolf.swm.api.world.SlimeWorld; -import com.grinderwolf.swm.api.world.properties.SlimeProperties; -import com.grinderwolf.swm.nms.CraftSlimeWorld; -import com.grinderwolf.swm.nms.SlimeNMS; -import lombok.Getter; -import net.minecraft.server.v1_9_R2.MinecraftServer; -import net.minecraft.server.v1_9_R2.WorldServer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_9_R2.CraftWorld; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; - -@Getter -public class v1_9_R2SlimeNMS implements SlimeNMS { - - private static final Logger LOGGER = LogManager.getLogger("SWM"); - - private final byte worldVersion = 0x02; - - private boolean loadingDefaultWorlds = true; // If true, the addWorld method will not be skipped - - private WorldServer defaultWorld; - private WorldServer defaultNetherWorld; - private WorldServer defaultEndWorld; - - public v1_9_R2SlimeNMS() { - try { - CraftCLSMBridge.initialize(this); - } catch (NoClassDefFoundError ex) { - LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?"); - System.exit(1); // No ClassModifier, no party - } - } - - @Override - public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) { - if (normalWorld != null) { - World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - - if (env != World.Environment.NORMAL) { - LOGGER.warn("The environment for the default world must always be 'NORMAL'."); - } - - defaultWorld = new CustomWorldServer((CraftSlimeWorld) normalWorld, new CustomDataManager(normalWorld), 0); - } - - if (netherWorld != null) { - World.Environment env = World.Environment.valueOf(netherWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultNetherWorld = new CustomWorldServer((CraftSlimeWorld) netherWorld, new CustomDataManager(netherWorld), env.getId()); - } - - if (endWorld != null) { - World.Environment env = World.Environment.valueOf(endWorld.getPropertyMap().getString(SlimeProperties.ENVIRONMENT).toUpperCase()); - defaultEndWorld = new CustomWorldServer((CraftSlimeWorld) endWorld, new CustomDataManager(endWorld), env.getId()); - } - - loadingDefaultWorlds = false; - } - - @Override - public Object createNMSWorld(SlimeWorld world) { - CustomDataManager dataManager = new CustomDataManager(world); - MinecraftServer mcServer = MinecraftServer.getServer(); - - int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + mcServer.worlds.size(); - boolean used = false; - - do { - for (WorldServer server : mcServer.worlds) { - used = server.dimension == dimension; - - if (used) { - dimension++; - break; - } - } - } while (used); - - return new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimension); - } - - @Override - public void generateWorld(SlimeWorld world) { - addWorldToServerList(createNMSWorld(world)); - } - - @Override - public void addWorldToServerList(Object worldObject) { - if (!(worldObject instanceof WorldServer)) { - throw new IllegalArgumentException("World object must be an instance of WorldServer!"); - } - - CustomWorldServer server = (CustomWorldServer) worldObject; - String worldName = server.getWorldData().getName(); - - if (Bukkit.getWorld(worldName) != null) { - throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?"); - } - - LOGGER.info("Loading world " + worldName); - long startTime = System.currentTimeMillis(); - - server.setReady(true); - MinecraftServer mcServer = MinecraftServer.getServer(); - - mcServer.server.addWorld(server.getWorld()); - mcServer.worlds.add(server); - - Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld())); - Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld())); - - LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms."); - } - - @Override - public SlimeWorld getSlimeWorld(World world) { - CraftWorld craftWorld = (CraftWorld) world; - - if (!(craftWorld.getHandle() instanceof CustomWorldServer)) { - return null; - } - - CustomWorldServer worldServer = (CustomWorldServer) craftWorld.getHandle(); - - return worldServer.getSlimeWorld(); - } -} diff --git a/slimeworldmanager-plugin/pom.xml b/slimeworldmanager-plugin/pom.xml index a73b6c6..0b68021 100644 --- a/slimeworldmanager-plugin/pom.xml +++ b/slimeworldmanager-plugin/pom.xml @@ -23,7 +23,7 @@ org.spigotmc spigot-api - 1.13-R0.1-SNAPSHOT + 1.8.8-R0.1-SNAPSHOT provided @@ -41,55 +41,10 @@ slimeworldmanager-nms-v1_8_R3 ${project.version} - - com.grinderwolf - slimeworldmanager-nms-v1_9_R1 - ${project.version} - - - com.grinderwolf - slimeworldmanager-nms-v1_9_R2 - ${project.version} - - - com.grinderwolf - slimeworldmanager-nms-v1_10_R1 - ${project.version} - - - com.grinderwolf - slimeworldmanager-nms-v1_11_R1 - ${project.version} - - - com.grinderwolf - slimeworldmanager-nms-v1_12_R1 - ${project.version} - - - com.grinderwolf - slimeworldmanager-nms-v1_13_R1 - ${project.version} - - - com.grinderwolf - slimeworldmanager-nms-v1_13_R2 - ${project.version} - - - com.grinderwolf - slimeworldmanager-nms-v1_14_R1 - ${project.version} - - - com.grinderwolf - slimeworldmanager-nms-v1_15_R1 - ${project.version} - com.github.luben zstd-jni - 1.4.1-1 + 1.5.0-4 com.zaxxer @@ -99,17 +54,27 @@ org.mongodb mongo-java-driver - 3.11.0-rc0 + 3.12.10 org.spongepowered configurate-yaml - 3.7-SNAPSHOT + 4.1.2 org.bstats bstats-bukkit - 1.5 + 2.2.1 + + + org.spongepowered + configurate-core + 3.7.2 + + + org.spongepowered + configurate-yaml + 3.7.2 diff --git a/slimeworldmanager-plugin/src/main/java/com/grinderwolf/swm/plugin/SWMPlugin.java b/slimeworldmanager-plugin/src/main/java/com/grinderwolf/swm/plugin/SWMPlugin.java index 6e345ad..23da95c 100644 --- a/slimeworldmanager-plugin/src/main/java/com/grinderwolf/swm/plugin/SWMPlugin.java +++ b/slimeworldmanager-plugin/src/main/java/com/grinderwolf/swm/plugin/SWMPlugin.java @@ -10,16 +10,7 @@ import com.grinderwolf.swm.api.world.properties.SlimePropertyMap; import com.grinderwolf.swm.nms.CraftSlimeWorld; import com.grinderwolf.swm.nms.SlimeNMS; -import com.grinderwolf.swm.nms.v1_10_R1.v1_10_R1SlimeNMS; -import com.grinderwolf.swm.nms.v1_11_R1.v1_11_R1SlimeNMS; -import com.grinderwolf.swm.nms.v1_12_R1.v1_12_R1SlimeNMS; -import com.grinderwolf.swm.nms.v1_13_R1.v1_13_R1SlimeNMS; -import com.grinderwolf.swm.nms.v1_13_R2.v1_13_R2SlimeNMS; -import com.grinderwolf.swm.nms.v1_14_R1.v1_14_R1SlimeNMS; -import com.grinderwolf.swm.nms.v1_15_R1.v1_15_R1SlimeNMS; import com.grinderwolf.swm.nms.v1_8_R3.v1_8_R3SlimeNMS; -import com.grinderwolf.swm.nms.v1_9_R1.v1_9_R1SlimeNMS; -import com.grinderwolf.swm.nms.v1_9_R2.v1_9_R2SlimeNMS; import com.grinderwolf.swm.plugin.commands.CommandManager; import com.grinderwolf.swm.plugin.config.*; import com.grinderwolf.swm.plugin.loaders.LoaderUtils; @@ -111,7 +102,7 @@ public void onEnable() { return; } - new Metrics(this); + new Metrics(this, 498); final CommandManager commandManager = new CommandManager(); final PluginCommand swmCommand = getCommand("swm"); @@ -159,24 +150,6 @@ private SlimeNMS getNMSBridge() throws InvalidVersionException { switch (nmsVersion) { case "v1_8_R3": return new v1_8_R3SlimeNMS(); - case "v1_9_R1": - return new v1_9_R1SlimeNMS(); - case "v1_9_R2": - return new v1_9_R2SlimeNMS(); - case "v1_10_R1": - return new v1_10_R1SlimeNMS(); - case "v1_11_R1": - return new v1_11_R1SlimeNMS(); - case "v1_12_R1": - return new v1_12_R1SlimeNMS(); - case "v1_13_R1": - return new v1_13_R1SlimeNMS(); - case "v1_13_R2": - return new v1_13_R2SlimeNMS(); - case "v1_14_R1": - return new v1_14_R1SlimeNMS(); - case "v1_15_R1": - return new v1_15_R1SlimeNMS(); default: throw new InvalidVersionException(nmsVersion); }