Search in sources :

Example 6 with User

use of com.iridium.iridiumskyblock.database.User 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)));
                }
            }
        }
    });
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) InventoryHolder(org.bukkit.inventory.InventoryHolder) EventHandler(org.bukkit.event.EventHandler)

Example 7 with User

use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.

the class PlayerInteractListener method onPlayerInteractEntity.

@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    Player player = event.getPlayer();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getRightClicked().getLocation());
    if (!island.isPresent())
        return;
    if (IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.INTERACT_ENTITIES)) {
        return;
    }
    event.setCancelled(true);
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotInteractEntities.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 8 with User

use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.

the class IslandMembersGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    members.clear();
    InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().membersGUI.background);
    AtomicInteger slot = new AtomicInteger(0);
    for (User user : getIsland().getMembers()) {
        int itemSlot = slot.getAndIncrement();
        inventory.setItem(itemSlot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().membersGUI.item, new PlaceholderBuilder().applyPlayerPlaceholders(user).applyIslandPlaceholders(getIsland()).build()));
        members.put(itemSlot, user);
    }
}
Also used : User(com.iridium.iridiumskyblock.database.User) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder)

Example 9 with User

use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.

the class IslandRanksGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    IslandRanksInventoryConfig islandRanks = IridiumSkyblock.getInstance().getInventories().islandRanksGUI;
    InventoryUtils.fillInventory(inventory, islandRanks.background);
    List<User> members = IridiumSkyblock.getInstance().getIslandManager().getIslandMembers(getIsland());
    inventory.setItem(islandRanks.owner.slot, ItemStackUtils.makeItem(islandRanks.owner, Collections.singletonList(new Placeholder("members", getIsland().getOwner().getName()))));
    inventory.setItem(islandRanks.coOwner.slot, ItemStackUtils.makeItem(islandRanks.coOwner, Collections.singletonList(new Placeholder("members", members.stream().filter(member -> member.getIslandRank().equals(IslandRank.CO_OWNER)).map(User::getName).collect(Collectors.joining(", "))))));
    inventory.setItem(islandRanks.moderator.slot, ItemStackUtils.makeItem(islandRanks.moderator, Collections.singletonList(new Placeholder("members", members.stream().filter(member -> member.getIslandRank().equals(IslandRank.MODERATOR)).map(User::getName).collect(Collectors.joining(", "))))));
    inventory.setItem(islandRanks.member.slot, ItemStackUtils.makeItem(islandRanks.member, Collections.singletonList(new Placeholder("members", members.stream().filter(member -> member.getIslandRank().equals(IslandRank.MEMBER)).map(User::getName).collect(Collectors.joining(", "))))));
    inventory.setItem(islandRanks.visitor.slot, ItemStackUtils.makeItem(islandRanks.visitor));
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : IslandRanksInventoryConfig(com.iridium.iridiumskyblock.configs.inventories.IslandRanksInventoryConfig) Placeholder(com.iridium.iridiumcore.utils.Placeholder) User(com.iridium.iridiumskyblock.database.User)

Example 10 with User

use of com.iridium.iridiumskyblock.database.User in project IridiumSkyblock by Iridium-Development.

the class IslandRegenGUI method selectSchematic.

/**
 * Executed when the player selects the Island schematic.
 *
 * @param schematicConfig The data of the selected schematic
 */
@Override
public void selectSchematic(Map.Entry<String, Schematics.SchematicConfig> schematicConfig) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    IslandRegenSettings regenSettings = IridiumSkyblock.getInstance().getConfiguration().regenSettings;
    if (island.isPresent()) {
        if (PlayerUtils.pay(player, island.get(), regenSettings.crystalPrice, regenSettings.moneyPrice)) {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().regeneratingIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            IridiumSkyblock.getInstance().getIslandManager().regenerateIsland(island.get(), user, schematicConfig.getValue());
            cooldownProvider.applyCooldown(player);
        } else {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    } else {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
}
Also used : User(com.iridium.iridiumskyblock.database.User) IslandRegenSettings(com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

User (com.iridium.iridiumskyblock.database.User)94 Island (com.iridium.iridiumskyblock.database.Island)73 Player (org.bukkit.entity.Player)66 OfflinePlayer (org.bukkit.OfflinePlayer)16 EventHandler (org.bukkit.event.EventHandler)16 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)13 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)12 List (java.util.List)12 Optional (java.util.Optional)11 Collectors (java.util.stream.Collectors)11 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)10 Duration (java.time.Duration)10 StringUtils (com.iridium.iridiumcore.utils.StringUtils)9 Collections (java.util.Collections)9 CommandSender (org.bukkit.command.CommandSender)9 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)6 BankItem (com.iridium.iridiumskyblock.bank.BankItem)5 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)5 IslandTrusted (com.iridium.iridiumskyblock.database.IslandTrusted)5 IslandWarp (com.iridium.iridiumskyblock.database.IslandWarp)5