use of com.iridium.iridiumskyblock.database.IslandLog 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.database.IslandLog in project IridiumSkyblock by Iridium-Development.
the class PromoteCommand 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).
* Promotes a user in the Island rank system.
*
* @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) {
if (args.length != 2) {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
OfflinePlayer targetPlayer = Bukkit.getServer().getOfflinePlayer(args[1]);
User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
if (!island.get().equals(targetUser.getIsland().orElse(null))) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
IslandRank nextRank = IslandRank.getByLevel(targetUser.getIslandRank().getLevel() + 1);
if (nextRank == null || nextRank.getLevel() >= user.getIslandRank().getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.PROMOTE)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotPromoteUser.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
UserPromoteEvent userPromoteEvent = new UserPromoteEvent(island.get(), user, nextRank);
Bukkit.getPluginManager().callEvent(userPromoteEvent);
if (userPromoteEvent.isCancelled())
return false;
targetUser.setIslandRank(nextRank);
for (User member : island.get().getMembers()) {
Player islandMember = Bukkit.getPlayer(member.getUuid());
if (islandMember != null) {
if (islandMember.equals(player)) {
islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().promotedPlayer.replace("%player%", targetUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
} else {
islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userPromotedPlayer.replace("%promoter%", player.getName()).replace("%player%", targetUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
}
IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_PROMOTED, user, targetUser, 0, nextRank.getDisplayName());
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
return true;
}
use of com.iridium.iridiumskyblock.database.IslandLog in project IridiumSkyblock by Iridium-Development.
the class BoosterCommand 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).
* Shows an overview over the members of the Island and allows quick rank management.
*
* @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;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (args.length != 2) {
player.openInventory(new IslandBoostersGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
return true;
}
String boosterName = args[1];
Booster booster = IridiumSkyblock.getInstance().getBoosterList().get(boosterName);
if (booster == null) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownBooster.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island.get(), boosterName);
if (islandBooster.isActive() && !booster.stackable) {
return false;
}
if (!PlayerUtils.pay(player, island.get(), booster.crystalsCost, booster.vaultCost)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
islandBooster.setTime(LocalDateTime.now().plusSeconds(booster.time + (islandBooster.isActive() && booster.stackable ? islandBooster.getRemainingTime() : 0)));
IslandLog islandLog = new IslandLog(island.get(), LogAction.BOOSTER_PURCHASE, user, null, 0, boosterName);
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().successfullyBoughtBooster.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%booster%", IridiumSkyblock.getInstance().getBoosterList().get(islandBooster.getBooster()).name).replace("%vault_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(booster.vaultCost)).replace("%crystal_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(booster.crystalsCost))));
return true;
}
use of com.iridium.iridiumskyblock.database.IslandLog in project IridiumSkyblock by Iridium-Development.
the class Reward method claim.
/**
* Claims this reward for the provided user and island.
* Sets the experience, executes the commands and plays the sound.
*
* @param player The Player which should receive the reward
* @param island The Island of the Player
*/
public void claim(Player player, Island island) {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
island.setExperience(island.getTotalExperience() + islandExperience);
commands.forEach(command -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("%player%", player.getName())));
sound.play(player);
IslandBank islandCrystals = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
IslandBank islandExperience = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().experienceBankItem);
IslandBank islandMoney = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().moneyBankItem);
islandCrystals.setNumber(islandCrystals.getNumber() + crystals);
islandExperience.setNumber(islandExperience.getNumber() + experience);
islandMoney.setNumber(islandMoney.getNumber() + money);
IslandLog islandLog = new IslandLog(island, LogAction.REWARD_REDEEMED, user, null, 0, ChatColor.stripColor(item.displayName));
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
}
Aggregations