Skip to content

Commit

Permalink
Merge branch 'master' into ocean-generator-&-others
Browse files Browse the repository at this point in the history
  • Loading branch information
sh0inx authored Mar 16, 2024
2 parents 545e414 + 898bc8a commit 741577d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
implementation("org.jetbrains:annotations:24.1.0")
implementation("com.j256.ormlite:ormlite-core:6.1")
implementation("com.j256.ormlite:ormlite-jdbc:6.1")
implementation("com.iridium:IridiumTeams:2.3.7")
implementation("com.iridium:IridiumTeams:2.4.1")

// Other dependencies that are not required or already available at runtime
compileOnly("org.projectlombok:lombok:1.18.30")
Expand Down Expand Up @@ -88,6 +88,9 @@ tasks {
// Maven publishing
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
setGroupId("com.iridium")
setArtifactId("IridiumSkyblock")
setVersion(version)
artifact(tasks["shadowJar"])
}
}
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 @Nullable IridiumSkyblockAPI getInstance() {
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");
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void setIslandBiome(@NotNull Island island, @NotNull XBiome biome) {
World.Environment dimension = biome.getEnvironment();
World world = getWorld(dimension);

if(world == null) return;
if (world == null) return;

getIslandChunks(island).thenAccept(chunks -> {
Location pos1 = island.getPosition1(world);
Expand Down Expand Up @@ -221,8 +221,8 @@ 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);

if(schematicConfig.regenCost.money != 0 || !schematicConfig.regenCost.bankItems.isEmpty()) {
if(!IridiumSkyblock.getInstance().getSchematicManager().buy(owner, schematicConfig)) {
if (schematicConfig.regenCost.money != 0 || !schematicConfig.regenCost.bankItems.isEmpty()) {
if (!IridiumSkyblock.getInstance().getSchematicManager().buy(owner, schematicConfig)) {
return null;
}
}
Expand Down Expand Up @@ -536,9 +536,12 @@ public synchronized TeamBlock getTeamBlock(Island island, XMaterial xMaterial) {
}

@Override
public synchronized TeamSetting getTeamSetting(Island island, String settingKey) {
public synchronized @Nullable TeamSetting getTeamSetting(Island island, String settingKey) {
Setting settingConfig = IridiumSkyblock.getInstance().getSettingsList().get(settingKey);
String defaultValue = settingConfig == null ? "" : settingConfig.getDefaultValue();
if (settingConfig == null) {
return null;
}
String defaultValue = settingConfig.getDefaultValue();
Optional<TeamSetting> teamSetting = IridiumSkyblock.getInstance().getDatabaseManager().getTeamSettingsTableManager().getEntry(new TeamSetting(island, settingKey, defaultValue));
if (teamSetting.isPresent()) {
return teamSetting.get();
Expand Down Expand Up @@ -725,21 +728,28 @@ public void deleteTeamReward(TeamReward teamReward) {
}

public @Nullable World getWorld(World.Environment environment) {
String worldName = getWorldName(environment);
if (worldName == null) return null;
return Bukkit.getWorld(worldName);
}

public @Nullable String getWorldName(World.Environment environment) {
if (!IridiumSkyblock.getInstance().getConfiguration().enabledWorlds.getOrDefault(environment, true))
return null;
switch (environment) {
case NORMAL:
return Bukkit.getWorld(IridiumSkyblock.getInstance().getConfiguration().worldName);
return IridiumSkyblock.getInstance().getConfiguration().worldName;
case NETHER:
return Bukkit.getWorld(IridiumSkyblock.getInstance().getConfiguration().worldName + "_nether");
return IridiumSkyblock.getInstance().getConfiguration().worldName + "_nether";
case THE_END:
return Bukkit.getWorld(IridiumSkyblock.getInstance().getConfiguration().worldName + "_the_end");
return IridiumSkyblock.getInstance().getConfiguration().worldName + "_the_end";
}
return null;
}

public boolean isInSkyblockWorld(World world) {
return Objects.equals(world, getWorld(World.Environment.NORMAL)) || Objects.equals(world, getWorld(World.Environment.NETHER)) || Objects.equals(world, getWorld(World.Environment.THE_END));
if(world == null) return false;
return world.getName().equals(getWorldName(World.Environment.NORMAL)) || world.getName().equals(getWorldName(World.Environment.NETHER)) || world.getName().equals(getWorldName(World.Environment.THE_END));
}

public void sendIslandBorder(Player player) {
Expand Down

0 comments on commit 741577d

Please sign in to comment.