Skip to content

Commit

Permalink
Fixed islands making database update calls before they are inserted f…
Browse files Browse the repository at this point in the history
…irst
  • Loading branch information
OmerBenGera committed Aug 5, 2022
1 parent 80327e7 commit 3d59575
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Expand Up @@ -193,11 +193,14 @@ public void createIsland(SuperiorPlayer superiorPlayer, String schemName, BigDec

pendingCreationTasks.remove(superiorPlayer.getUniqueId());

island.getDatabaseBridge().setDatabaseBridgeMode(DatabaseBridgeMode.IDLE);
island.setBonusWorth(offset ? island.getRawWorth().negate() : bonusWorth);
island.setBonusLevel(offset ? island.getRawLevel().negate() : bonusLevel);
island.setBiome(biome);
island.setIslandHome(schematic.adjustRotation(islandLocation));

island.getDatabaseBridge().setDatabaseBridgeMode(DatabaseBridgeMode.SAVE_DATA);

IslandsDatabaseBridge.insertIsland(island);

BukkitExecutor.sync(() -> superiorPlayer.runIfOnline(player -> {
Expand Down
@@ -1,6 +1,7 @@
package com.bgsoftware.superiorskyblock.island.algorithm;

import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.data.DatabaseBridgeMode;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.schematic.Schematic;
import com.bgsoftware.superiorskyblock.api.world.algorithm.IslandCreationAlgorithm;
Expand Down Expand Up @@ -47,14 +48,18 @@ public CompletableFuture<IslandCreationResult> createIsland(UUID islandUUID, Sup
Island island = plugin.getFactory().createIsland(owner, islandUUID, islandLocation.add(0.5, 0, 0.5),
islandName, schematic.getName());

island.getDatabaseBridge().setDatabaseBridgeMode(DatabaseBridgeMode.IDLE);

EventResult<Boolean> event = plugin.getEventsBus().callIslandCreateEvent(owner, island, schematic.getName());

if (!event.isCancelled()) {
schematic.pasteSchematic(island, islandLocation.getBlock().getRelative(BlockFace.DOWN).getLocation(), () -> {
plugin.getProviders().getWorldsProvider().finishIslandCreation(islandLocation,
owner.getUniqueId(), islandUUID);
completableFuture.complete(new IslandCreationResult(island, islandLocation, event.getResult()));
island.getDatabaseBridge().setDatabaseBridgeMode(DatabaseBridgeMode.SAVE_DATA);
}, error -> {
island.getDatabaseBridge().setDatabaseBridgeMode(DatabaseBridgeMode.SAVE_DATA);
plugin.getProviders().getWorldsProvider().finishIslandCreation(islandLocation,
owner.getUniqueId(), islandUUID);
completableFuture.completeExceptionally(error);
Expand Down

0 comments on commit 3d59575

Please sign in to comment.