Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Api bug and add standard getOwner/getMembers #811

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@
*/
public class IridiumSkyblockAPI {

private static final IridiumSkyblockAPI instance;
private static IridiumSkyblockAPI instance;
private final IridiumSkyblock iridiumSkyblock;

static {
instance = new IridiumSkyblockAPI(IridiumSkyblock.getInstance());
}

/**
* Constructor for api initialization.
*
Expand All @@ -47,7 +43,10 @@ private IridiumSkyblockAPI(@NotNull IridiumSkyblock iridiumSkyblock) {
* @return the instance of this api
* @since 3.0.0
*/
public static @NotNull IridiumSkyblockAPI getInstance() {
public static IridiumSkyblockAPI getInstance() {
boiscljo marked this conversation as resolved.
Show resolved Hide resolved
if(instance == null && IridiumSkyblock.getInstance() != null) {
instance = new IridiumSkyblockAPI(IridiumSkyblock.getInstance());
}
return instance;
}

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/iridium/iridiumskyblock/database/Island.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.jetbrains.annotations.NotNull;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@NoArgsConstructor
@Getter
Expand Down Expand Up @@ -132,11 +134,19 @@ public void setColor(Color color) {
@Override
public @NotNull String getName() {
if (super.getName() != null) return super.getName();
String ownerName = IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(this).stream()
.filter(user -> user.getUserRank() == Rank.OWNER.getId())
.findFirst()
String ownerName = getOwner()
.map(User::getName)
.orElse("N/A");
dlsf marked this conversation as resolved.
Show resolved Hide resolved
return IridiumSkyblock.getInstance().getConfiguration().defaultIslandName.replace("%owner%", ownerName);
}

public List<User> getMembers() {
return IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(this);
}

public Optional<User> getOwner() {
return getMembers().stream()
.filter(user -> user.getUserRank() == Rank.OWNER.getId())
.findFirst();
}
}
Loading