Skip to content

Commit

Permalink
Fix issue with plugin incompatibility causing crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Dec 6, 2023
1 parent 8d03e69 commit 1266cdf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import me.lokka30.phantomworlds.listeners.player.PlayerDeathListener;
import me.lokka30.phantomworlds.listeners.player.PlayerJoinListener;
import me.lokka30.phantomworlds.listeners.player.PlayerPortalListener;
import me.lokka30.phantomworlds.listeners.world.WorldInitListener;
import me.lokka30.phantomworlds.managers.FileManager;
import me.lokka30.phantomworlds.managers.WorldManager;
import me.lokka30.phantomworlds.misc.CompatibilityChecker;
import me.lokka30.phantomworlds.misc.UpdateCheckerResult;
import me.lokka30.phantomworlds.scheduler.BackupScheduler;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import revxrsal.commands.bukkit.BukkitCommandHandler;
Expand Down Expand Up @@ -106,7 +109,6 @@ public void onEnable() {
QuickTimer timer = new QuickTimer(TimeUnit.MILLISECONDS);
checkCompatibility();
loadFiles();
loadWorlds();

registerCommands();
registerListeners();
Expand Down Expand Up @@ -247,7 +249,7 @@ void registerListeners() {
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
getServer().getPluginManager().registerEvents(new PlayerPortalListener(this), this);

//getServer().getPluginManager().registerEvents(new WorldInitListener(this), this);
getServer().getPluginManager().registerEvents(new WorldInitListener(this), this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public WorldInitListener(PhantomWorlds plugin) {

@EventHandler
public void onInit(WorldInitEvent event) {
if(PhantomWorlds.instance().data.getConfig().contains("worlds-to-load." + event.getWorld().getName())) {

}
if(!plugin.isWorldLoaded()) {
plugin.loadWorlds();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ public void loadManagedWorlds() {
return;
}

final String defaultWorld = Utils.defaultWorld();

//noinspection ConstantConditions
for(final String worldName : PhantomWorlds.instance().data.getConfig().getConfigurationSection("worlds-to-load").getKeys(false)) {

if(worldName.equalsIgnoreCase(defaultWorld) || worldName.startsWith(defaultWorld)) {
continue;
}

final WorldLoadResponse response = loadWorld(worldName);

if(response.equals(WorldLoadResponse.INVALID)) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/me/lokka30/phantomworlds/misc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Properties;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

Expand Down Expand Up @@ -399,4 +402,16 @@ public static boolean checkWorld(@NotNull final CommandSender sender, final Stri
}
return true;
}

public static String defaultWorld() {
try (InputStream input = Files.newInputStream(new File(PhantomWorlds.instance().getDataFolder(), "../../server.properties").toPath())) {

final Properties prop = new Properties();
prop.load(input);

return prop.getProperty("level-name");
} catch(Exception ignore) {
return "world";
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ website: 'https://github.com/lokka30/PhantomWorlds'

main: 'me.lokka30.phantomworlds.PhantomWorlds'
api-version: '1.13'
load: POSTWORLD
load: STARTUP

commands:
phantomworlds:
Expand Down

0 comments on commit 1266cdf

Please sign in to comment.