Skip to content

Commit

Permalink
Fixed calling the factory for algorithms of players and islands is do…
Browse files Browse the repository at this point in the history
…ne before the objects are initialized, causing their uuid and names to be null
  • Loading branch information
OmerBenGera committed Sep 25, 2022
1 parent 60462ab commit 7460391
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/main/java/com/bgsoftware/superiorskyblock/island/SIsland.java
Expand Up @@ -129,11 +129,11 @@ public class SIsland implements Island {
private static final SuperiorSkyblockPlugin plugin = SuperiorSkyblockPlugin.getPlugin();
private static int blocksUpdateCounter = 0;

private final DatabaseBridge databaseBridge = plugin.getFactory().createDatabaseBridge(this);
private final IslandBank islandBank = plugin.getFactory().createIslandBank(this, this::hasGiveInterestFailed);
private final IslandCalculationAlgorithm calculationAlgorithm = plugin.getFactory().createIslandCalculationAlgorithm(this);
private final IslandBlocksTrackerAlgorithm blocksTracker = plugin.getFactory().createIslandBlocksTrackerAlgorithm(this);
private final IslandEntitiesTrackerAlgorithm entitiesTracker = plugin.getFactory().createIslandEntitiesTrackerAlgorithm(this);
private final DatabaseBridge databaseBridge;
private final IslandBank islandBank;
private final IslandCalculationAlgorithm calculationAlgorithm;
private final IslandBlocksTrackerAlgorithm blocksTracker;
private final IslandEntitiesTrackerAlgorithm entitiesTracker;
private final Synchronized<BukkitTask> bankInterestTask = Synchronized.of(null);
@Nullable
private PersistentDataContainer persistentDataContainer;
Expand Down Expand Up @@ -252,6 +252,12 @@ private SIsland(@Nullable SuperiorPlayer owner, UUID uuid, Location location, St
this.islandName = islandName;
this.islandRawName = Formatters.STRIP_COLOR_FORMATTER.format(islandName);
this.schemName = schemName;

this.databaseBridge = plugin.getFactory().createDatabaseBridge(this);
this.islandBank = plugin.getFactory().createIslandBank(this, this::hasGiveInterestFailed);
this.calculationAlgorithm = plugin.getFactory().createIslandCalculationAlgorithm(this);
this.blocksTracker = plugin.getFactory().createIslandBlocksTrackerAlgorithm(this);
this.entitiesTracker = plugin.getFactory().createIslandEntitiesTrackerAlgorithm(this);
}

public static Optional<Island> fromDatabase(DatabaseCache<CachedIslandInfo> cache, DatabaseResult resultSet) {
Expand Down
Expand Up @@ -51,8 +51,8 @@ public class SSuperiorPlayer implements SuperiorPlayer {

private static final SuperiorSkyblockPlugin plugin = SuperiorSkyblockPlugin.getPlugin();

private final DatabaseBridge databaseBridge = plugin.getFactory().createDatabaseBridge(this);
private final PlayerTeleportAlgorithm playerTeleportAlgorithm = plugin.getFactory().createPlayerTeleportAlgorithm(this);
private final DatabaseBridge databaseBridge;
private final PlayerTeleportAlgorithm playerTeleportAlgorithm;
@Nullable
private PersistentDataContainer persistentDataContainer; // Lazy loading

Expand Down Expand Up @@ -104,6 +104,10 @@ public SSuperiorPlayer(UUID uuid, @Nullable String name, PlayerRole playerRole,
this.playerRole = playerRole;
this.disbands = disbands;
this.userLocale = userLocale;

this.databaseBridge = plugin.getFactory().createDatabaseBridge(this);
this.playerTeleportAlgorithm = plugin.getFactory().createPlayerTeleportAlgorithm(this);

databaseBridge.setDatabaseBridgeMode(DatabaseBridgeMode.SAVE_DATA);
}

Expand Down

0 comments on commit 7460391

Please sign in to comment.