use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.
the class PlayerInteractListener method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
user.getIsland().ifPresent(island -> {
if (event.getAction() != Action.PHYSICAL) {
int islandCrystals = IridiumSkyblock.getInstance().getIslandManager().getIslandCrystals(event.getPlayer().getInventory().getItemInMainHand());
if (islandCrystals > 0) {
// Required because Spigot likes to trigger this event for each hand which removes two items
if (event.getHand() == EquipmentSlot.HAND) {
int amount = event.getPlayer().getInventory().getItemInMainHand().getAmount();
if (amount == 1) {
event.getPlayer().getInventory().setItemInMainHand(null);
} else {
event.getPlayer().getInventory().getItemInMainHand().setAmount(amount - 1);
}
IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
islandBank.setNumber(islandBank.getNumber() + islandCrystals);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankDeposited.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%type%", IridiumSkyblock.getInstance().getBankItems().crystalsBankItem.getDisplayName()).replace("%amount%", String.valueOf(islandCrystals))));
event.setCancelled(true);
}
}
}
});
if (event.getClickedBlock() == null)
return;
IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getClickedBlock().getLocation()).ifPresent(island -> {
XMaterial material = XMaterial.matchXMaterial(event.getClickedBlock().getType());
String materialName = material.name();
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.INTERACT)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotInteract.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return;
}
if (event.getAction() == Action.PHYSICAL && material == XMaterial.FARMLAND) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.TRAMPLE_CROPS)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTrampleCrops.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (materialName.contains("DOOR")) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.DOORS)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotOpenDoors.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (event.getClickedBlock().getState() instanceof InventoryHolder) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.OPEN_CONTAINERS)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotOpenContainers.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (redstoneMaterials.contains(material) || materialName.contains("BUTTON") || materialName.contains("PRESSURE_PLATE")) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.REDSTONE)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotUseRedstone.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
} else if (materialName.contains("MINECART") || materialName.contains("BOAT") || materialName.contains("EGG") || materialName.contains("BUCKET") || material == XMaterial.END_CRYSTAL || material == XMaterial.ARMOR_STAND) {
if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.INTERACT_ENTITIES)) {
event.setCancelled(true);
if (hasNoCooldown(player)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotSpawnEntities.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
}
});
}
use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.
the class IslandBankGUI method onInventoryClick.
/**
* Called when there is a click in this GUI.
* Cancelled automatically.
*
* @param event The InventoryClickEvent provided by Bukkit
*/
@Override
public void onInventoryClick(InventoryClickEvent event) {
Optional<BankItem> bankItemOptional = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getItem().slot == event.getSlot()).findFirst();
if (!bankItemOptional.isPresent())
return;
BankItem bankItem = bankItemOptional.get();
IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(getIsland(), bankItem);
switch(event.getClick()) {
case LEFT:
IridiumSkyblock.getInstance().getCommands().withdrawCommand.execute(event.getWhoClicked(), new String[] { "", bankItem.getName(), String.valueOf(bankItem.getDefaultAmount()) });
break;
case SHIFT_LEFT:
IridiumSkyblock.getInstance().getCommands().withdrawCommand.execute(event.getWhoClicked(), new String[] { "", bankItem.getName(), String.valueOf(islandBank.getNumber()) });
break;
case RIGHT:
IridiumSkyblock.getInstance().getCommands().depositCommand.execute(event.getWhoClicked(), new String[] { "", bankItem.getName(), String.valueOf(bankItem.getDefaultAmount()) });
break;
case SHIFT_RIGHT:
IridiumSkyblock.getInstance().getCommands().depositCommand.execute(event.getWhoClicked(), new String[] { "", bankItem.getName(), String.valueOf(islandBank.getNumber()) });
break;
}
addContent(event.getInventory());
}
use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.
the class IslandBankGUI method addContent.
@Override
public void addContent(Inventory inventory) {
inventory.clear();
InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
for (BankItem bankItem : IridiumSkyblock.getInstance().getBankItemList()) {
IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(getIsland(), bankItem);
inventory.setItem(bankItem.getItem().slot, ItemStackUtils.makeItem(bankItem.getItem(), Collections.singletonList(new Placeholder("amount", IridiumSkyblock.getInstance().getNumberFormatter().format(islandBank.getNumber())))));
}
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.database.IslandBank in project IridiumSkyblock by Iridium-Development.
the class RemoveCommand method execute.
@Override
public boolean execute(CommandSender sender, String[] args) {
if (args.length == 5) {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (island.isPresent()) {
Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[3])).findFirst();
if (bankItem.isPresent()) {
try {
IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), bankItem.get());
islandBank.setNumber(Math.max(islandBank.getNumber() - Double.parseDouble(args[4]), 0));
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().removedBank.replace("%player%", player.getName()).replace("%amount%", args[4]).replace("%item%", bankItem.get().getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return true;
} catch (NumberFormatException exception) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
} else {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
} else {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
} else {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return false;
}
use of com.iridium.iridiumskyblock.database.IslandBank in project IridiumSkyblock by Iridium-Development.
the class CrystalsBankItem method deposit.
/**
* Deposits the given amount of this item to the Player's bank.
*
* @param player The player who wants to deposit
* @param amount The amount which should be deposited
*/
@Override
public double deposit(Player player, Number amount) {
Optional<Island> islandOptional = IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland();
if (!islandOptional.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return 0;
}
int remainingItemAmount = amount.intValue();
int depositAmount = 0;
ItemStack[] contents = player.getInventory().getContents();
for (int i = 0; i < contents.length && remainingItemAmount > 0; i++) {
ItemStack itemStack = contents[i];
int crystalsPerItem = IridiumSkyblock.getInstance().getIslandManager().getIslandCrystals(itemStack);
if (crystalsPerItem == 0)
continue;
int itemStackAmount = itemStack.getAmount();
if (itemStackAmount <= remainingItemAmount) {
player.getInventory().setItem(i, null);
depositAmount += itemStackAmount * crystalsPerItem;
remainingItemAmount -= itemStackAmount;
} else {
itemStack.setAmount(itemStack.getAmount() - remainingItemAmount);
player.getInventory().setItem(i, itemStack);
depositAmount += remainingItemAmount * crystalsPerItem;
remainingItemAmount = 0;
}
}
if (depositAmount == 0) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().insufficientFundsToDeposit.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%type%", getDisplayName()));
return 0;
}
IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(islandOptional.get(), this);
islandBank.setNumber(islandBank.getNumber() + depositAmount);
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankDeposited.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)).replace("%amount%", String.valueOf(depositAmount)).replace("%type%", getDisplayName()));
return depositAmount;
}
Aggregations