From 4b4af88af7aa45c37032d021c3025af6c3f0c4f4 Mon Sep 17 00:00:00 2001 From: Misat11 <20199703+Misat11@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:22:42 +0200 Subject: [PATCH] feat: go to snapshot, allow loading slightly broken files with some warnings or errors in log --- build.gradle | 2 +- .../screamingsandals/bedwars/game/Game.java | 22 ++++++++++++++++++- .../bedwars/game/ItemSpawner.java | 2 ++ .../holograms/LeaderboardHolograms.java | 19 +++++++++++----- .../holograms/StatisticsHolograms.java | 19 +++++++++++----- .../bedwars/lib/signmanager/SignManager.java | 6 ++++- 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index f8805f5ed..e3130a236 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { allprojects { group = 'org.screamingsandals.bedwars' - version = '0.2.34' + version = '0.2.35-SNAPSHOT' } if (version.toString().endsWith('-SNAPSHOT')) { diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java b/plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java index 79aa476d5..37de6ef9f 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java @@ -1057,6 +1057,10 @@ public static Game loadGame(File file, boolean firstAttempt) { ((Number) spawner.getOrDefault("startLevel", 1)).doubleValue(), game.getTeamFromName((String) spawner.get("team")), (int) spawner.getOrDefault("maxSpawnedResources", -1)); + if (sa.type == null) { + sa.declaredSpawnerType = (String) spawner.get("type"); + Main.getInstance().getLogger().warning("There is an unknown spawner type " + sa.declaredSpawnerType + " defined in game " + game.name + " on location " + spawner.get("location")); + } game.spawners.add(sa); } } @@ -1226,7 +1230,7 @@ public void saveToConfig() { for (ItemSpawner spawner : spawners) { Map spawnerMap = new HashMap<>(); spawnerMap.put("location", MiscUtils.setLocationToString(spawner.loc)); - spawnerMap.put("type", spawner.type.getConfigKey()); + spawnerMap.put("type", spawner.type != null ? spawner.type.getConfigKey() : spawner.declaredSpawnerType); spawnerMap.put("customName", spawner.customName); spawnerMap.put("startLevel", spawner.startLevel); spawnerMap.put("hologramEnabled", spawner.hologramEnabled); @@ -1933,6 +1937,10 @@ public void run() { } for (ItemSpawner spawner : spawners) { + if (spawner.type == null) { + continue; + } + spawner.countdownDelay = 0; spawner.currentCycle = spawner.type.getInterval(); @@ -1944,6 +1952,10 @@ public void run() { if (getOriginalOrInheritedSpawnerHolograms()) { for (ItemSpawner spawner : spawners) { + if (spawner.type == null) { + continue; + } + CurrentTeam spawnerTeam = getCurrentTeamFromTeam(spawner.getTeam()); if (getOriginalOrInheritedStopTeamSpawnersOnDie() && spawner.getTeam() != null && spawnerTeam == null) { continue; // team of this spawner is not available. Fix #147 @@ -2246,6 +2258,10 @@ public void run() { } } else if (countdown != gameTime /* Prevent spawning resources on game start */) { for (ItemSpawner spawner : spawners) { + if (spawner.type == null) { + continue; + } + CurrentTeam spawnerTeam = getCurrentTeamFromTeam(spawner.getTeam()); if (getOriginalOrInheritedStopTeamSpawnersOnDie() && spawner.getTeam() != null && spawnerTeam == null) { continue; // team of this spawner is not available. Fix #147 @@ -2420,6 +2436,10 @@ public void rebuild() { Main.getInstance().getServer().getPluginManager().callEvent(preRebuildingEvent); for (ItemSpawner spawner : spawners) { + if (spawner.type == null) { + continue; + } + spawner.currentLevel = spawner.startLevel; spawner.spawnedItems.clear(); } diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/game/ItemSpawner.java b/plugin/src/main/java/org/screamingsandals/bedwars/game/ItemSpawner.java index 9780389b6..ab1232577 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/game/ItemSpawner.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/game/ItemSpawner.java @@ -20,6 +20,7 @@ package org.screamingsandals.bedwars.game; import org.bukkit.entity.Entity; +import org.jetbrains.annotations.Nullable; import org.screamingsandals.bedwars.api.Team; import org.screamingsandals.bedwars.lib.nms.holograms.Hologram; @@ -33,6 +34,7 @@ public class ItemSpawner implements org.screamingsandals.bedwars.api.game.ItemSpawner { public Location loc; + public @Nullable String declaredSpawnerType; public ItemSpawnerType type; public String customName; public double startLevel; diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/holograms/LeaderboardHolograms.java b/plugin/src/main/java/org/screamingsandals/bedwars/holograms/LeaderboardHolograms.java index 0318a8531..d5de9d16b 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/holograms/LeaderboardHolograms.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/holograms/LeaderboardHolograms.java @@ -77,13 +77,22 @@ public void loadHolograms() { File file = new File(Main.getInstance().getDataFolder(), "holodb_leaderboard.yml"); if (file.exists()) { - YamlConfiguration config = YamlConfiguration.loadConfiguration(file); - List locations = (List) config.get("locations"); - assert locations != null; - this.hologramLocations.addAll(locations); + try { + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + List locations = (List) config.get("locations"); + if (locations != null) { + if (locations.removeIf(location -> location.getWorld() == null)) { // Skip invalid locations + Main.getInstance().getLogger().warning("There are holograms in " + file.getAbsolutePath() + " with location in unknown world! They were removed from the configuration"); + } + this.hologramLocations.addAll(locations); + } + } catch (Throwable t) { + Main.getInstance().getLogger().severe("Failed to load holograms from " + file.getAbsolutePath()); + t.printStackTrace(); + } } - if (this.hologramLocations.size() == 0) { + if (this.hologramLocations.isEmpty()) { return; } diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/holograms/StatisticsHolograms.java b/plugin/src/main/java/org/screamingsandals/bedwars/holograms/StatisticsHolograms.java index 797a8acd6..52f9c4f79 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/holograms/StatisticsHolograms.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/holograms/StatisticsHolograms.java @@ -63,13 +63,22 @@ public void loadHolograms() { File file = new File(Main.getInstance().getDataFolder(), "holodb.yml"); if (file.exists()) { - YamlConfiguration config = YamlConfiguration.loadConfiguration(file); - List locations = (List) config.get("locations"); - assert locations != null; - this.hologramLocations.addAll(locations); + try { + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + List locations = (List) config.get("locations"); + if (locations != null) { + if (locations.removeIf(location -> location.getWorld() == null)) { // Skip invalid locations + Main.getInstance().getLogger().warning("There are holograms in " + file.getAbsolutePath() + " with location in unknown world! They were removed from the configuration"); + } + this.hologramLocations.addAll(locations); + } + } catch (Throwable t) { + Main.getInstance().getLogger().severe("Failed to load holograms from " + file.getAbsolutePath()); + t.printStackTrace(); + } } - if (this.hologramLocations.size() == 0) { + if (this.hologramLocations.isEmpty()) { return; } diff --git a/plugin/src/main/java/org/screamingsandals/bedwars/lib/signmanager/SignManager.java b/plugin/src/main/java/org/screamingsandals/bedwars/lib/signmanager/SignManager.java index 20f38f81f..a00fa8b88 100644 --- a/plugin/src/main/java/org/screamingsandals/bedwars/lib/signmanager/SignManager.java +++ b/plugin/src/main/java/org/screamingsandals/bedwars/lib/signmanager/SignManager.java @@ -59,10 +59,14 @@ public void loadConfig() { if (conf != null) { for (Map c : conf) { String name = (String) c.get("name"); - if (name == null || name.trim().equals("")) { + if (name == null || name.trim().isEmpty()) { name = (String) c.get("game"); // Compatibility with old BedWars sign.yml } Location loc = (Location) c.get("location"); + if (loc.getWorld() == null) { + Main.getInstance().getLogger().warning("A sign on location " + loc.getX() + ";" + loc.getY() + ";" + loc.getZ() + " is in unknown world! It was removed from the configuration"); + continue; // Skip invalid locations + } signs.put(loc, new SignBlock(loc, name)); owner.updateSign(signs.get(loc)); }