Skip to content

Commit

Permalink
Fixed errors when loading data from invalid worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Feb 25, 2022
1 parent 6143b75 commit 8d505cb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
Expand Up @@ -30,6 +30,7 @@
import com.bgsoftware.superiorskyblock.utils.StringUtils;
import com.bgsoftware.superiorskyblock.utils.islands.IslandUtils;
import com.bgsoftware.superiorskyblock.utils.items.ItemUtils;
import com.bgsoftware.superiorskyblock.utils.locations.SmartLocation;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
Expand Down Expand Up @@ -268,6 +269,13 @@ public static void deserializeWarps(DatabaseBridge databaseBridge, DatabaseCache
return;
}

if (location.get().getWorld() == null) {
SuperiorSkyblockPlugin.log(
String.format("&cCannot load warps with invalid world %s for %s, skipping...",
((SmartLocation) location.get()).getWorldName(), uuid.get()));
return;
}

CachedWarpInfo cachedWarpInfo = new CachedWarpInfo();
cachedWarpInfo.name = name.get();
cachedWarpInfo.category = islandWarp.getString("category").orElse("");
Expand Down Expand Up @@ -403,10 +411,17 @@ public static void deserializeMissions(DatabaseBridge databaseBridge, DatabaseCa
return;
}

Optional<Mission<?>> mission = missions.getString("name").map(plugin.getMissions()::getMission);
Optional<String> missionName = missions.getString("name");
Optional<Mission<?>> mission = missionName.map(plugin.getMissions()::getMission);
if (!mission.isPresent()) {
SuperiorSkyblockPlugin.log(
String.format("&cCannot load island missions with invalid missions for %s, skipping...", uuid.get()));
if (!missionName.isPresent()) {
SuperiorSkyblockPlugin.log(
String.format("&cCannot load island missions with invalid missions for %s, skipping...", uuid.get()));
} else {
SuperiorSkyblockPlugin.log(
String.format("&cCannot load island missions with invalid mission %s for %s, skipping...",
missionName.get(), uuid.get()));
}
return;
}

Expand Down Expand Up @@ -520,6 +535,13 @@ public static void deserializeIslandHomes(DatabaseBridge databaseBridge, Databas
return;
}

if (location.get().getWorld() == null) {
SuperiorSkyblockPlugin.log(
String.format("&cCannot load island homes with invalid world %s for %s, skipping...",
((SmartLocation) location.get()).getWorldName(), uuid.get()));
return;
}

CachedIslandInfo cachedIslandInfo = databaseCache.computeIfAbsentInfo(uuid.get(), CachedIslandInfo::new);
cachedIslandInfo.islandHomes[environment.get()] = location.get();
});
Expand Down Expand Up @@ -550,6 +572,13 @@ public static void deserializeVisitorHomes(DatabaseBridge databaseBridge, Databa
return;
}

if (location.get().getWorld() == null) {
SuperiorSkyblockPlugin.log(
String.format("&cCannot load island homes with invalid world %s for %s, skipping...",
((SmartLocation) location.get()).getWorldName(), uuid.get()));
return;
}

CachedIslandInfo cachedIslandInfo = databaseCache.computeIfAbsentInfo(uuid.get(), CachedIslandInfo::new);
cachedIslandInfo.visitorHomes[environment.get()] = location.get();
});
Expand Down
Expand Up @@ -59,6 +59,7 @@
import com.bgsoftware.superiorskyblock.utils.islands.IslandUtils;
import com.bgsoftware.superiorskyblock.utils.islands.SortingComparators;
import com.bgsoftware.superiorskyblock.utils.islands.SortingTypes;
import com.bgsoftware.superiorskyblock.utils.locations.SmartLocation;
import com.bgsoftware.superiorskyblock.world.chunks.ChunkPosition;
import com.bgsoftware.superiorskyblock.world.chunks.ChunksTracker;
import com.bgsoftware.superiorskyblock.wrappers.SBlockPosition;
Expand Down Expand Up @@ -254,6 +255,13 @@ public static Optional<Island> fromDatabase(DatabaseCache<CachedIslandInfo> cach
return Optional.empty();
}

if (center.get().getWorld() == null) {
SuperiorSkyblockPlugin.log(
String.format("&cCannot load island invalid world %s for %s, skipping...",
((SmartLocation) center.get()).getWorldName(), uuid.get()));
return Optional.empty();
}

PluginDebugger.debug("Action: Load Island, UUID: " + uuid.get() + ", Owner: " + owner.get().getUniqueId());

SIsland island = new SIsland(
Expand Down
Expand Up @@ -31,4 +31,8 @@ public void setWorld(World world) {
worldName = null;
}

public String getWorldName() {
return worldName;
}

}
Expand Up @@ -5,14 +5,13 @@
import com.bgsoftware.superiorskyblock.api.data.DatabaseBridgeMode;
import com.bgsoftware.superiorskyblock.api.handlers.StackedBlocksManager;
import com.bgsoftware.superiorskyblock.api.key.Key;
import com.bgsoftware.superiorskyblock.api.wrappers.BlockPosition;
import com.bgsoftware.superiorskyblock.database.DatabaseResult;
import com.bgsoftware.superiorskyblock.database.bridge.StackedBlocksDatabaseBridge;
import com.bgsoftware.superiorskyblock.handler.AbstractHandler;
import com.bgsoftware.superiorskyblock.utils.debug.PluginDebugger;
import com.bgsoftware.superiorskyblock.world.chunks.ChunkPosition;
import com.bgsoftware.superiorskyblock.threads.Executor;
import com.bgsoftware.superiorskyblock.utils.debug.PluginDebugger;
import com.bgsoftware.superiorskyblock.world.blocks.stacked.container.StackedBlocksContainer;
import com.bgsoftware.superiorskyblock.world.chunks.ChunkPosition;
import com.bgsoftware.superiorskyblock.wrappers.SBlockPosition;
import com.google.common.base.Preconditions;
import org.bukkit.Chunk;
Expand Down Expand Up @@ -260,12 +259,18 @@ public void saveStackedBlocks() {
}

private void loadStackedBlock(DatabaseResult resultSet) {
Optional<BlockPosition> location = resultSet.getString("location").map(SBlockPosition::of);
Optional<SBlockPosition> location = resultSet.getString("location").map(SBlockPosition::of);
if (!location.isPresent()) {
SuperiorSkyblockPlugin.log("&cCannot load stacked block from null location, skipping...");
return;
}

if (location.get().getWorld() == null) {
SuperiorSkyblockPlugin.log(String.format("&cCannot load stacked block with invalid world %s, skipping...",
location.get().getWorldName()));
return;
}

Optional<Integer> amount = resultSet.getInt("amount");
if (!amount.isPresent()) {
SuperiorSkyblockPlugin.log("&cCannot load stacked block from null amount, skipping...");
Expand Down

0 comments on commit 8d505cb

Please sign in to comment.