use of com.iridium.iridiumskyblock.PlaceholderBuilder in project IridiumSkyblock by Iridium-Development.
the class ChatCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Chats with the sender's island members {@link Island}.
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
Optional<Island> island = IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (args.length > 1) {
String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
for (User user : island.get().getMembers()) {
Player recipient = Bukkit.getPlayer(user.getUuid());
if (recipient != null) {
recipient.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandMemberChat, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%message%", message)));
}
}
} else {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
UserChatToggleEvent userChatToggleEvent = new UserChatToggleEvent(user, !user.isIslandChat());
Bukkit.getPluginManager().callEvent(userChatToggleEvent);
if (userChatToggleEvent.isCancelled())
return false;
user.setIslandChat(!user.isIslandChat());
player.sendMessage(StringUtils.color((user.isIslandChat() ? IridiumSkyblock.getInstance().getMessages().islandChatEnabled : IridiumSkyblock.getInstance().getMessages().islandChatDisabled).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return true;
}
use of com.iridium.iridiumskyblock.PlaceholderBuilder in project IridiumSkyblock by Iridium-Development.
the class IslandInvitesGUI method addContent.
@Override
public void addContent(Inventory inventory) {
List<IslandInvite> islandInvites = IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().getEntries(getIsland());
inventory.clear();
InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
AtomicInteger slot = new AtomicInteger(0);
for (int i = 0; i < islandInvites.size(); i++) {
Bukkit.getScheduler().runTaskAsynchronously(IridiumSkyblock.getInstance(), () -> {
int itemSlot = slot.getAndIncrement();
List<Placeholder> placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(islandInvites.get(itemSlot).getUser()).applyIslandPlaceholders(getIsland()).build();
placeholderList.add(new Placeholder("inviter", islandInvites.get(itemSlot).getInviter().getName()));
placeholderList.add(new Placeholder("time", islandInvites.get(itemSlot).getTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))));
inventory.setItem(itemSlot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandInvitesGUI.item, placeholderList));
invites.put(itemSlot, islandInvites.get(itemSlot).getUser().getName());
});
}
if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
}
}
use of com.iridium.iridiumskyblock.PlaceholderBuilder in project IridiumSkyblock by Iridium-Development.
the class IslandLogsGUI method setItemStack.
public void setItemStack(Inventory inventory, Item item, int page, LogAction... logActions) {
ItemStack itemStack = ItemStackUtils.makeItem(item, new PlaceholderBuilder().applyIslandPlaceholders(getIsland()).build());
ItemMeta itemMeta = itemStack.getItemMeta();
List<String> lore = new ArrayList<>();
List<IslandLog> islandLogs = IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().getEntries(getIsland()).stream().filter(islandLog -> Arrays.stream(logActions).anyMatch(logAction -> logAction.equals(islandLog.getLogAction()))).sorted(Comparator.comparing(IslandLog::getTime).reversed()).collect(Collectors.toList());
int index = 0;
for (IslandLog islandLog : islandLogs) {
if ((page - 1) * 10 <= index && page * 10 > index) {
long time = (System.currentTimeMillis() - islandLog.getTime()) / 1000L;
int days = (int) TimeUnit.SECONDS.toDays(time);
int hours = (int) Math.floor(TimeUnit.SECONDS.toHours(time - days * 86400L));
int minutes = (int) Math.floor((time - (days * 86400) - (hours * 3600)) / 60.0D);
int seconds = (int) Math.floor((time - (days * 86400) - (hours * 3600)) % 60.0D);
lore.add(StringUtils.color(getLore(islandLog.getLogAction()).replace("%type%", islandLog.getData()).replace("%amount%", String.valueOf(islandLog.getAmount())).replace("%user%", islandLog.getUser().getName())).replace("%target%", islandLog.getTarget().getName()).replace("%seconds%", String.valueOf(seconds)).replace("%minutes%", String.valueOf(minutes)).replace("%hours%", String.valueOf(hours)).replace("%days%", String.valueOf(days)));
}
index++;
}
if (itemMeta.getLore() != null) {
lore.addAll(itemMeta.getLore());
}
int maxPage = (int) Math.ceil(islandLogs.size() / 10.00);
itemMeta.setLore(lore.stream().map(loreLine -> loreLine.replace("%current_page%", String.valueOf(page)).replace("%max_page%", String.valueOf(maxPage > 0 ? maxPage : 1))).collect(Collectors.toList()));
itemStack.setItemMeta(itemMeta);
inventory.setItem(item.slot, itemStack);
}
use of com.iridium.iridiumskyblock.PlaceholderBuilder in project IridiumSkyblock by Iridium-Development.
the class IslandTopGUI method addContent.
@Override
public void addContent(Inventory inventory) {
List<Island> islands = IridiumSkyblock.getInstance().getIslandManager().getIslands(IslandManager.SortType.VALUE);
islandSlots.clear();
inventory.clear();
InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().islandTopGUI.background);
for (int rank : IridiumSkyblock.getInstance().getConfiguration().islandTopSlots.keySet()) {
int slot = IridiumSkyblock.getInstance().getConfiguration().islandTopSlots.get(rank);
if (islands.size() >= rank) {
Island island = islands.get(rank - 1);
islandSlots.put(slot, island);
inventory.setItem(slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandTopGUI.item, new PlaceholderBuilder().applyIslandPlaceholders(island).build()));
} else {
inventory.setItem(slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandTopGUI.filler));
}
}
if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
}
}
use of com.iridium.iridiumskyblock.PlaceholderBuilder in project IridiumSkyblock by Iridium-Development.
the class IslandVisitorsGUI method addContent.
@Override
public void addContent(Inventory inventory) {
inventory.clear();
InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
inventory.setItem(inventory.getSize() - 3, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().nextPage));
inventory.setItem(inventory.getSize() - 7, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().previousPage));
final long elementsPerPage = inventory.getSize() - 9;
AtomicInteger slot = new AtomicInteger(0);
IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(getIsland()).stream().filter(user -> user.getIsland().map(Island::getId).orElse(0) != getIsland().getId()).skip((page - 1) * elementsPerPage).limit(elementsPerPage).forEachOrdered(user -> {
visitors.add(user);
List<Placeholder> placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(user).applyIslandPlaceholders(getIsland()).build();
inventory.setItem(slot.getAndIncrement(), ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().visitorsGUI.item, placeholderList));
});
}
Aggregations