use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class VisitGUI method addContent.
@Override
public void addContent(Inventory inventory) {
inventory.clear();
InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().visitGUI.background);
inventory.setItem(inventory.getSize() - 3, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().nextPage));
inventory.setItem(inventory.getSize() - 7, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().previousPage));
int elementsPerPage = inventory.getSize() - 9;
List<Island> islands = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().getEntries().stream().filter(island -> viewer.isBypassing() || island.isVisitable()).skip((long) (page - 1) * elementsPerPage).limit(elementsPerPage).collect(Collectors.toList());
AtomicInteger slot = new AtomicInteger(0);
for (Island island : islands) {
inventory.setItem(slot.getAndIncrement(), ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().visitGUI.item, new PlaceholderBuilder().applyIslandPlaceholders(island).build()));
}
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class VisitGUI 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) {
List<Island> islands = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().getEntries().stream().filter(island -> viewer.isBypassing() || island.isVisitable()).collect(Collectors.toList());
if (event.getSlot() == getInventory().getSize() - 7) {
if (page > 1) {
event.getWhoClicked().openInventory(new VisitGUI(page - 1, viewer).getInventory());
}
} else if (event.getSlot() == getInventory().getSize() - 3) {
if ((event.getInventory().getSize() - 9) * page < islands.size()) {
event.getWhoClicked().openInventory(new VisitGUI(page + 1, viewer).getInventory());
}
} else if (event.getSlot() + 1 <= islands.size()) {
int index = ((event.getInventory().getSize() - 9) * (page - 1)) + event.getSlot();
if (islands.size() > index) {
Island island = islands.get(index);
IridiumSkyblock.getInstance().getCommands().visitCommand.execute(event.getWhoClicked(), new String[] { "", island.getOwner().getName() });
event.getWhoClicked().closeInventory();
}
}
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class ItemCraftListener method monitorItemCraft.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorItemCraft(CraftItemEvent event) {
if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getWhoClicked().getWorld()))
return;
int amount = event.isShiftClick() ? Arrays.stream(event.getInventory().getMatrix()).filter(Objects::nonNull).map(ItemStack::getAmount).sorted().findFirst().orElse(1) * event.getRecipe().getResult().getAmount() : event.getRecipe().getResult().getAmount();
Player player = (Player) event.getWhoClicked();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
XMaterial material = XMaterial.matchXMaterial(event.getRecipe().getResult().getType());
island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "CRAFT", material.name(), amount));
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class PlayerFishListener method monitorPlayerFish.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorPlayerFish(PlayerFishEvent event) {
if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getPlayer().getWorld()))
return;
Entity caughtEntity = event.getCaught();
if (caughtEntity == null || event.getState() != PlayerFishEvent.State.CAUGHT_FISH)
return;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
Optional<Island> island = user.getIsland();
island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "FISH", ((Item) caughtEntity).getItemStack().getType().name(), 1));
}
use of com.iridium.iridiumskyblock.database.Island in project IridiumSkyblock by Iridium-Development.
the class RemoveCommand 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).
*
* @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 < 4) {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> optionalIsland = user.getIsland();
if (!optionalIsland.isPresent()) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
double amount;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException exception) {
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Island island = optionalIsland.get();
island.setExtraValue(island.getExtraValue() - amount);
sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().extraValueSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%amount%", String.valueOf(island.getExtraValue()))));
return true;
}
Aggregations