Skip to content

Commit

Permalink
feat: go to snapshot, allow loading slightly broken files with some w…
Browse files Browse the repository at this point in the history
…arnings or errors in log
  • Loading branch information
Misat11 committed Aug 26, 2024
1 parent d7dfa56 commit 4b4af88
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

allprojects {
group = 'org.screamingsandals.bedwars'
version = '0.2.34'
version = '0.2.35-SNAPSHOT'
}

if (version.toString().endsWith('-SNAPSHOT')) {
Expand Down
22 changes: 21 additions & 1 deletion plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -1226,7 +1230,7 @@ public void saveToConfig() {
for (ItemSpawner spawner : spawners) {
Map<String, Object> 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);
Expand Down Expand Up @@ -1933,6 +1937,10 @@ public void run() {
}

for (ItemSpawner spawner : spawners) {
if (spawner.type == null) {
continue;
}

spawner.countdownDelay = 0;
spawner.currentCycle = spawner.type.getInterval();

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location> locations = (List<Location>) config.get("locations");
assert locations != null;
this.hologramLocations.addAll(locations);
try {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
List<Location> locations = (List<Location>) 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location> locations = (List<Location>) config.get("locations");
assert locations != null;
this.hologramLocations.addAll(locations);
try {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
List<Location> locations = (List<Location>) 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ public void loadConfig() {
if (conf != null) {
for (Map<String, Object> 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));
}
Expand Down

0 comments on commit 4b4af88

Please sign in to comment.