use of com.iridium.iridiumskyblock.upgrades.UpgradeData in project IridiumSkyblock by Iridium-Development.
the class IslandUpgradesGUI method addContent.
@Override
public void addContent(Inventory inventory) {
inventory.clear();
InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().upgradesGUI.background);
for (Map.Entry<String, Upgrade<?>> upgrade : IridiumSkyblock.getInstance().getUpgradesList().entrySet()) {
Item item = upgrade.getValue().item;
int level = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(getIsland(), upgrade.getKey()).getLevel();
List<Placeholder> placeholderList = new ArrayList<>();
placeholderList.add(new Placeholder("level", String.valueOf(level)));
if (upgrade.getValue().upgrades.get(level) != null) {
UpgradeData upgradeData = upgrade.getValue().upgrades.get(level);
placeholderList.addAll(upgradeData.getPlaceholders());
}
if (upgrade.getValue().upgrades.get(level + 1) != null) {
UpgradeData upgradeData = upgrade.getValue().upgrades.get(level + 1);
placeholderList.add(new Placeholder("crystalscost", String.valueOf(upgradeData.crystals)));
placeholderList.add(new Placeholder("vaultcost", String.valueOf(upgradeData.money)));
} else if (!upgrade.getValue().upgrades.containsKey(level + 1)) {
placeholderList.add(new Placeholder("crystalscost", IridiumSkyblock.getInstance().getPlaceholders().crystalCost));
placeholderList.add(new Placeholder("vaultcost", IridiumSkyblock.getInstance().getPlaceholders().vaultCost));
}
inventory.setItem(item.slot, ItemStackUtils.makeItem(item, placeholderList));
}
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.upgrades.UpgradeData in project IridiumSkyblock by Iridium-Development.
the class UpgradesCommand 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 IslandUpgradesGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
return true;
}
String upgradeName = args[1];
Upgrade<?> upgrade = IridiumSkyblock.getInstance().getUpgradesList().get(upgradeName);
if (upgrade == null) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownUpgrade.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), upgradeName);
UpgradeData upgradeData = upgrade.upgrades.get(islandUpgrade.getLevel() + 1);
if (upgradeData == null) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().maxLevelReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (!PlayerUtils.pay(player, island.get(), upgradeData.crystals, upgradeData.money)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
islandUpgrade.setLevel(islandUpgrade.getLevel() + 1);
IslandLog islandLog = new IslandLog(island.get(), LogAction.UPGRADE_PURCHASE, user, null, 0, upgradeName);
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
IridiumSkyblock.getInstance().getIslandManager().sendIslandBorder(island.get());
island.get().resetCache();
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().successfullyBoughtUpgrade.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%upgrade%", upgrade.name).replace("%vault_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(upgradeData.money)).replace("%crystal_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(upgradeData.crystals))));
return true;
}
Aggregations