Skip to content

Commit

Permalink
Merge branch 'master' into spawn-support
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG authored May 10, 2024
2 parents b19c7e5 + c5a275d commit 23b0df3
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void setColor(Color color) {
if (super.getName() != null) return super.getName();
String ownerName = getOwner()
.map(User::getName)
.orElse("N/A");
.orElse(IridiumSkyblock.getInstance().getMessages().nullPlaceholder);
return IridiumSkyblock.getInstance().getConfiguration().defaultIslandName.replace("%owner%", ownerName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
import com.iridium.iridiumteams.Rank;
import com.iridium.iridiumteams.TemporaryCache;
import com.iridium.iridiumteams.bank.BankItem;
import com.iridium.iridiumteams.database.TeamEnhancement;
import com.iridium.iridiumteams.enhancements.Enhancement;
import com.iridium.iridiumteams.enhancements.EnhancementType;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import java.time.Duration;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

public class IslandPlaceholderBuilder implements PlaceholderBuilder<Island> {
Expand All @@ -28,73 +30,124 @@ public class IslandPlaceholderBuilder implements PlaceholderBuilder<Island> {
public List<Placeholder> getPlaceholders(Island island) {
return cache.get(island, Duration.ofSeconds(1), () -> {
List<User> users = IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island);
List<String> onlineUsers = users.stream()
.filter(u -> u.getPlayer() != null)
.map(User::getName)
.collect(Collectors.toList());
List<String> offlineUsers = users.stream()
.filter(u -> u.getPlayer() == null)
.map(User::getName)
.collect(Collectors.toList());

List<String> onlineUsers = new ArrayList<>(Collections.emptyList());
List<String> offlineUsers = new ArrayList<>(Collections.emptyList());

for (User user : users) {
if (user.getPlayer() != null) {
onlineUsers.add(user.getName());
} else {
offlineUsers.add(user.getName());
}
}

List<Placeholder> placeholderList = new ArrayList<>(Arrays.asList(
new Placeholder("island_name", island.getName()),
new Placeholder("island_owner", IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island).stream()
new Placeholder("island_name", island::getName),
new Placeholder("island_owner", () -> IridiumSkyblock.getInstance().getTeamManager().getTeamMembers(island).stream()
.filter(user -> user.getUserRank() == Rank.OWNER.getId())
.findFirst()
.map(User::getName)
.orElse("N/A")),
new Placeholder("island_create", island.getCreateTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))),
new Placeholder("island_description", island.getDescription()),
new Placeholder("island_value", String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamValue(island))),
new Placeholder("island_level", String.valueOf(island.getLevel())),
new Placeholder("island_experience", String.valueOf(island.getExperience())),
new Placeholder("island_value_rank", String.valueOf(IridiumSkyblock.getInstance().getTop().valueTeamSort.getRank(island, IridiumSkyblock.getInstance()))),
new Placeholder("island_experience_rank", String.valueOf(IridiumSkyblock.getInstance().getTop().experienceTeamSort.getRank(island, IridiumSkyblock.getInstance()))),
new Placeholder("island_members_online", String.join(", ", onlineUsers)),
new Placeholder("island_members_online_count", String.valueOf(onlineUsers.size())),
new Placeholder("island_members_offline", String.join(", ", offlineUsers)),
new Placeholder("island_members_offline_count", String.valueOf(offlineUsers.size())),
new Placeholder("island_members_count", String.valueOf(users.size()))
.orElse(IridiumSkyblock.getInstance().getMessages().nullPlaceholder)),
new Placeholder("island_create", () -> island.getCreateTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))),
new Placeholder("island_description", island::getDescription),
new Placeholder("island_value", () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamValue(island))),
new Placeholder("island_level", () -> String.valueOf(island.getLevel())),
new Placeholder("island_experience", () -> String.valueOf(island.getExperience())),
new Placeholder("island_value_rank", () -> String.valueOf(IridiumSkyblock.getInstance().getTop().valueTeamSort.getRank(island, IridiumSkyblock.getInstance()))),
new Placeholder("island_experience_rank", () -> String.valueOf(IridiumSkyblock.getInstance().getTop().experienceTeamSort.getRank(island, IridiumSkyblock.getInstance()))),
new Placeholder("island_members_online", () -> String.join(", ", onlineUsers)),
new Placeholder("island_members_online_count", () -> String.valueOf(onlineUsers.size())),
new Placeholder("island_members_offline", () -> String.join(", ", offlineUsers)),
new Placeholder("island_members_offline_count", () -> String.valueOf(offlineUsers.size())),
new Placeholder("island_members_count", () -> String.valueOf(users.size()))
));

List<Player> visitingPlayers = Bukkit.getOnlinePlayers().stream()
.map(Player::getPlayer)
.filter(Objects::nonNull)
.filter(player -> island.isInIsland(player.getLocation()))
.collect(Collectors.toList());

visitingPlayers.removeIf(player -> onlineUsers.contains(player.getName()));

placeholderList.add(new Placeholder("island_visitors", () -> visitingPlayers.stream().map(Player::getName).collect(Collectors.joining(", "))));
placeholderList.add(new Placeholder("island_visitors_amount", () -> String.valueOf(visitingPlayers.size())));

placeholderList.add(new Placeholder("island_visitors", () -> visitingPlayers.stream().map(Player::getName).collect(Collectors.joining(", "))));
placeholderList.add(new Placeholder("island_visitors_amount", () -> String.valueOf(visitingPlayers.size())));

for (Map.Entry<String, Enhancement<?>> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) {
if (!enhancement.getValue().enabled) continue;
TeamEnhancement teamEnhancement = IridiumSkyblock.getInstance().getIslandManager().getTeamEnhancement(island, enhancement.getKey());

placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_active", () -> String.valueOf(teamEnhancement.isActive())));
placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_level", () -> String.valueOf(teamEnhancement.getLevel())));
placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_time_hours", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() % 60), 0))));
placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_time_minutes", () -> String.valueOf(Math.max((int) ((teamEnhancement.getRemainingTime() % 3600) / 60), 0))));
placeholderList.add(new Placeholder("island_enhancement_" + enhancement.getKey() + "_time_seconds", () -> String.valueOf(Math.max((int) (teamEnhancement.getRemainingTime() / 3600), 0))));
}

for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) {
placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island, bankItem.getName()).getNumber())));
placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBank(island, bankItem.getName()).getNumber())));
}
for (XMaterial xMaterial : XMaterial.values()) {
placeholderList.add(new Placeholder("island_" + xMaterial.name().toLowerCase() + "_amount", String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBlock(island, xMaterial).getAmount())));
placeholderList.add(new Placeholder("island_" + xMaterial.name().toLowerCase() + "_amount", () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamBlock(island, xMaterial).getAmount())));
}
for (EntityType entityType : EntityType.values()) {
placeholderList.add(new Placeholder("island_" + entityType.name().toLowerCase() + "_amount", String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamSpawners(island, entityType).getAmount())));
placeholderList.add(new Placeholder("island_" + entityType.name().toLowerCase() + "_amount", () -> String.valueOf(IridiumSkyblock.getInstance().getTeamManager().getTeamSpawners(island, entityType).getAmount())));
}
return placeholderList;
});
}

private List<Placeholder> initializeDefaultPlaceholders() {

List<Placeholder> placeholderList = new ArrayList<>(Arrays.asList(
new Placeholder("island_name", "N/A"),
new Placeholder("island_owner", "N/A"),
new Placeholder("island_description", "N/A"),
new Placeholder("island_create", "N/A"),
new Placeholder("island_value", "N/A"),
new Placeholder("island_level", "N/A"),
new Placeholder("island_experience", "N/A"),
new Placeholder("island_value_rank", "N/A"),
new Placeholder("island_experience_rank", "N/A"),
new Placeholder("island_members_online", "N/A"),
new Placeholder("island_members_online_count", "N/A"),
new Placeholder("island_members_offline", "N/A"),
new Placeholder("island_members_offline_count", "N/A"),
new Placeholder("island_members_count", "N/A")
new Placeholder("island_name", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_owner", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_description", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_create", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_value", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_level", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_experience", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_value_rank", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_experience_rank", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_members_online", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_members_online_count", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_members_offline", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_members_offline_count", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_members_count", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_visitors", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("island_visitors_amount", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)
));

for (Map.Entry<String, Enhancement<?>> enhancement : IridiumSkyblock.getInstance().getEnhancementList().entrySet()) {
if (enhancement.getValue().type == EnhancementType.BOOSTER) {
placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_active", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_level", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_hours", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_minutes", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
placeholderList.add(new Placeholder("island_booster_" + enhancement.getKey() + "_time_seconds", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
}

if (enhancement.getValue().type == EnhancementType.UPGRADE) {
placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_active", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_level", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_hours", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_minutes", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
placeholderList.add(new Placeholder("island_upgrade_" + enhancement.getKey() + "_time_seconds", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
}
}

for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) {
placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), "N/A"));
placeholderList.add(new Placeholder("island_bank_" + bankItem.getName().toLowerCase(), IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
}
for (XMaterial xMaterial : XMaterial.values()) {
placeholderList.add(new Placeholder("island_" + xMaterial.name().toLowerCase() + "_amount", "N/A"));
placeholderList.add(new Placeholder("island_" + xMaterial.name().toLowerCase() + "_amount", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
}
for (EntityType entityType : EntityType.values()) {
placeholderList.add(new Placeholder("island_" + entityType.name().toLowerCase() + "_amount", "N/A"));
placeholderList.add(new Placeholder("island_" + entityType.name().toLowerCase() + "_amount", IridiumSkyblock.getInstance().getMessages().nullPlaceholder));
}
return placeholderList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
public class UserPlaceholderBuilder implements PlaceholderBuilder<User> {
private final TemporaryCache<User, List<Placeholder>> cache = new TemporaryCache<>();
private final List<Placeholder> defaultPlaceholders = Arrays.asList(
new Placeholder("player_rank", "N/A"),
new Placeholder("player_name", "N/A"),
new Placeholder("player_join", "N/A")
new Placeholder("player_rank", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("player_name", IridiumSkyblock.getInstance().getMessages().nullPlaceholder),
new Placeholder("player_join", IridiumSkyblock.getInstance().getMessages().nullPlaceholder)
);

@Override
public List<Placeholder> getPlaceholders(User user) {
return cache.get(user, Duration.ofSeconds(1), () -> Arrays.asList(
new Placeholder("player_rank", IridiumSkyblock.getInstance().getUserRanks().getOrDefault(user.getUserRank(), new UserRank("N/A", null)).name),
new Placeholder("player_rank", IridiumSkyblock.getInstance().getUserRanks().getOrDefault(user.getUserRank(), new UserRank(IridiumSkyblock.getInstance().getMessages().nullPlaceholder, null)).name),
new Placeholder("player_name", user.getName()),
new Placeholder("player_join", user.getJoinTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat)))
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public void paste(File file, Location location, Boolean ignoreAirBlock, Completa
int width = clipboard.getDimensions().getBlockX();
int height = clipboard.getDimensions().getBlockY();
int length = clipboard.getDimensions().getBlockZ();
location.subtract(width / 2.00, height / 2.00, length / 2.00); // Centers the schematic

int newLength = (int) (length / 2.00);
int newWidth = (int) (width / 2.00);
int newHeight = (int) (height / 2.00);

location.subtract(newWidth, newHeight, newLength); //Center the schematic (for real this time)

clipboard.setOrigin(clipboard.getRegion().getMinimumPoint()); // Change the //copy point to the minimum
// corner
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public void paste(File file, Location location, Boolean ignoreAirBlock, Completa
short width = schematicData.width;
short height = schematicData.height;

location.subtract(width / 2.00, height / 2.00, length / 2.00); // Centers the schematic
int newLength = (int) (length / 2.00);
int newWidth = (int) (width / 2.00);
int newHeight = (int) (height / 2.00);

location.subtract(newWidth, newHeight, newLength); //Center the schematic (for real this time)

BukkitRunnable runnable = new BukkitRunnable() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ public void paste(File file, Location location, Boolean ignoreAirBlock, Completa
ClipboardFormat format = cachedClipboardFormat.getOrDefault(file, ClipboardFormats.findByFile(file));
ClipboardReader reader = format.getReader(new FileInputStream(file));
Clipboard clipboard = reader.read();

int width = clipboard.getDimensions().getBlockX();
int height = clipboard.getDimensions().getBlockY();
int length = clipboard.getDimensions().getBlockZ();
location.subtract(width / 2.00, height / 2.00, length / 2.00); // Centers the schematic

int newLength = (int) (length / 2.00);
int newWidth = (int) (width / 2.00);
int newHeight = (int) (height / 2.00);

location.subtract(newWidth, newHeight, newLength); //Center the schematic (for real this time)

clipboard.setOrigin(clipboard.getRegion().getMinimumPoint()); // Change the //copy point to the minimum corner
try (EditSession editSession = com.sk89q.worldedit.WorldEdit.getInstance().newEditSession(new BukkitWorld(location.getWorld()))) {
Operation operation = new ClipboardHolder(clipboard)
Expand Down

0 comments on commit 23b0df3

Please sign in to comment.