Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

world restore adapters update #820

Merged
merged 6 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/compile_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion bedwars-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>22.9-SNAPSHOT</version>
<version>23.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bedwars-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
15 changes: 14 additions & 1 deletion bedwars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>22.9-SNAPSHOT</version>
<version>23.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bedwars-plugin</artifactId>
Expand Down Expand Up @@ -294,6 +294,19 @@
<scope>compile</scope>
</dependency>
<!-- End of Sidebar LIB-->
<!-- Slime Paper -->
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>resetadapter-slimepaper</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Slime Paper -->
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>resetadapter-aswm</artifactId>
<version>${project.version}</version>
</dependency>
<!-- End of Slime Paper -->
</dependencies>

<build>
Expand Down
123 changes: 51 additions & 72 deletions bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
20 changes: 11 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>BedWars1058</artifactId>
<packaging>pom</packaging>
<version>22.9-SNAPSHOT</version>
<version>23.6-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -21,14 +21,14 @@
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/groups/4800570/-/packages/maven</url>
</repository>
<repository>
<id>vipfeatures-maven</id>
<url>https://gitlab.com/api/v4/projects/6491858/packages/maven</url>
</repository>
<!-- <repository>-->
<!-- <id>gitlab-maven</id>-->
<!-- <url>https://gitlab.com/api/v4/groups/4800570/-/packages/maven</url>-->
<!-- </repository>-->
<!-- <repository>-->
<!-- <id>vipfeatures-maven</id>-->
<!-- <url>https://gitlab.com/api/v4/projects/6491858/packages/maven</url>-->
<!-- </repository>-->
<repository>
<id>codemc-nms</id>
<url>https://repo.codemc.io/repository/nms/</url>
Expand Down Expand Up @@ -100,7 +100,9 @@
<modules>
<module>bedwars-plugin</module>
<module>bedwars-api</module>
<module>resetadapter_aswm</module>
<module>resetadapter_slime</module>
<module>resetadapter_slimepaper</module>
<module>versionsupport_1_8_R3</module>
<module>versionsupport_1_12_R1</module>
<module>versionsupport_common</module>
Expand Down
68 changes: 68 additions & 0 deletions resetadapter_aswm/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.6-SNAPSHOT</version>
</parent>

<artifactId>resetadapter-aswm</artifactId>
<version>${project.parent.version}</version>

<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>flow-nbt</id>
<url>https://repo.glaremasters.me/repository/concuncan/</url>
</repository>
<repository>
<id>legacy-aswm</id>
<url>https://repo.rapture.pw/repository/maven-snapshots/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.andrei1058.bedwars</groupId>
<artifactId>bedwars-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.grinderwolf</groupId>
<artifactId>slimeworldmanager-api</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.flowpowered</groupId>
<artifactId>flow-nbt</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading