diff --git a/.github/workflows/compile_snapshot.yml b/.github/workflows/compile_snapshot.yml
index 683cb18d1..585ec68d0 100644
--- a/.github/workflows/compile_snapshot.yml
+++ b/.github/workflows/compile_snapshot.yml
@@ -15,10 +15,10 @@ jobs:
url: https://repo.andrei1058.dev
steps:
- uses: actions/checkout@v2
- - name: Set up JDK 17.0.5
+ - name: Set up JDK
uses: actions/setup-java@v2
with:
- java-version: '17.0.5'
+ java-version: '19.0.2+7'
distribution: 'adopt'
- name: Deploy snapshot with Maven
env:
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 74211a889..9e6e6985b 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -12,10 +12,10 @@ jobs:
url: https://repo.andrei1058.com
steps:
- uses: actions/checkout@v2
- - name: Set up JDK 17.0.5
+ - name: Set up JDK
uses: actions/setup-java@v2
with:
- java-version: '17.0.5'
+ java-version: '19.0.2+7'
distribution: 'adopt'
- name: Deploy with Maven
env:
diff --git a/.github/workflows/deploy_snapshot.yml b/.github/workflows/deploy_snapshot.yml
index 0d5575620..9fd07c10f 100644
--- a/.github/workflows/deploy_snapshot.yml
+++ b/.github/workflows/deploy_snapshot.yml
@@ -14,10 +14,10 @@ jobs:
url: https://repo.andrei1058.dev
steps:
- uses: actions/checkout@v2
- - name: Set up JDK 17.0.5
+ - name: Set up JDK
uses: actions/setup-java@v2
with:
- java-version: '17.0.5'
+ java-version: '19.0.2+7'
distribution: 'adopt'
- name: Deploy snapshot with Maven
env:
diff --git a/README.md b/README.md
index d153d3aa3..7e8c75a33 100644
--- a/README.md
+++ b/README.md
@@ -20,9 +20,9 @@ It is required to use **Java 11** or newer.
The internal world restore system is based on zipping and unzipping maps which can become
heavy if you are still making use of HDDs and you do not have a decent CPU, for a better
and faster restore system we recommend using one of the following solutions:
-- [SlimeWorldManager](https://www.spigotmc.org/resources/slimeworldmanager.69974/) plug-in
-- [AdvancedWorldManager](https://www.spigotmc.org/resources/advanced-slimeworldmanager.87209/) plug-in
-- [AdvancedSlimePaper](https://github.com/InfernalSuite/AdvancedSlimePaper) server jar
+- [SlimeWorldManager](https://www.spigotmc.org/resources/slimeworldmanager.69974/) plug-in (v2.2.1 **only**)
+- [AdvancedWorldManager](https://www.spigotmc.org/resources/advanced-slimeworldmanager.87209/) plug-in (v2.8.0 **only**)
+- [AdvancedSlimePaper](https://github.com/InfernalSuite/AdvancedSlimePaper) server jar (**1.20 or newer**)
BedWars1058 will hook into it and do everything for you, no additional configuration is needed.
diff --git a/bedwars-api/pom.xml b/bedwars-api/pom.xml
index 5dcbe3698..80f78054b 100644
--- a/bedwars-api/pom.xml
+++ b/bedwars-api/pom.xml
@@ -5,7 +5,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
4.0.0
bedwars-api
diff --git a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/server/RestoreAdapter.java b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/server/RestoreAdapter.java
index 8bcdc6fe7..bd8831a52 100644
--- a/bedwars-api/src/main/java/com/andrei1058/bedwars/api/server/RestoreAdapter.java
+++ b/bedwars-api/src/main/java/com/andrei1058/bedwars/api/server/RestoreAdapter.java
@@ -101,4 +101,6 @@ public Plugin getOwner() {
* Let them load on BedWars1058 main Thread so they will be converted before getting loaded.
*/
public abstract void convertWorlds();
+
+ public abstract String getDisplayName();
}
diff --git a/bedwars-plugin/pom.xml b/bedwars-plugin/pom.xml
index f0dc8ea23..cb0b2e30c 100644
--- a/bedwars-plugin/pom.xml
+++ b/bedwars-plugin/pom.xml
@@ -5,7 +5,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
4.0.0
bedwars-plugin
@@ -294,6 +294,19 @@
compile
+
+
+ com.andrei1058.bedwars
+ resetadapter-slimepaper
+ ${project.version}
+
+
+
+ com.andrei1058.bedwars
+ resetadapter-aswm
+ ${project.version}
+
+
diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java
index ecc69ff9e..87a7f4f05 100644
--- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java
+++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java
@@ -97,6 +97,7 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
@@ -221,44 +222,9 @@ public void onEnable() {
nms.registerVersionListeners();
- if (Bukkit.getPluginManager().getPlugin("Enhanced-SlimeWorldManager") != null) {
- try {
- //noinspection rawtypes
- Constructor constructor = Class.forName("com.andrei1058.bedwars.arena.mapreset.eswm.ESlimeAdapter").getConstructor(Plugin.class);
- try {
- api.setRestoreAdapter((RestoreAdapter) constructor.newInstance(this));
- this.getLogger().info("Hook into Enhanced-SlimeWorldManager support!");
- } catch (InstantiationException e) {
- e.printStackTrace();
- api.setRestoreAdapter(new InternalAdapter(this));
- this.getLogger().info("Failed to hook into Enhanced-SlimeWorldManager support! Using the internal reset adapter.");
- }
- } catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException |
- InvocationTargetException e) {
- e.printStackTrace();
- api.setRestoreAdapter(new InternalAdapter(this));
- this.getLogger().info("Failed to hook into Enhanced-SlimeWorldManager support! Using the internal reset adapter.");
- }
- } else if (checkSWM()) {
- try {
- //noinspection rawtypes
- Constructor constructor = Class.forName("com.andrei1058.bedwars.arena.mapreset.slime.SlimeAdapter").getConstructor(Plugin.class);
- try {
- api.setRestoreAdapter((RestoreAdapter) constructor.newInstance(this));
- this.getLogger().info("Hook into SlimeWorldManager support!");
- } catch (InstantiationException e) {
- e.printStackTrace();
- api.setRestoreAdapter(new InternalAdapter(this));
- this.getLogger().info("Failed to hook into SlimeWorldManager support! Using internal reset adapter.");
- }
- } catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException |
- InvocationTargetException e) {
- e.printStackTrace();
- api.setRestoreAdapter(new InternalAdapter(this));
- this.getLogger().info("Failed to hook into SlimeWorldManager support! Using internal reset adapter.");
- }
- } else {
+ if (!this.handleWorldAdapter()) {
api.setRestoreAdapter(new InternalAdapter(this));
+ getLogger().info("Using internal world restore system.");
}
/* Register commands */
@@ -606,6 +572,54 @@ public void onEnable() {
SpoilPlayerTNTFeature.init();
}
+ /**
+ * Try loading custom adapter support.
+ * @return true when custom adapter was registered.
+ */
+ private boolean handleWorldAdapter() {
+ Plugin swmPlugin = Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
+
+ if (null == swmPlugin){
+ return false;
+ }
+ PluginDescriptionFile pluginDescription = swmPlugin.getDescription();
+ if (null == pluginDescription) {
+ return false;
+ }
+
+ String[] versionString = pluginDescription.getVersion().split("\\.");
+
+
+ try {
+ int major = Integer.parseInt(versionString[0]);
+ int minor = Integer.parseInt(versionString[1]);
+ int release = versionString.length > 3 ? Integer.parseInt(versionString[3]) : 0;
+
+ String adapterPath;
+ if (major == 2 && minor == 2 && release == 1) {
+ adapterPath = "com.andrei1058.bedwars.arena.mapreset.slime.SlimeAdapter";
+ } else if (major == 2 && minor == 8 && release == 0) {
+ adapterPath = "com.andrei1058.bedwars.arena.mapreset.slime.AdvancedSlimeAdapter";
+ } else if (major > 2 || major == 2 && minor >= 10) {
+ adapterPath = "com.andrei1058.bedwars.arena.mapreset.slime.SlimePaperAdapter";
+ } else {
+ return false;
+ }
+
+ Constructor> constructor = Class.forName(adapterPath).getConstructor(Plugin.class);
+ getLogger().info("Loading restore adapter: "+adapterPath+" ...");
+
+ RestoreAdapter candidate = (RestoreAdapter) constructor.newInstance(this);
+ api.setRestoreAdapter(candidate);
+ getLogger().info("Hook into "+candidate.getDisplayName()+" as restore adapter.");
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ this.getLogger().info("Something went wrong! Using internal reset adapter...");
+ }
+ return false;
+ }
+
private void registerDelayedCommands() {
if (!nms.isBukkitCommandRegistered("shout")) {
nms.registerCommand("shout", new ShoutCommand("shout"));
@@ -784,41 +798,6 @@ public static com.andrei1058.bedwars.api.BedWars getAPI() {
return api;
}
- /**
- * This is used to check if can hook in SlimeWorldManager support.
- *
- * @return true if can load swm support.
- */
- private boolean checkSWM() {
- Plugin plugin = Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
- if (plugin == null) return false;
- switch (plugin.getDescription().getVersion()) {
- case "2.2.0":
- case "2.1.3":
- case "2.1.2":
- case "2.1.1":
- case "2.1.0":
- case "2.0.5":
- case "2.0.4":
- case "2.0.3":
- case "2.0.2":
- case "2.0.1":
- case "2.0.0":
- case "1.1.4":
- case "1.1.3":
- case "1.1.2":
- case "1.1.1":
- case "1.1.0":
- case "1.0.2":
- case "1.0.1":
- case "1.0.0-BETA":
- getLogger().warning("Could not hook into SlimeWorldManager support! You are running an unsupported version");
- return false;
- default:
- return true;
- }
- }
-
public static boolean isShuttingDown() {
return shuttingDown;
}
diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/maprestore/internal/InternalAdapter.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/maprestore/internal/InternalAdapter.java
index 7fb324c2b..20fab597e 100644
--- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/maprestore/internal/InternalAdapter.java
+++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/maprestore/internal/InternalAdapter.java
@@ -322,6 +322,11 @@ public void convertWorlds() {
});
}
+ @Override
+ public String getDisplayName() {
+ return "Internal Restore Adapter";
+ }
+
private void deleteWorldTrash(String world) {
for (File f : new File[]{new File(Bukkit.getWorldContainer(), world + "/level.dat"),
new File(Bukkit.getWorldContainer(), world + "/level.dat_mcr"),
diff --git a/pom.xml b/pom.xml
index e072f1861..810fa4ac7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
com.andrei1058.bedwars
BedWars1058
pom
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
UTF-8
@@ -21,14 +21,14 @@
bungeecord-repo
https://oss.sonatype.org/content/repositories/snapshots
-
- gitlab-maven
- https://gitlab.com/api/v4/groups/4800570/-/packages/maven
-
-
- vipfeatures-maven
- https://gitlab.com/api/v4/projects/6491858/packages/maven
-
+
+
+
+
+
+
+
+
codemc-nms
https://repo.codemc.io/repository/nms/
@@ -100,7 +100,9 @@
bedwars-plugin
bedwars-api
+ resetadapter_aswm
resetadapter_slime
+ resetadapter_slimepaper
versionsupport_1_8_R3
versionsupport_1_12_R1
versionsupport_common
diff --git a/resetadapter_aswm/pom.xml b/resetadapter_aswm/pom.xml
new file mode 100644
index 000000000..24581fb3e
--- /dev/null
+++ b/resetadapter_aswm/pom.xml
@@ -0,0 +1,68 @@
+
+
+ 4.0.0
+
+
+ BedWars1058
+ com.andrei1058.bedwars
+ 23.6-SNAPSHOT
+
+
+ resetadapter-aswm
+ ${project.parent.version}
+
+
+
+ spigotmc-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+ flow-nbt
+ https://repo.glaremasters.me/repository/concuncan/
+
+
+ legacy-aswm
+ https://repo.rapture.pw/repository/maven-snapshots/
+
+
+
+
+
+ com.andrei1058.bedwars
+ bedwars-api
+ ${project.version}
+ provided
+
+
+ org.spigotmc
+ spigot-api
+ 1.8.8-R0.1-SNAPSHOT
+ provided
+
+
+ com.grinderwolf
+ slimeworldmanager-api
+ 2.2.1
+ provided
+
+
+ com.flowpowered
+ flow-nbt
+ 2.0.0
+ compile
+
+
+
+
+
+
+ maven-deploy-plugin
+
+ true
+
+
+
+
+
\ No newline at end of file
diff --git a/resetadapter_aswm/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/AdvancedSlimeAdapter.java b/resetadapter_aswm/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/AdvancedSlimeAdapter.java
new file mode 100644
index 000000000..4c0e07bdd
--- /dev/null
+++ b/resetadapter_aswm/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/AdvancedSlimeAdapter.java
@@ -0,0 +1,484 @@
+/*
+ * BedWars1058 - A bed wars mini-game.
+ * Copyright (C) 2021 Andrei Dascălu
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * Contact e-mail: andrew.dascalu@gmail.com
+ */
+
+package com.andrei1058.bedwars.arena.mapreset.slime;
+
+import com.andrei1058.bedwars.api.BedWars;
+import com.andrei1058.bedwars.api.arena.GameState;
+import com.andrei1058.bedwars.api.arena.IArena;
+import com.andrei1058.bedwars.api.configuration.ConfigPath;
+import com.andrei1058.bedwars.api.server.ISetupSession;
+import com.andrei1058.bedwars.api.server.RestoreAdapter;
+import com.andrei1058.bedwars.api.server.ServerType;
+import com.andrei1058.bedwars.api.util.FileUtil;
+import com.andrei1058.bedwars.api.util.ZipFileUtil;
+import com.flowpowered.nbt.CompoundMap;
+import com.flowpowered.nbt.CompoundTag;
+import com.flowpowered.nbt.IntTag;
+import com.flowpowered.nbt.stream.NBTInputStream;
+import com.flowpowered.nbt.stream.NBTOutputStream;
+import com.grinderwolf.swm.api.SlimePlugin;
+import com.grinderwolf.swm.api.exceptions.*;
+import com.grinderwolf.swm.api.loaders.SlimeLoader;
+import com.grinderwolf.swm.api.world.SlimeWorld;
+import com.grinderwolf.swm.api.world.properties.SlimeProperties;
+import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
+import org.apache.commons.io.FileUtils;
+import org.bukkit.*;
+import org.bukkit.entity.Item;
+import org.bukkit.entity.Player;
+import org.bukkit.event.world.WorldInitEvent;
+import org.bukkit.event.world.WorldLoadEvent;
+import org.bukkit.plugin.Plugin;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.*;
+import java.util.logging.Level;
+
+@SuppressWarnings("unused")
+public class AdvancedSlimeAdapter extends RestoreAdapter {
+
+ private final SlimePlugin slime;
+ private final BedWars api;
+
+ public AdvancedSlimeAdapter(Plugin plugin) {
+ super(plugin);
+ slime = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
+ api = Objects.requireNonNull(Bukkit.getServer().getServicesManager().getRegistration(BedWars.class)).getProvider();
+ }
+
+ @Override
+ public void onEnable(IArena a) {
+ if (api.getVersionSupport().getMainLevel().equalsIgnoreCase(a.getWorldName())) {
+ if (!(api.getServerType() == ServerType.BUNGEE && api.getArenaUtil().getGamesBeforeRestart() == 1)) {
+ FileUtil.setMainLevel("ignore_main_level", api.getVersionSupport());
+ getOwner().getLogger().log(Level.SEVERE, "Cannot use level-name as arenas. Automatically creating a new void map for level-name.");
+ getOwner().getLogger().log(Level.SEVERE, "The server is restarting...");
+ Bukkit.getServer().spigot().restart();
+ return;
+ }
+ }
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ if (Bukkit.getWorld(a.getWorldName()) != null) {
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ World w = Bukkit.getWorld(a.getWorldName());
+ a.init(w);
+ });
+ return;
+ }
+
+ SlimeLoader flat = slime.getLoader("file");
+ String[] spawn = a.getConfig().getString("waiting.Loc").split(",");
+
+ try {
+ // Note that this method should be called asynchronously
+ SlimeWorld world = slime.loadWorld(
+ flat,
+ a.getArenaName(),
+ true,
+ getCreateProperties(
+ (int) Double.parseDouble(spawn[0]),
+ (int) Double.parseDouble(spawn[1]),
+ (int) Double.parseDouble(spawn[2])
+ )
+ );
+
+ if (api.getServerType() == ServerType.BUNGEE && api.isAutoScale()) {
+ world = world.clone(a.getWorldName());
+ }
+
+ // This method must be called synchronously
+ SlimeWorld finalWorld = world;
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ slime.generateWorld(finalWorld);
+
+ World w = Bukkit.getWorld(a.getArenaName());
+ if (w == null) {
+ api.getArenaUtil().removeFromEnableQueue(a);
+ getOwner().getLogger().severe("Something wrong... removing arena " + a.getArenaName() + " from queue.");
+ return;
+ }
+ Bukkit.getPluginManager().callEvent(new WorldInitEvent(w));
+ Bukkit.getScheduler().runTask(
+ getOwner(), () -> Bukkit.getPluginManager().callEvent(new WorldLoadEvent(w))
+ );
+ });
+ } catch (UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException |
+ WorldInUseException ex) {
+ api.getArenaUtil().removeFromEnableQueue(a);
+ ex.printStackTrace();
+ } catch (ConcurrentModificationException thisShouldNotHappenSWM) {
+ // this should not happen since they say to use #load async
+ // https://github.com/Grinderwolf/Slime-World-Manager/blob/develop/.docs/api/load-world.md
+ thisShouldNotHappenSWM.printStackTrace();
+ api.getArenaUtil().removeFromEnableQueue(a);
+ getOwner().getLogger().severe("This is a SlimeWorldManager issue!");
+ getOwner().getLogger().severe("I've submitted a bug report: https://github.com/Grinderwolf/Slime-World-Manager/issues/174");
+ getOwner().getLogger().severe("Trying again to load arena: " + a.getArenaName());
+
+ // hope not to get an overflow
+ onEnable(a);
+ }
+ });
+ }
+
+ @Override
+ public void onRestart(IArena a) {
+ if (api.getServerType() == ServerType.BUNGEE) {
+ if (api.getArenaUtil().getGamesBeforeRestart() == 0) {
+ if (api.getArenaUtil().getArenas().size() == 1 && api.getArenaUtil().getArenas().get(0).getStatus() == GameState.restarting) {
+ getOwner().getLogger().info("Dispatching command: " + api.getConfigs().getMainConfig().getString(ConfigPath.GENERAL_CONFIGURATION_BUNGEE_OPTION_RESTART_CMD));
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), api.getConfigs().getMainConfig().getString(ConfigPath.GENERAL_CONFIGURATION_BUNGEE_OPTION_RESTART_CMD));
+ }
+ } else {
+ if (api.getArenaUtil().getGamesBeforeRestart() != -1) {
+ api.getArenaUtil().setGamesBeforeRestart(api.getArenaUtil().getGamesBeforeRestart() - 1);
+ }
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ Bukkit.unloadWorld(a.getWorldName(), false);
+ if (api.getArenaUtil().canAutoScale(a.getArenaName())) {
+ Bukkit.getScheduler().runTaskLater(getOwner(), () -> api.getArenaUtil().loadArena(a.getArenaName(), null), 80L);
+ }
+ });
+ }
+ } else {
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ Bukkit.unloadWorld(a.getWorldName(), false);
+ Bukkit.getScheduler().runTaskLater(getOwner(), () -> api.getArenaUtil().loadArena(a.getArenaName(), null), 80L);
+ });
+ }
+ }
+
+ @Override
+ public void onDisable(IArena a) {
+ if (api.isShuttingDown()) {
+ Bukkit.unloadWorld(a.getWorldName(), false);
+ return;
+ }
+ Bukkit.getScheduler().runTask(getOwner(), () -> Bukkit.unloadWorld(a.getWorldName(), false));
+ }
+
+ @Override
+ public void onSetupSessionStart(ISetupSession s) {
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ SlimeLoader sLoader = slime.getLoader("file");
+ String[] spawn = new String[]{"0", "50", "0"};
+ if (s.getConfig().getYml().getString("waiting.Loc") != null) {
+ spawn = s.getConfig().getString("waiting.Loc").split(",");
+ }
+ SlimePropertyMap spm = getCreateProperties(
+ (int) Double.parseDouble(spawn[0]),
+ (int) Double.parseDouble(spawn[1]),
+ (int) Double.parseDouble(spawn[2])
+ );
+
+ try {
+
+ if (Bukkit.getWorld(s.getWorldName()) != null) {
+ Bukkit.getScheduler().runTask(getOwner(), () -> Bukkit.unloadWorld(s.getWorldName(), false));
+ }
+
+ SlimeWorld world;
+ if (sLoader.worldExists(s.getWorldName())) {
+ world = slime.loadWorld(sLoader, s.getWorldName(), false, spm);
+ Bukkit.getScheduler().runTask(getOwner(), () -> s.getPlayer().sendMessage(ChatColor.GREEN + "Loading world from SlimeWorldManager container."));
+ } else {
+ if (new File(Bukkit.getWorldContainer(), s.getWorldName() + "/level.dat").exists()) {
+ Bukkit.getScheduler().runTask(getOwner(), () -> s.getPlayer().sendMessage(ChatColor.GREEN + "Importing world to the SlimeWorldManager container."));
+ slime.importWorld(new File(Bukkit.getWorldContainer(), s.getWorldName()), s.getWorldName().toLowerCase(), sLoader);
+ world = slime.loadWorld(sLoader, s.getWorldName(), false, spm);
+ } else {
+ Bukkit.getScheduler().runTask(getOwner(), () -> s.getPlayer().sendMessage(ChatColor.GREEN + "Creating anew void map."));
+ world = slime.createEmptyWorld(sLoader, s.getWorldName(), false, spm);
+ }
+ }
+
+ SlimeWorld sw = world;
+ // This method must be called synchronously
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ slime.generateWorld(sw);
+
+ World w = Bukkit.getWorld(s.getWorldName());
+ if (w == null) {
+ return;
+ }
+ Bukkit.getPluginManager().callEvent(new WorldInitEvent(w));
+ Bukkit.getScheduler().runTask(
+ getOwner(), () -> Bukkit.getPluginManager().callEvent(new WorldLoadEvent(w))
+ );
+ s.teleportPlayer();
+ });
+ } catch (UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException |
+ WorldInUseException | WorldAlreadyExistsException | InvalidWorldException | WorldTooBigException |
+ WorldLoadedException ex) {
+ s.getPlayer().sendMessage(ChatColor.RED + "An error occurred! Please check console.");
+ ex.printStackTrace();
+ s.close();
+ }
+ });
+ }
+
+ @Override
+ public void onSetupSessionClose(@NotNull ISetupSession s) {
+ Objects.requireNonNull(Bukkit.getWorld(s.getWorldName())).save();
+ Bukkit.getScheduler().runTask(getOwner(), () -> Bukkit.unloadWorld(s.getWorldName(), true));
+ }
+
+ @Override
+ public void onLobbyRemoval(IArena a) {
+ Location loc1 = a.getConfig().getArenaLoc(ConfigPath.ARENA_WAITING_POS1),
+ loc2 = a.getConfig().getArenaLoc(ConfigPath.ARENA_WAITING_POS2);
+ if (loc1 == null || loc2 == null) return;
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ int minX, minY, minZ;
+ int maxX, maxY, maxZ;
+ minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
+ maxX = Math.max(loc1.getBlockX(), loc2.getBlockX());
+ minY = Math.min(loc1.getBlockY(), loc2.getBlockY());
+ maxY = Math.max(loc1.getBlockY(), loc2.getBlockY());
+ minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
+ maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
+
+ for (int x = minX; x < maxX; x++) {
+ for (int y = minY; y < maxY; y++) {
+ for (int z = minZ; z < maxZ; z++) {
+ Objects.requireNonNull(loc1.getWorld()).getBlockAt(x, y, z).setType(Material.AIR);
+ }
+ }
+ }
+
+ Bukkit.getScheduler().runTaskLater(getOwner(), () ->
+ Objects.requireNonNull(loc1.getWorld()).getEntities().forEach(e -> {
+ if (e instanceof Item) e.remove();
+ }), 15L);
+ });
+ }
+
+ @Override
+ public boolean isWorld(String name) {
+ try {
+ return slime.getLoader("file").worldExists(name);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ @Override
+ public void deleteWorld(String name) {
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ try {
+ slime.getLoader("file").deleteWorld(name);
+ } catch (UnknownWorldException | IOException e) {
+ e.printStackTrace();
+ }
+ });
+ }
+
+ @Override
+ public void cloneArena(String name1, String name2) {
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+
+ try {
+ // Note that this method should be called asynchronously
+ SlimeWorld world = slime.loadWorld(
+ slime.getLoader("file"),
+ name1,
+ true,
+ getCreateProperties(0, 118, 0)
+ );
+ world.clone(name2, slime.getLoader("file"));
+
+ } catch (
+ UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException |
+ WorldInUseException | WorldAlreadyExistsException ex
+ ) {
+ ex.printStackTrace();
+ }
+
+ });
+ }
+
+ @Override
+ public List getWorldsList() {
+ try {
+ return slime.getLoader("file").listWorlds();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return new ArrayList<>();
+ }
+
+ /**
+ * Convert vanilla worlds to the slime format.
+ */
+ public void convertWorlds() {
+ File dir = new File(getOwner().getDataFolder(), "/Arenas");
+ File ff;
+ SlimeLoader sl = slime.getLoader("file");
+ if (dir.exists()) {
+ File[] fls = dir.listFiles();
+ if (fls != null) {
+ for (File fl : fls) {
+ if (fl.isFile()) {
+ if (fl.getName().endsWith(".yml")) {
+ final String name = fl.getName().replace(".yml", "").toLowerCase();
+ ff = new File(Bukkit.getWorldContainer(), fl.getName().replace(".yml", ""));
+ try {
+ if (!sl.worldExists(name)) {
+ if (!fl.getName().equals(name)) {
+ if (!fl.renameTo(new File(dir, name + ".yml"))) {
+ getOwner().getLogger().log(Level.WARNING, "Could not rename " + fl.getName() + ".yml to " + name + ".yml");
+ }
+ }
+ File bc = new File(getOwner().getDataFolder() + "/Cache", ff.getName() + ".zip");
+ if (ff.exists() && bc.exists()) {
+ FileUtil.delete(ff);
+ ZipFileUtil.unzipFileIntoDirectory(bc, new File(Bukkit.getWorldContainer(), name));
+ }
+ deleteWorldTrash(name);
+ handleLevelDat(name);
+
+ convertWorld(name, null);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ File[] files = Bukkit.getWorldContainer().listFiles();
+ if (files != null) {
+ for (File f : files) {
+ if (f != null && f.isDirectory()) {
+ if (f.getName().contains("bw_temp_")) {
+ try {
+ FileUtils.deleteDirectory(f);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "Advanced Slime World Manager by Paul19988";
+ }
+
+ @SuppressWarnings("SameParameterValue")
+ private void convertWorld(String name, @Nullable Player player) {
+ SlimeLoader sl = slime.getLoader("file");
+ try {
+ getOwner().getLogger().log(Level.INFO, "Converting " + name + " to the Slime format.");
+ slime.importWorld(new File(Bukkit.getWorldContainer(), name), name, sl);
+ } catch (WorldAlreadyExistsException | InvalidWorldException | WorldLoadedException | WorldTooBigException |
+ IOException e) {
+ if (null != player) {
+ player.sendMessage(ChatColor.RED + "Could not convert " + name + " to the Slime format.");
+ player.sendMessage(ChatColor.RED + "Check the console for details.");
+ ISetupSession s = api.getSetupSession(player.getUniqueId());
+ if (s != null) {
+ s.close();
+ }
+ }
+ getOwner().getLogger().log(Level.WARNING, "Could not convert " + name + " to the Slime format.");
+ e.printStackTrace();
+ }
+ }
+
+ private void deleteWorldTrash(String world) {
+ for (File f : new File[]{/*new File(Bukkit.getWorldContainer(), world+"/level.dat"),*/
+ new File(Bukkit.getWorldContainer(), world + "/level.dat_mcr"),
+ new File(Bukkit.getWorldContainer(), world + "/level.dat_old"),
+ new File(Bukkit.getWorldContainer(), world + "/session.lock"),
+ new File(Bukkit.getWorldContainer(), world + "/uid.dat")}) {
+ if (f.exists()) {
+ if (!f.delete()) {
+ getOwner().getLogger().warning("Could not delete: " + f.getPath());
+ getOwner().getLogger().warning("This may cause issues!");
+ }
+ }
+ }
+ }
+
+ private void handleLevelDat(String world) throws IOException {
+
+ File level = new File(Bukkit.getWorldContainer(), world + "/level.dat");
+
+ if (!level.exists()) {
+ if (level.createNewFile()) {
+ File regions = new File(Bukkit.getWorldContainer(), "world/region");
+ if (regions.exists() && Objects.requireNonNull(regions.list()).length > 0) {
+ if (Arrays.stream(Objects.requireNonNull(regions.list())).filter(p -> p.endsWith(".mca")).toArray().length > 0) {
+ File region = new File(Bukkit.getWorldContainer(), world + "/" + Arrays.stream(Objects.requireNonNull(regions.list())).filter(p -> p.endsWith(".mca")).toArray()[0]);
+ NBTInputStream inputStream = new NBTInputStream(new FileInputStream(region));
+ Optional tag = inputStream.readTag().getAsCompoundTag();
+ inputStream.close();
+ if (tag.isPresent()) {
+ Optional dataTag = tag.get().getAsCompoundTag("Chunk");
+ if (dataTag.isPresent()) {
+ int dataVersion = dataTag.get().getIntValue("DataVersion").orElse(-1);
+
+ NBTOutputStream outputStream = new NBTOutputStream(new FileOutputStream(level));
+
+ CompoundMap cm = new CompoundMap();
+ cm.put(new IntTag("SpawnX", 0));
+ cm.put(new IntTag("SpawnY", 255));
+ cm.put(new IntTag("SpawnZ", 0));
+ if (dataVersion != -1) {
+ cm.put(new IntTag("DataVersion", dataVersion));
+ }
+ CompoundTag root = new CompoundTag("Data", cm);
+ outputStream.writeTag(root);
+ outputStream.flush();
+ outputStream.close();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private @NotNull SlimePropertyMap getCreateProperties(int spawnX, int spawnY, int spawnZ) {
+ SlimePropertyMap spm = new SlimePropertyMap();
+ spm.setString(SlimeProperties.WORLD_TYPE, "flat");
+ spm.setInt(SlimeProperties.SPAWN_X, spawnX);
+ spm.setInt(SlimeProperties.SPAWN_Y, spawnY);
+ spm.setInt(SlimeProperties.SPAWN_Z, spawnZ);
+ spm.setBoolean(SlimeProperties.ALLOW_ANIMALS, false);
+ spm.setBoolean(SlimeProperties.ALLOW_MONSTERS, false);
+ spm.setString(SlimeProperties.DIFFICULTY, "easy");
+ spm.setBoolean(SlimeProperties.PVP, true);
+ return spm;
+ }
+}
diff --git a/resetadapter_slime/pom.xml b/resetadapter_slime/pom.xml
index 72632f959..0359ce241 100644
--- a/resetadapter_slime/pom.xml
+++ b/resetadapter_slime/pom.xml
@@ -7,7 +7,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
resetadapter-slime
@@ -22,11 +22,6 @@
spigotmc-repo
https://hub.spigotmc.org/nexus/content/repositories/snapshots/
-
-
- flow-nbt
- https://hub.spigotmc.org/nexus/content/repositories/snapshots/
-
@@ -48,12 +43,6 @@
2.2.1
provided
-
- com.flowpowered
- flow-nbt
- 2.0.0
- compile
-
diff --git a/resetadapter_slime/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/SlimeAdapter.java b/resetadapter_slime/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/SlimeAdapter.java
index a5539718b..b137082a9 100644
--- a/resetadapter_slime/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/SlimeAdapter.java
+++ b/resetadapter_slime/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/SlimeAdapter.java
@@ -362,6 +362,11 @@ public void convertWorlds() {
});
}
+ @Override
+ public String getDisplayName() {
+ return "Slime World Manager by Grinderwolf";
+ }
+
private void convertWorld(String name, Player player) {
SlimeLoader sl = slime.getLoader("file");
try {
diff --git a/resetadapter_slimepaper/pom.xml b/resetadapter_slimepaper/pom.xml
new file mode 100644
index 000000000..8a3058198
--- /dev/null
+++ b/resetadapter_slimepaper/pom.xml
@@ -0,0 +1,76 @@
+
+
+ 4.0.0
+
+
+ BedWars1058
+ com.andrei1058.bedwars
+ 23.6-SNAPSHOT
+
+
+ resetadapter-slimepaper
+ ${project.parent.version}
+
+
+
+ 11
+ 11
+
+
+
+
+
+ spigotmc-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+
+ is-snapshots
+ https://repo.infernalsuite.com/repository/maven-snapshots/
+
+
+ flow-nbt
+ https://repo.glaremasters.me/repository/concuncan/
+
+
+
+
+
+ com.andrei1058.bedwars
+ bedwars-api
+ ${project.version}
+ provided
+
+
+ org.spigotmc
+ spigot-api
+ 1.8.8-R0.1-SNAPSHOT
+ provided
+
+
+ com.infernalsuite.aswm
+ api
+ 1.20-R0.1-SNAPSHOT
+ provided
+
+
+ com.flowpowered
+ flow-nbt
+ 2.0.0
+ compile
+
+
+
+
+
+
+ maven-deploy-plugin
+
+ true
+
+
+
+
+
\ No newline at end of file
diff --git a/resetadapter_slimepaper/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/SlimePaperAdapter.java b/resetadapter_slimepaper/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/SlimePaperAdapter.java
new file mode 100644
index 000000000..78ca5eef7
--- /dev/null
+++ b/resetadapter_slimepaper/src/main/java/com/andrei1058/bedwars/arena/mapreset/slime/SlimePaperAdapter.java
@@ -0,0 +1,478 @@
+/*
+ * BedWars1058 - A bed wars mini-game.
+ * Copyright (C) 2023 Andrei Dascălu
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * Contact e-mail: andrew.dascalu@gmail.com
+ */
+
+package com.andrei1058.bedwars.arena.mapreset.slime;
+
+import com.andrei1058.bedwars.api.BedWars;
+import com.andrei1058.bedwars.api.arena.GameState;
+import com.andrei1058.bedwars.api.arena.IArena;
+import com.andrei1058.bedwars.api.configuration.ConfigPath;
+import com.andrei1058.bedwars.api.server.ISetupSession;
+import com.andrei1058.bedwars.api.server.RestoreAdapter;
+import com.andrei1058.bedwars.api.server.ServerType;
+import com.andrei1058.bedwars.api.util.FileUtil;
+import com.andrei1058.bedwars.api.util.ZipFileUtil;
+import com.flowpowered.nbt.CompoundMap;
+import com.flowpowered.nbt.CompoundTag;
+import com.flowpowered.nbt.IntTag;
+import com.flowpowered.nbt.stream.NBTInputStream;
+import com.flowpowered.nbt.stream.NBTOutputStream;
+import com.infernalsuite.aswm.api.SlimePlugin;
+import com.infernalsuite.aswm.api.exceptions.*;
+import com.infernalsuite.aswm.api.loaders.SlimeLoader;
+import com.infernalsuite.aswm.api.world.SlimeWorld;
+import com.infernalsuite.aswm.api.world.properties.SlimeProperties;
+import com.infernalsuite.aswm.api.world.properties.SlimePropertyMap;
+import org.apache.commons.io.FileUtils;
+import org.bukkit.*;
+import org.bukkit.entity.Item;
+import org.bukkit.entity.Player;
+import org.bukkit.event.world.WorldInitEvent;
+import org.bukkit.event.world.WorldLoadEvent;
+import org.bukkit.plugin.Plugin;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.*;
+import java.util.logging.Level;
+
+public class SlimePaperAdapter extends RestoreAdapter {
+
+ private final SlimePlugin slime;
+ private final BedWars api;
+
+ public SlimePaperAdapter(Plugin plugin) {
+ super(plugin);
+ slime = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
+ api = Objects.requireNonNull(Bukkit.getServer().getServicesManager().getRegistration(BedWars.class)).getProvider();
+ }
+
+ @Override
+ public void onEnable(@NotNull IArena a) {
+ if (api.getVersionSupport().getMainLevel().equalsIgnoreCase(a.getWorldName())) {
+ if (!(api.getServerType() == ServerType.BUNGEE && api.getArenaUtil().getGamesBeforeRestart() == 1)) {
+ FileUtil.setMainLevel("ignore_main_level", api.getVersionSupport());
+ getOwner().getLogger().log(Level.SEVERE, "Cannot use level-name as arenas. Automatically creating a new void map for level-name.");
+ getOwner().getLogger().log(Level.SEVERE, "The server is restarting...");
+ Bukkit.getServer().spigot().restart();
+ return;
+ }
+ }
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ if (Bukkit.getWorld(a.getWorldName()) != null) {
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ World w = Bukkit.getWorld(a.getWorldName());
+ a.init(w);
+ });
+ return;
+ }
+
+ SlimeLoader flat = slime.getLoader("file");
+ String[] spawn = a.getConfig().getString("waiting.Loc").split(",");
+
+ SlimePropertyMap spm = getCreateProperties(
+ (int) Double.parseDouble(spawn[0]),
+ (int) Double.parseDouble(spawn[1]),
+ (int) Double.parseDouble(spawn[2])
+ );
+
+ try {
+ // Note that this method should be called asynchronously
+ SlimeWorld world = slime.loadWorld(flat, a.getArenaName(), true, spm);
+ if (api.getServerType() == ServerType.BUNGEE && api.isAutoScale()) {
+ world = world.clone(a.getWorldName());
+ }
+
+ // This method must be called synchronously
+ SlimeWorld finalWorld = world;
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ SlimeWorld loaded = slime.loadWorld(finalWorld);
+ if (null == loaded) {
+ api.getArenaUtil().removeFromEnableQueue(a);
+ getOwner().getLogger().severe("Something wrong... removing arena " + a.getArenaName() + " from queue.");
+ return;
+ }
+ World w = Bukkit.getWorld(loaded.getName());
+ if (w == null) {
+ api.getArenaUtil().removeFromEnableQueue(a);
+ getOwner().getLogger().severe("Something wrong... removing arena " + a.getArenaName() + " from queue.");
+ return;
+ }
+ Bukkit.getPluginManager().callEvent(new WorldInitEvent(w));
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ Bukkit.getPluginManager().callEvent(new WorldLoadEvent(w));
+ });
+ });
+ } catch (UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException |
+ WorldLockedException ex) {
+ api.getArenaUtil().removeFromEnableQueue(a);
+ ex.printStackTrace();
+ } catch (ConcurrentModificationException thisShouldNotHappenSWM) {
+ // this should not happen since they say to use #load async
+ // https://github.com/Grinderwolf/Slime-World-Manager/blob/develop/.docs/api/load-world.md
+ thisShouldNotHappenSWM.printStackTrace();
+ api.getArenaUtil().removeFromEnableQueue(a);
+ getOwner().getLogger().severe("This is a AdvancedSlimePaper issue!");
+ getOwner().getLogger().severe("I've submitted a bug report: https://github.com/Grinderwolf/Slime-World-Manager/issues/174");
+ getOwner().getLogger().severe("Trying again to load arena: " + a.getArenaName());
+
+ // hope not to get an overflow
+ onEnable(a);
+ }
+ });
+ }
+
+ @Override
+ public void onRestart(IArena a) {
+ if (api.getServerType() == ServerType.BUNGEE) {
+ if (api.getArenaUtil().getGamesBeforeRestart() == 0) {
+ if (api.getArenaUtil().getArenas().size() == 1 && api.getArenaUtil().getArenas().get(0).getStatus() == GameState.restarting) {
+ getOwner().getLogger().info("Dispatching command: " + api.getConfigs().getMainConfig().getString(ConfigPath.GENERAL_CONFIGURATION_BUNGEE_OPTION_RESTART_CMD));
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), api.getConfigs().getMainConfig().getString(ConfigPath.GENERAL_CONFIGURATION_BUNGEE_OPTION_RESTART_CMD));
+ }
+ } else {
+ if (api.getArenaUtil().getGamesBeforeRestart() != -1) {
+ api.getArenaUtil().setGamesBeforeRestart(api.getArenaUtil().getGamesBeforeRestart() - 1);
+ }
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ Bukkit.unloadWorld(a.getWorldName(), false);
+ if (api.getArenaUtil().canAutoScale(a.getArenaName())) {
+ Bukkit.getScheduler().runTaskLater(getOwner(), () -> api.getArenaUtil().loadArena(a.getArenaName(), null), 80L);
+ }
+ });
+ }
+ } else {
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ Bukkit.unloadWorld(a.getWorldName(), false);
+ Bukkit.getScheduler().runTaskLater(getOwner(), () -> api.getArenaUtil().loadArena(a.getArenaName(), null), 80L);
+ });
+ }
+ }
+
+ @Override
+ public void onDisable(IArena a) {
+ if (api.isShuttingDown()) {
+ Bukkit.unloadWorld(a.getWorldName(), false);
+ return;
+ }
+ Bukkit.getScheduler().runTask(getOwner(), () -> Bukkit.unloadWorld(a.getWorldName(), false));
+ }
+
+ @Override
+ public void onSetupSessionStart(ISetupSession s) {
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ SlimeLoader sLoader = slime.getLoader("file");
+ String[] spawn = new String[]{"0", "50", "0"};
+ if (s.getConfig().getYml().getString("waiting.Loc") != null) {
+ spawn = s.getConfig().getString("waiting.Loc").split(",");
+ }
+ SlimePropertyMap spm = getCreateProperties(
+ (int) Double.parseDouble(spawn[0]),
+ (int) Double.parseDouble(spawn[1]),
+ (int) Double.parseDouble(spawn[2])
+ );
+
+ try {
+
+ if (Bukkit.getWorld(s.getWorldName()) != null) {
+ Bukkit.getScheduler().runTask(getOwner(), () -> Bukkit.unloadWorld(s.getWorldName(), false));
+ }
+
+ SlimeWorld world;
+ if (sLoader.worldExists(s.getWorldName())) {
+ world = slime.loadWorld(sLoader, s.getWorldName(), false, spm);
+ Bukkit.getScheduler().runTask(getOwner(), () -> s.getPlayer().sendMessage(ChatColor.GREEN + "Loading world from SlimeWorldManager container."));
+ } else {
+ if (new File(Bukkit.getWorldContainer(), s.getWorldName() + "/level.dat").exists()) {
+ Bukkit.getScheduler().runTask(getOwner(), () -> s.getPlayer().sendMessage(ChatColor.GREEN + "Importing world to the SlimeWorldManager container."));
+ slime.importWorld(new File(Bukkit.getWorldContainer(), s.getWorldName()), s.getWorldName().toLowerCase(), sLoader);
+ world = slime.loadWorld(sLoader, s.getWorldName(), false, spm);
+ } else {
+ Bukkit.getScheduler().runTask(getOwner(), () -> s.getPlayer().sendMessage(ChatColor.GREEN + "Creating anew void map."));
+ world = slime.createEmptyWorld(sLoader, s.getWorldName(), false, spm);
+ }
+ }
+
+ SlimeWorld sw = world;
+ // This method must be called synchronously
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ if (null == sw) {
+ return;
+ }
+ World w = Bukkit.getWorld(sw.getName());
+ if (w == null) {
+ return;
+ }
+ Bukkit.getPluginManager().callEvent(new WorldInitEvent(w));
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ Bukkit.getPluginManager().callEvent(new WorldLoadEvent(w));
+ });
+ s.teleportPlayer();
+ });
+ } catch (UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException |
+ WorldAlreadyExistsException | InvalidWorldException | WorldTooBigException | WorldLoadedException |
+ WorldLockedException ex) {
+ s.getPlayer().sendMessage(ChatColor.RED + "An error occurred! Please check console.");
+ ex.printStackTrace();
+ s.close();
+ }
+ });
+ }
+
+ @Override
+ public void onSetupSessionClose(ISetupSession s) {
+ Objects.requireNonNull(Bukkit.getWorld(s.getWorldName())).save();
+ Bukkit.getScheduler().runTask(getOwner(), () -> Bukkit.unloadWorld(s.getWorldName(), true));
+ }
+
+ @Override
+ public void onLobbyRemoval(IArena a) {
+ Location loc1 = a.getConfig().getArenaLoc(ConfigPath.ARENA_WAITING_POS1),
+ loc2 = a.getConfig().getArenaLoc(ConfigPath.ARENA_WAITING_POS2);
+ if (loc1 == null || loc2 == null) return;
+ Bukkit.getScheduler().runTask(getOwner(), () -> {
+ int minX, minY, minZ;
+ int maxX, maxY, maxZ;
+ minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
+ maxX = Math.max(loc1.getBlockX(), loc2.getBlockX());
+ minY = Math.min(loc1.getBlockY(), loc2.getBlockY());
+ maxY = Math.max(loc1.getBlockY(), loc2.getBlockY());
+ minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
+ maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
+
+ for (int x = minX; x < maxX; x++) {
+ for (int y = minY; y < maxY; y++) {
+ for (int z = minZ; z < maxZ; z++) {
+ Objects.requireNonNull(loc1.getWorld()).getBlockAt(x, y, z).setType(Material.AIR);
+ }
+ }
+ }
+
+ Bukkit.getScheduler().runTaskLater(getOwner(), () ->
+ Objects.requireNonNull(loc1.getWorld()).getEntities().forEach(e -> {
+ if (e instanceof Item) e.remove();
+ }), 15L);
+ });
+ }
+
+ @Override
+ public boolean isWorld(String name) {
+ try {
+ return slime.getLoader("file").worldExists(name);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ @Override
+ public void deleteWorld(String name) {
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ try {
+ slime.getLoader("file").deleteWorld(name);
+ } catch (UnknownWorldException | IOException e) {
+ e.printStackTrace();
+ }
+ });
+ }
+
+ @Override
+ public void cloneArena(String name1, String name2) {
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ try {
+ // Note that this method should be called asynchronously
+ SlimeWorld world = slime.loadWorld(
+ slime.getLoader("file"),
+ name1,
+ true,
+ getCreateProperties(0, 118, 0)
+ );
+ world.clone(name2, slime.getLoader("file"));
+ } catch (UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException |
+ WorldLockedException | WorldAlreadyExistsException ex) {
+ ex.printStackTrace();
+ }
+ });
+ }
+
+ @Override
+ public List getWorldsList() {
+ try {
+ return slime.getLoader("file").listWorlds();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return new ArrayList<>();
+ }
+
+ /**
+ * Convert vanilla worlds to the slime format.
+ */
+ public void convertWorlds() {
+ File dir = new File(getOwner().getDataFolder(), "/Arenas");
+ File ff;
+ SlimeLoader sl = slime.getLoader("file");
+ if (dir.exists()) {
+ File[] fls = dir.listFiles();
+ if (fls != null) {
+ for (File fl : fls) {
+ if (fl.isFile()) {
+ if (fl.getName().endsWith(".yml")) {
+ final String name = fl.getName().replace(".yml", "").toLowerCase();
+ ff = new File(Bukkit.getWorldContainer(), fl.getName().replace(".yml", ""));
+ try {
+ if (!sl.worldExists(name)) {
+ if (!fl.getName().equals(name)) {
+ if (!fl.renameTo(new File(dir, name + ".yml"))) {
+ getOwner().getLogger().log(Level.WARNING, "Could not rename " + fl.getName() + ".yml to " + name + ".yml");
+ }
+ }
+ File bc = new File(getOwner().getDataFolder() + "/Cache", ff.getName() + ".zip");
+ if (ff.exists() && bc.exists()) {
+ FileUtil.delete(ff);
+ ZipFileUtil.unzipFileIntoDirectory(bc, new File(Bukkit.getWorldContainer(), name));
+ }
+ deleteWorldTrash(name);
+ handleLevelDat(name);
+
+ convertWorld(name, null);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
+ Bukkit.getScheduler().runTaskAsynchronously(getOwner(), () -> {
+ File[] files = Bukkit.getWorldContainer().listFiles();
+ if (files != null) {
+ for (File f : files) {
+ if (f != null && f.isDirectory()) {
+ if (f.getName().contains("bw_temp_")) {
+ try {
+ FileUtils.deleteDirectory(f);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "Advanced Slime Paper by InfernalSuite";
+ }
+
+ @SuppressWarnings("SameParameterValue")
+ private void convertWorld(String name, Player player) {
+ SlimeLoader sl = slime.getLoader("file");
+ try {
+ getOwner().getLogger().log(Level.INFO, "Converting " + name + " to the Slime format.");
+ slime.importWorld(new File(Bukkit.getWorldContainer(), name), name, sl);
+ } catch (WorldAlreadyExistsException | InvalidWorldException | WorldLoadedException | WorldTooBigException |
+ IOException e) {
+ if (player != null) {
+ player.sendMessage(ChatColor.RED + "Could not convert " + name + " to the Slime format.");
+ player.sendMessage(ChatColor.RED + "Check the console for details.");
+ ISetupSession s = api.getSetupSession(player.getUniqueId());
+ if (s != null) {
+ s.close();
+ }
+ }
+ getOwner().getLogger().log(Level.WARNING, "Could not convert " + name + " to the Slime format.");
+ e.printStackTrace();
+ }
+ }
+
+ private void deleteWorldTrash(String world) {
+ for (File f : new File[]{/*new File(Bukkit.getWorldContainer(), world+"/level.dat"),*/
+ new File(Bukkit.getWorldContainer(), world + "/level.dat_mcr"),
+ new File(Bukkit.getWorldContainer(), world + "/level.dat_old"),
+ new File(Bukkit.getWorldContainer(), world + "/session.lock"),
+ new File(Bukkit.getWorldContainer(), world + "/uid.dat")}) {
+ if (f.exists()) {
+ if (!f.delete()) {
+ getOwner().getLogger().warning("Could not delete: " + f.getPath());
+ getOwner().getLogger().warning("This may cause issues!");
+ }
+ }
+ }
+ }
+
+ private void handleLevelDat(String world) throws IOException {
+
+ File level = new File(Bukkit.getWorldContainer(), world + "/level.dat");
+
+ if (!level.exists()) {
+ if (level.createNewFile()) {
+ File regions = new File(Bukkit.getWorldContainer(), "world/region");
+ if (regions.exists() && Objects.requireNonNull(regions.list()).length > 0) {
+ if (Arrays.stream(Objects.requireNonNull(regions.list())).filter(p -> p.endsWith(".mca")).toArray().length > 0) {
+ File region = new File(Bukkit.getWorldContainer(), world + "/" + Arrays.stream(Objects.requireNonNull(regions.list())).filter(p -> p.endsWith(".mca")).toArray()[0]);
+ NBTInputStream inputStream = new NBTInputStream(new FileInputStream(region));
+ Optional tag = inputStream.readTag().getAsCompoundTag();
+ inputStream.close();
+ if (tag.isPresent()) {
+ Optional dataTag = tag.get().getAsCompoundTag("Chunk");
+ if (dataTag.isPresent()) {
+ int dataVersion = dataTag.get().getIntValue("DataVersion").orElse(-1);
+
+ NBTOutputStream outputStream = new NBTOutputStream(new FileOutputStream(level));
+
+ CompoundMap cm = new CompoundMap();
+ cm.put(new IntTag("SpawnX", 0));
+ cm.put(new IntTag("SpawnY", 255));
+ cm.put(new IntTag("SpawnZ", 0));
+ if (dataVersion != -1) {
+ cm.put(new IntTag("DataVersion", dataVersion));
+ }
+ CompoundTag root = new CompoundTag("Data", cm);
+ outputStream.writeTag(root);
+ outputStream.flush();
+ outputStream.close();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private @NotNull SlimePropertyMap getCreateProperties(int spawnX, int spawnY, int spawnZ) {
+ SlimePropertyMap spm = new SlimePropertyMap();
+ spm.setValue(SlimeProperties.WORLD_TYPE, "flat");
+ spm.setValue(SlimeProperties.SPAWN_X, spawnX);
+ spm.setValue(SlimeProperties.SPAWN_Y, spawnY);
+ spm.setValue(SlimeProperties.SPAWN_Z, spawnZ);
+ spm.setValue(SlimeProperties.ALLOW_ANIMALS, false);
+ spm.setValue(SlimeProperties.ALLOW_MONSTERS, false);
+ spm.setValue(SlimeProperties.DIFFICULTY, "easy");
+ spm.setValue(SlimeProperties.PVP, true);
+ return spm;
+ }
+}
diff --git a/versionsupport_1_12_R1/pom.xml b/versionsupport_1_12_R1/pom.xml
index a6174c3ec..d931d78c2 100644
--- a/versionsupport_1_12_R1/pom.xml
+++ b/versionsupport_1_12_R1/pom.xml
@@ -10,7 +10,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
diff --git a/versionsupport_1_8_R3/pom.xml b/versionsupport_1_8_R3/pom.xml
index e1d9d05d4..4359bd414 100644
--- a/versionsupport_1_8_R3/pom.xml
+++ b/versionsupport_1_8_R3/pom.xml
@@ -7,7 +7,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
versionsupport_1_8_R3
diff --git a/versionsupport_common/pom.xml b/versionsupport_common/pom.xml
index 185f49df8..346439743 100644
--- a/versionsupport_common/pom.xml
+++ b/versionsupport_common/pom.xml
@@ -5,7 +5,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
4.0.0
diff --git a/versionsupport_v1_16_R3/pom.xml b/versionsupport_v1_16_R3/pom.xml
index 26c2b0971..ae5ff04c8 100644
--- a/versionsupport_v1_16_R3/pom.xml
+++ b/versionsupport_v1_16_R3/pom.xml
@@ -5,7 +5,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
4.0.0
diff --git a/versionsupport_v1_17_R1/pom.xml b/versionsupport_v1_17_R1/pom.xml
index 9d758b14b..f01bf20fc 100644
--- a/versionsupport_v1_17_R1/pom.xml
+++ b/versionsupport_v1_17_R1/pom.xml
@@ -5,7 +5,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
4.0.0
diff --git a/versionsupport_v1_18_R2/pom.xml b/versionsupport_v1_18_R2/pom.xml
index df95ac88e..08e5f1559 100644
--- a/versionsupport_v1_18_R2/pom.xml
+++ b/versionsupport_v1_18_R2/pom.xml
@@ -5,7 +5,7 @@
BedWars1058
com.andrei1058.bedwars
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
4.0.0
diff --git a/versionsupport_v1_19_R2/pom.xml b/versionsupport_v1_19_R2/pom.xml
index 6e91e2e5d..e39437158 100644
--- a/versionsupport_v1_19_R2/pom.xml
+++ b/versionsupport_v1_19_R2/pom.xml
@@ -6,7 +6,7 @@
com.andrei1058.bedwars
BedWars1058
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
versionsupport_v1_19_R2
diff --git a/versionsupport_v1_19_R3/pom.xml b/versionsupport_v1_19_R3/pom.xml
index 81904caa2..5d5be96a6 100644
--- a/versionsupport_v1_19_R3/pom.xml
+++ b/versionsupport_v1_19_R3/pom.xml
@@ -6,7 +6,7 @@
com.andrei1058.bedwars
BedWars1058
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
versionsupport_v1_19_R3
diff --git a/versionsupport_v1_20_R1/pom.xml b/versionsupport_v1_20_R1/pom.xml
index 40643120d..b168e907c 100644
--- a/versionsupport_v1_20_R1/pom.xml
+++ b/versionsupport_v1_20_R1/pom.xml
@@ -6,7 +6,7 @@
com.andrei1058.bedwars
BedWars1058
- 22.9-SNAPSHOT
+ 23.6-SNAPSHOT
versionsupport_v1_20_R1