Skip to content

Commit

Permalink
Update IslandManager.java (#751)
Browse files Browse the repository at this point in the history
* Update IslandManager.java

updated the island manager to automagically skip the createGUI for the user if there is only 1 schematic to pick from

* Update IslandManager.java

fixed it cause the last one was bad (i forgor completableFuture spot)

* boop

* boop

---------

Co-authored-by: Peaches_MLG <[email protected]>
  • Loading branch information
sh0inx and PeachesMLG authored Oct 21, 2023
1 parent f87eb50 commit 2b2d870
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RegenCommand() {
@Override
public boolean execute(User user, Island island, String[] args, IridiumTeams<Island, User> iridiumTeams) {
Player player = user.getPlayer();
if (args.length == 0) {
if (args.length == 0 && IridiumSkyblock.getInstance().getSchematics().schematics.entrySet().size() > 1) {
if (!IridiumSkyblock.getInstance().getIslandManager().getTeamPermission(island, IridiumSkyblock.getInstance().getUserManager().getUser(player), "regen")) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotRegenIsland
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
Expand All @@ -36,7 +36,7 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams<Isl
}

Optional<String> schematic = IridiumSkyblock.getInstance().getSchematics().schematics.keySet().stream()
.filter(config -> config.equalsIgnoreCase(args[0]))
.filter(config -> IridiumSkyblock.getInstance().getSchematics().schematics.entrySet().size() == 1 || config.equalsIgnoreCase(args[0]))
.findFirst();
if (!schematic.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownSchematic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,23 @@ public List<Island> getTeams() {
return IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().getEntries();
}

private CompletableFuture<String> getSchematic(Player player) {
CompletableFuture<String> schematicNameCompletableFuture = new CompletableFuture<>();
if (IridiumSkyblock.getInstance().getSchematics().schematics.entrySet().size() == 1) {
for (Map.Entry<String, Schematics.SchematicConfig> entry : IridiumSkyblock.getInstance().getSchematics().schematics.entrySet()) {
schematicNameCompletableFuture.complete(entry.getKey());
return schematicNameCompletableFuture;
}
}

Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> player.openInventory(new CreateGUI(player.getOpenInventory().getTopInventory(), schematicNameCompletableFuture).getInventory()));
return schematicNameCompletableFuture;
}

@Override
public CompletableFuture<Island> createTeam(@NotNull Player owner, String name) {
CompletableFuture<String> schematicNameCompletableFuture = new CompletableFuture<>();
owner.openInventory(new CreateGUI(owner.getOpenInventory().getTopInventory(), schematicNameCompletableFuture).getInventory());
return CompletableFuture.supplyAsync(() -> {
String schematic = schematicNameCompletableFuture.join();
String schematic = getSchematic(owner).join();
if (schematic == null) return null;

User user = IridiumSkyblock.getInstance().getUserManager().getUser(owner);
Expand Down

0 comments on commit 2b2d870

Please sign in to comment.