Search in sources :

Example 46 with ItemMap

use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.

the class Menu method usePane.

/**
 * Opens the Pane for the Player.
 * This Pane is for setting the use-cooldown.
 *
 * @param player - The Player to have the Pane opened.
 * @param itemMap - The ItemMap currently being modified.
 */
private static void usePane(final Player player, final ItemMap itemMap) {
    Interface usePane = new Interface(true, 6, GUIName, player);
    SchedulerUtils.runAsync(() -> {
        usePane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the item definition menu."), event -> {
            creatingPane(player, itemMap);
        }));
        usePane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "YELLOW_STAINED_GLASS_PANE" : "STAINED_GLASS_PANE:4"), 1, false, "&e&lCustom Usage", "&7", "&7*Click to set a custom usage cooldown", "&7value for the item."), event -> {
            player.closeInventory();
            String[] placeHolders = LanguageAPI.getLang(false).newString();
            placeHolders[16] = "USAGE COOLDOWN";
            placeHolders[15] = "120";
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputType", player, placeHolders);
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputExample", player, placeHolders);
        }, event -> {
            if (StringUtils.isInt(ChatColor.stripColor(event.getMessage()))) {
                itemMap.setInteractCooldown(Integer.parseInt(ChatColor.stripColor(event.getMessage())));
                String[] placeHolders = LanguageAPI.getLang(false).newString();
                placeHolders[16] = "USAGE COOLDOWN";
                LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputSet", player, placeHolders);
            } else {
                String[] placeHolders = LanguageAPI.getLang(false).newString();
                placeHolders[16] = ChatColor.stripColor(event.getMessage());
                LanguageAPI.getLang(false).sendLangMessage("commands.menu.noInteger", player, placeHolders);
            }
            creatingPane(event.getPlayer(), itemMap);
        }));
        for (int i = 1; i <= 64; i++) {
            final int k = i;
            usePane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "BLUE_STAINED_GLASS_PANE" : "STAINED_GLASS_PANE:11"), k, false, "&9&lDuration: &a&l" + k + " Second(s)", "&7", "&7*Click to set the", "&7use-cooldown of the item."), event -> {
                itemMap.setInteractCooldown(k);
                creatingPane(player, itemMap);
            }));
        }
    });
    usePane.open(player);
}
Also used : ItemHandler(me.RockinChaos.itemjoin.handlers.ItemHandler) PatternType(org.bukkit.block.banner.PatternType) Enchantment(org.bukkit.enchantments.Enchantment) GameProfile(com.mojang.authlib.GameProfile) Player(org.bukkit.entity.Player) LanguageAPI(me.RockinChaos.itemjoin.utils.api.LanguageAPI) Inventory(org.bukkit.inventory.Inventory) DependAPI(me.RockinChaos.itemjoin.utils.api.DependAPI) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) Material(org.bukkit.Material) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) Bukkit(org.bukkit.Bukkit) Action(me.RockinChaos.itemjoin.item.ItemCommand.Action) CommandSender(org.bukkit.command.CommandSender) UUID(java.util.UUID) Sound(org.bukkit.Sound) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) EntityType(org.bukkit.entity.EntityType) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) ItemUtilities(me.RockinChaos.itemjoin.item.ItemUtilities) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) SchedulerUtils(me.RockinChaos.itemjoin.utils.SchedulerUtils) StringUtils(me.RockinChaos.itemjoin.utils.StringUtils) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ItemJoin(me.RockinChaos.itemjoin.ItemJoin) PotionEffectType(org.bukkit.potion.PotionEffectType) Button(me.RockinChaos.itemjoin.utils.interfaces.Button) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Pattern(org.bukkit.block.banner.Pattern) BookMeta(org.bukkit.inventory.meta.BookMeta) Interface(me.RockinChaos.itemjoin.utils.interfaces.Interface) HashMap(java.util.HashMap) HeadDatabaseAPI(me.arcaniax.hdb.api.HeadDatabaseAPI) BannerMeta(org.bukkit.inventory.meta.BannerMeta) ServerUtils(me.RockinChaos.itemjoin.utils.ServerUtils) ArrayList(java.util.ArrayList) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Environment(org.bukkit.World.Environment) Property(com.mojang.authlib.properties.Property) ConfigHandler(me.RockinChaos.itemjoin.handlers.ConfigHandler) Color(org.bukkit.Color) Attribute(org.bukkit.attribute.Attribute) Type(org.bukkit.FireworkEffect.Type) PlayerHandler(me.RockinChaos.itemjoin.handlers.PlayerHandler) LegacyAPI(me.RockinChaos.itemjoin.utils.api.LegacyAPI) DecimalFormat(java.text.DecimalFormat) Field(java.lang.reflect.Field) File(java.io.File) PotionEffect(org.bukkit.potion.PotionEffect) CommandSequence(me.RockinChaos.itemjoin.item.ItemCommand.CommandSequence) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) Button(me.RockinChaos.itemjoin.utils.interfaces.Button) Interface(me.RockinChaos.itemjoin.utils.interfaces.Interface)

Example 47 with ItemMap

use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.

the class Menu method blocksPane.

/**
 * Opens the Pane for the Player.
 * This Pane is for setting the blocks drop chances.
 *
 * @param player - The Player to have the Pane opened.
 * @param itemMap - The ItemMap currently being modified.
 */
private static void blocksPane(final Player player, final ItemMap itemMap) {
    Interface blockPane = new Interface(true, 6, GUIName, player);
    SchedulerUtils.runAsync(() -> {
        blockPane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the drop chances menu."), event -> {
            dropsPane(player, itemMap);
        }));
        blockPane.addButton(new Button(ItemHandler.getItem("STICK", 1, true, "&b&lBukkit Material", "&7", "&7*If you know the name", "&7of the BUKKIT material type", "&7simply click and type it."), event -> {
            player.closeInventory();
            String[] placeHolders = LanguageAPI.getLang(false).newString();
            placeHolders[16] = "BUKKIT MATERIAL";
            placeHolders[15] = "IRON_SWORD";
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputType", player, placeHolders);
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputExample", player, placeHolders);
        }, event -> {
            if (ItemHandler.getMaterial(ChatColor.stripColor(event.getMessage()), null) != null) {
                String[] placeHolders = LanguageAPI.getLang(false).newString();
                placeHolders[16] = "BUKKIT MATERIAL";
                LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputSet", player, placeHolders);
                chancePane(player, itemMap, null, ItemHandler.getMaterial(ChatColor.stripColor(event.getMessage()), null));
            } else {
                String[] placeHolders = LanguageAPI.getLang(false).newString();
                placeHolders[16] = ChatColor.stripColor(event.getMessage());
                LanguageAPI.getLang(false).sendLangMessage("commands.menu.noMaterial", player, placeHolders);
                blocksPane(player, itemMap);
            }
        }));
        Inventory inventoryCheck = Bukkit.getServer().createInventory(null, 9, GUIName);
        for (Material material : Material.values()) {
            if (material.isBlock() && itemMap.getBlocksDrop().containsKey(material)) {
                if (!material.name().contains("LEGACY") && material.name() != "AIR" && safeMaterial(ItemHandler.getItem(material.toString(), 1, false, "", ""), inventoryCheck)) {
                    if (!ServerUtils.hasSpecificUpdate("1_13") && LegacyAPI.getDataValue(material) != 0) {
                        for (int i = 0; i <= LegacyAPI.getDataValue(material); i++) {
                            if (!material.toString().equalsIgnoreCase("STEP") || material.toString().equalsIgnoreCase("STEP") && i != 2) {
                                final int dataValue = i;
                                blockPane.addButton(new Button(ItemHandler.getItem(material.toString() + ":" + dataValue, 1, (itemMap.getBlocksDrop().containsKey(material)), "", "&7", "&7*Click to set the material.", (itemMap.getBlocksDrop().containsKey(material) ? "&9&lChance: &a" + itemMap.getBlocksDrop().get(material) : "")), event -> {
                                    if (itemMap.getBlocksDrop().containsKey(material)) {
                                        Map<Material, Double> blocksDrop = itemMap.getBlocksDrop();
                                        blocksDrop.remove(material);
                                        itemMap.setBlocksDrop(blocksDrop);
                                        blocksPane(player, itemMap);
                                    } else {
                                        chancePane(player, itemMap, null, material);
                                    }
                                }));
                            }
                        }
                    } else {
                        blockPane.addButton(new Button(ItemHandler.getItem(material.toString(), 1, (itemMap.getBlocksDrop().containsKey(material)), "", "&7", "&7*Click to set the material.", (itemMap.getBlocksDrop().containsKey(material) ? "&9&lChance: &a" + itemMap.getBlocksDrop().get(material) : "")), event -> {
                            if (itemMap.getBlocksDrop().containsKey(material)) {
                                Map<Material, Double> blocksDrop = itemMap.getBlocksDrop();
                                blocksDrop.remove(material);
                                itemMap.setBlocksDrop(blocksDrop);
                                blocksPane(player, itemMap);
                            } else {
                                chancePane(player, itemMap, null, material);
                            }
                        }));
                    }
                }
            }
        }
        for (Material material : Material.values()) {
            if (material.isBlock() && !itemMap.getBlocksDrop().containsKey(material)) {
                if (!material.name().contains("LEGACY") && material.name() != "AIR" && safeMaterial(ItemHandler.getItem(material.toString(), 1, false, "", ""), inventoryCheck)) {
                    if (!ServerUtils.hasSpecificUpdate("1_13") && LegacyAPI.getDataValue(material) != 0) {
                        for (int i = 0; i <= LegacyAPI.getDataValue(material); i++) {
                            if (!material.toString().equalsIgnoreCase("STEP") || material.toString().equalsIgnoreCase("STEP") && i != 2) {
                                final int dataValue = i;
                                blockPane.addButton(new Button(ItemHandler.getItem(material.toString() + ":" + dataValue, 1, (itemMap.getBlocksDrop().containsKey(material)), "", "&7", "&7*Click to set the material.", (itemMap.getBlocksDrop().containsKey(material) ? "&9&lChance: &a" + itemMap.getBlocksDrop().get(material) : "")), event -> {
                                    if (itemMap.getBlocksDrop().containsKey(material)) {
                                        Map<Material, Double> blocksDrop = itemMap.getBlocksDrop();
                                        blocksDrop.remove(material);
                                        itemMap.setBlocksDrop(blocksDrop);
                                        blocksPane(player, itemMap);
                                    } else {
                                        chancePane(player, itemMap, null, material);
                                    }
                                }));
                            }
                        }
                    } else {
                        blockPane.addButton(new Button(ItemHandler.getItem(material.toString(), 1, (itemMap.getBlocksDrop().containsKey(material)), "", "&7", "&7*Click to set the material.", (itemMap.getBlocksDrop().containsKey(material) ? "&9&lChance: &a" + itemMap.getBlocksDrop().get(material) : "")), event -> {
                            if (itemMap.getBlocksDrop().containsKey(material)) {
                                Map<Material, Double> blocksDrop = itemMap.getBlocksDrop();
                                blocksDrop.remove(material);
                                itemMap.setBlocksDrop(blocksDrop);
                                blocksPane(player, itemMap);
                            } else {
                                chancePane(player, itemMap, null, material);
                            }
                        }));
                    }
                }
            }
        }
        inventoryCheck.clear();
    });
    blockPane.open(player);
}
Also used : ItemHandler(me.RockinChaos.itemjoin.handlers.ItemHandler) PatternType(org.bukkit.block.banner.PatternType) Enchantment(org.bukkit.enchantments.Enchantment) GameProfile(com.mojang.authlib.GameProfile) Player(org.bukkit.entity.Player) LanguageAPI(me.RockinChaos.itemjoin.utils.api.LanguageAPI) Inventory(org.bukkit.inventory.Inventory) DependAPI(me.RockinChaos.itemjoin.utils.api.DependAPI) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) Material(org.bukkit.Material) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) Bukkit(org.bukkit.Bukkit) Action(me.RockinChaos.itemjoin.item.ItemCommand.Action) CommandSender(org.bukkit.command.CommandSender) UUID(java.util.UUID) Sound(org.bukkit.Sound) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) EntityType(org.bukkit.entity.EntityType) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) ItemUtilities(me.RockinChaos.itemjoin.item.ItemUtilities) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) SchedulerUtils(me.RockinChaos.itemjoin.utils.SchedulerUtils) StringUtils(me.RockinChaos.itemjoin.utils.StringUtils) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ItemJoin(me.RockinChaos.itemjoin.ItemJoin) PotionEffectType(org.bukkit.potion.PotionEffectType) Button(me.RockinChaos.itemjoin.utils.interfaces.Button) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Pattern(org.bukkit.block.banner.Pattern) BookMeta(org.bukkit.inventory.meta.BookMeta) Interface(me.RockinChaos.itemjoin.utils.interfaces.Interface) HashMap(java.util.HashMap) HeadDatabaseAPI(me.arcaniax.hdb.api.HeadDatabaseAPI) BannerMeta(org.bukkit.inventory.meta.BannerMeta) ServerUtils(me.RockinChaos.itemjoin.utils.ServerUtils) ArrayList(java.util.ArrayList) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Environment(org.bukkit.World.Environment) Property(com.mojang.authlib.properties.Property) ConfigHandler(me.RockinChaos.itemjoin.handlers.ConfigHandler) Color(org.bukkit.Color) Attribute(org.bukkit.attribute.Attribute) Type(org.bukkit.FireworkEffect.Type) PlayerHandler(me.RockinChaos.itemjoin.handlers.PlayerHandler) LegacyAPI(me.RockinChaos.itemjoin.utils.api.LegacyAPI) DecimalFormat(java.text.DecimalFormat) Field(java.lang.reflect.Field) File(java.io.File) PotionEffect(org.bukkit.potion.PotionEffect) CommandSequence(me.RockinChaos.itemjoin.item.ItemCommand.CommandSequence) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) Button(me.RockinChaos.itemjoin.utils.interfaces.Button) Material(org.bukkit.Material) Map(java.util.Map) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) HashMap(java.util.HashMap) Interface(me.RockinChaos.itemjoin.utils.interfaces.Interface) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory)

Example 48 with ItemMap

use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.

the class Commands method onInteract.

/**
 * Runs the commands upon physically interacting with the custom item.
 *
 * @param event - PlayerInteractEvent
 */
@EventHandler(ignoreCancelled = false)
private void onInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final ItemStack item = (event.getItem() != null ? event.getItem().clone() : (event.getAction() == Action.PHYSICAL ? PlayerHandler.getMainHandItem(player) : event.getItem()));
    final String action = event.getAction().name();
    if (((PlayerHandler.isAdventureMode(player) && !action.contains("LEFT") || !PlayerHandler.isAdventureMode(player))) && !this.isDropEvent(event.getPlayer())) {
        final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(PlayerHandler.getHandItem(player), null, player.getWorld());
        if (!PlayerHandler.isMenuClick(player.getOpenInventory(), event.getAction()) && itemMap != null && itemMap.isSimilar(item)) {
            long dupeDuration = (this.interactDupe != null && !this.interactDupe.isEmpty() && this.interactDupe.get(item) != null ? (((System.currentTimeMillis()) - this.interactDupe.get(item))) : -1);
            if (dupeDuration == -1 || dupeDuration > 30) {
                this.interactDupe.put(item, System.currentTimeMillis());
                this.runCommands(player, null, item, action, (event.getAction() == Action.PHYSICAL ? "INTERACTED" : action.split("_")[0]), String.valueOf(player.getInventory().getHeldItemSlot()));
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 49 with ItemMap

use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.

the class Consumes method onConsumeSkullEffects.

/**
 * Gives the players the defined custom items potion effects upon consuming a skull.
 *
 * @param event - PlayerInteractEvent.
 */
@EventHandler(ignoreCancelled = false)
private void onConsumeSkullEffects(PlayerInteractEvent event) {
    final ItemStack item = event.getItem();
    final Player player = event.getPlayer();
    final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(item, null, player.getWorld());
    if (itemMap != null && ItemHandler.isSkull(itemMap.getMaterial()) && itemMap.isCustomConsumable()) {
        if (itemMap.getPotionEffect() != null && !itemMap.getPotionEffect().isEmpty()) {
            for (PotionEffect potion : itemMap.getPotionEffect()) {
                player.addPotionEffect(potion);
            }
        }
        event.setCancelled(true);
        if (item.getAmount() > 1) {
            item.setAmount(item.getAmount() - 1);
        } else if (itemMap.isReal(PlayerHandler.getMainHandItem(player))) {
            PlayerHandler.setMainHandItem(player, new ItemStack(Material.AIR));
        } else if (itemMap.isReal(PlayerHandler.getOffHandItem(player))) {
            PlayerHandler.setOffHandItem(player, new ItemStack(Material.AIR));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 50 with ItemMap

use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.

the class Crafting method returnCrafting.

/**
 * Returns the custom crafting item to the player after the specified delay.
 *
 * @param player - the Player having their item returned.
 * @param contents - the crafting contents to be returned.
 * @param delay - the delay to wait before returning the item.
 */
private void returnCrafting(final Player player, final ItemStack[] contents, final long delay, final boolean slotZero) {
    SchedulerUtils.runLater(delay, () -> {
        if (!player.isOnline()) {
            return;
        } else if (!PlayerHandler.isCraftingInv(player.getOpenInventory())) {
            this.returnCrafting(player, contents, 10L, slotZero);
            return;
        }
        if (!slotZero) {
            for (int i = 4; i >= 0; i--) {
                final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(contents[i], null, player.getWorld());
                if (contents != null && contents[i] != null && itemMap != null) {
                    player.getOpenInventory().getTopInventory().setItem(i, contents[i]);
                    PlayerHandler.updateInventory(player, itemMap, 1L);
                }
            }
        } else {
            final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(contents[0], null, player.getWorld());
            if (contents != null && contents[0] != null && itemMap != null) {
                player.getOpenInventory().getTopInventory().setItem(0, contents[0]);
                PlayerHandler.updateInventory(player, ItemUtilities.getUtilities().getItemMap(contents[0], null, player.getWorld()), 1L);
            }
        }
    });
}
Also used : ItemMap(me.RockinChaos.itemjoin.item.ItemMap)

Aggregations

ItemMap (me.RockinChaos.itemjoin.item.ItemMap)140 Player (org.bukkit.entity.Player)124 ItemStack (org.bukkit.inventory.ItemStack)116 ArrayList (java.util.ArrayList)102 World (org.bukkit.World)96 PotionEffect (org.bukkit.potion.PotionEffect)95 HashMap (java.util.HashMap)94 List (java.util.List)94 ItemCommand (me.RockinChaos.itemjoin.item.ItemCommand)92 ChatColor (org.bukkit.ChatColor)92 Color (org.bukkit.Color)92 DyeColor (org.bukkit.DyeColor)92 Material (org.bukkit.Material)92 GameProfile (com.mojang.authlib.GameProfile)91 Property (com.mojang.authlib.properties.Property)91 File (java.io.File)91 Field (java.lang.reflect.Field)91 DecimalFormat (java.text.DecimalFormat)91 Map (java.util.Map)91 UUID (java.util.UUID)91