Skip to content

Commit

Permalink
Fixed IslandCreateEvent async issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG committed Sep 23, 2023
1 parent 82dee3e commit d8ffaaf
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public CompletableFuture<Island> createTeam(@NotNull Player owner, String name)
User user = IridiumSkyblock.getInstance().getUserManager().getUser(owner);
Schematics.SchematicConfig schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.get(schematic);

IslandCreateEvent islandCreateEvent = new IslandCreateEvent(user, name, schematicConfig);
Bukkit.getPluginManager().callEvent(islandCreateEvent);
IslandCreateEvent islandCreateEvent = getIslandCreateEvent(user, name, schematicConfig).join();
if (islandCreateEvent.isCancelled()) return null;

owner.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().creatingIsland
Expand All @@ -143,6 +142,17 @@ public CompletableFuture<Island> createTeam(@NotNull Player owner, String name)
});
}

private CompletableFuture<IslandCreateEvent> getIslandCreateEvent(@NotNull User user, @Nullable String islandName, Schematics.@NotNull SchematicConfig schematicConfig) {
CompletableFuture<IslandCreateEvent> completableFuture = new CompletableFuture<>();
Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> {
IslandCreateEvent islandCreateEvent = new IslandCreateEvent(user, islandName, schematicConfig);
Bukkit.getPluginManager().callEvent(islandCreateEvent);
completableFuture.complete(islandCreateEvent);

});
return completableFuture;
}

public CompletableFuture<Void> generateIsland(Island island, Schematics.SchematicConfig schematicConfig) {
return CompletableFuture.runAsync(() -> {
setHome(island, schematicConfig);
Expand Down Expand Up @@ -596,12 +606,12 @@ public void handleBlockPlaceOutsideTerritory(BlockPlaceEvent blockEvent) {

public void clearTeamInventory(Island island) {

if(IridiumSkyblock.getInstance().getConfiguration().clearInventoryOnRegen) {
if (IridiumSkyblock.getInstance().getConfiguration().clearInventoryOnRegen) {
IridiumSkyblock.getInstance().getIslandManager().getMembersOnIsland(island).forEach(member ->
member.getPlayer().getInventory().clear());
}

if(IridiumSkyblock.getInstance().getConfiguration().clearEnderChestOnRegen) {
if (IridiumSkyblock.getInstance().getConfiguration().clearEnderChestOnRegen) {
IridiumSkyblock.getInstance().getIslandManager().getMembersOnIsland(island).forEach(member ->
member.getPlayer().getEnderChest().clear());
}
Expand Down

0 comments on commit d8ffaaf

Please sign in to comment.