Search in sources :

Example 96 with ItemMap

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

the class Projectile method onArrowHit.

/**
 * Teleports the Player to the custom arrow's landed position.
 *
 * @param event - ProjectileHitEvent
 */
@EventHandler(priority = EventPriority.NORMAL)
public void onArrowHit(ProjectileHitEvent event) {
    final org.bukkit.entity.Projectile projectile = event.getEntity();
    if (projectile instanceof Arrow && ((Arrow) projectile).getShooter() instanceof Player) {
        if (this.arrowList.get(projectile.getEntityId()) != null && !ItemUtilities.getUtilities().isAllowed((Player) ((Arrow) projectile).getShooter(), this.arrowList.get(projectile.getEntityId()), "teleport")) {
            final Player player = (Player) ((Arrow) projectile).getShooter();
            final Location location = ((Arrow) projectile).getLocation();
            final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(this.arrowList.get(projectile.getEntityId()), null, player.getWorld());
            location.setPitch(player.getLocation().getPitch());
            location.setYaw(player.getLocation().getYaw());
            player.teleport(location);
            if (itemMap.getTeleportEffect() != null) {
                try {
                    ((Arrow) projectile).getWorld().playEffect(((Arrow) projectile).getLocation(), Effect.valueOf(itemMap.getTeleportEffect()), 15);
                } catch (Exception e) {
                    ServerUtils.logSevere("The defined teleport-effect " + itemMap.getTeleportEffect() + " for the item " + itemMap.getConfigName() + " is not valid!");
                }
            }
            if (itemMap.getTeleportSound() != null && !itemMap.getTeleportSound().isEmpty()) {
                try {
                    ((Arrow) projectile).getWorld().playSound(((Arrow) projectile).getLocation(), Sound.valueOf(itemMap.getTeleportSound()), (float) ((double) itemMap.getTeleportVolume()), (float) ((double) itemMap.getTeleportPitch()));
                } catch (Exception e) {
                    ServerUtils.logSevere("The defined teleport-sound " + itemMap.getTeleportSound() + " for the item " + itemMap.getConfigName() + " is not valid!");
                }
            }
            projectile.remove();
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) Player(org.bukkit.entity.Player) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 97 with ItemMap

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

the class Projectile method onArrowFire.

/**
 * Refills the players arrows item to its original stack size when consuming the item.
 *
 * @param event - EntityShootBowEvent.
 */
@EventHandler(ignoreCancelled = true)
private void onArrowFire(EntityShootBowEvent event) {
    LivingEntity entity = event.getEntity();
    if (ServerUtils.hasSpecificUpdate("1_16") && entity instanceof Player && event.getBow() != null && event.getBow().getType() == Material.BOW) {
        ItemStack item = (event.getConsumable() != null ? event.getConsumable().clone() : event.getConsumable());
        Player player = (Player) event.getEntity();
        this.arrowList.put(event.getProjectile().getEntityId(), item);
        if (entity instanceof Player && !ItemUtilities.getUtilities().isAllowed(player, item, "count-lock")) {
            event.setConsumeItem(false);
            PlayerHandler.updateInventory(player, 1L);
        }
    } else if (entity instanceof Player) {
        HashMap<Integer, ItemStack> map = new HashMap<Integer, ItemStack>();
        Player player = (Player) event.getEntity();
        for (int i = 0; i < player.getInventory().getSize(); i++) {
            if (player.getInventory().getItem(i) != null && player.getInventory().getItem(i).getType() == Material.ARROW && event.getProjectile().getType().name().equalsIgnoreCase("ARROW")) {
                ItemStack cloneStack = player.getInventory().getItem(i).clone();
                ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(player.getInventory().getItem(i), null, player.getWorld());
                if (itemMap != null) {
                    cloneStack.setAmount(itemMap.getCount(player));
                }
                map.put(i, cloneStack);
            }
        }
        SchedulerUtils.runLater(2L, () -> {
            for (Integer key : map.keySet()) {
                if (player.getInventory().getItem(key) == null || player.getInventory().getItem(key).getAmount() != map.get(key).getAmount()) {
                    this.arrowList.put(event.getProjectile().getEntityId(), map.get(key));
                    if (!ItemUtilities.getUtilities().isAllowed(player, map.get(key), "count-lock")) {
                        player.getInventory().setItem(key, map.get(key));
                    }
                }
            }
            PlayerHandler.updateInventory(player, 1L);
        });
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) HashMap(java.util.HashMap) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 98 with ItemMap

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

the class Recipes method onPrepareRecipe.

/**
 * Called when the player tries to craft a recipe with a custom item.
 *
 * @param event - PrepareItemCraftEvent
 */
@EventHandler()
public void onPrepareRecipe(final PrepareItemCraftEvent event) {
    if (event.getRecipe() != null && event.getRecipe().getResult() != null && event.getRecipe().getResult().getType() != Material.AIR) {
        List<ItemMap> mapList = new ArrayList<ItemMap>();
        ItemMap checkMap = ItemUtilities.getUtilities().getItemMap(event.getRecipe().getResult(), null, event.getView().getPlayer().getWorld());
        if (checkMap != null) {
            mapList.add(checkMap);
        } else {
            return;
        }
        for (ItemMap itemMap : ItemUtilities.getUtilities().getItems()) {
            if (itemMap != null && itemMap.getIngredients() != null && !itemMap.getIngredients().isEmpty()) {
                mapList.add(itemMap);
            }
        }
        if (mapList != null && !mapList.isEmpty()) {
            boolean isBreak = false;
            for (ItemMap itemMap : mapList) {
                if (isBreak) {
                    break;
                }
                if (!itemMap.hasPermission((Player) event.getView().getPlayer(), event.getView().getPlayer().getWorld())) {
                    event.getInventory().setResult(new ItemStack(Material.AIR));
                } else {
                    boolean addRecipe = false;
                    int ingredientSize = 0;
                    int confirmations = 0;
                    for (Character character : itemMap.getRecipe()) {
                        if (character != 'X') {
                            ingredientSize += 1;
                        }
                    }
                    for (int i = 0; i < event.getInventory().getSize(); i++) {
                        final ItemStack item = event.getInventory().getItem(i + 1);
                        if (item != null) {
                            for (Character ingredient : itemMap.getIngredients().keySet()) {
                                ItemMap ingredMap = ItemUtilities.getUtilities().getItemMap(null, itemMap.getIngredients().get(ingredient), null);
                                if (itemMap.getRecipe().size() > i && itemMap.getRecipe().get(i) == ingredient) {
                                    if (((ingredMap == null && itemMap.getIngredients().get(ingredient).equalsIgnoreCase(item.getType().name())) || (ingredMap != null && ingredMap.isSimilar(item)))) {
                                        confirmations += 1;
                                        if (ingredMap != null) {
                                            addRecipe = true;
                                        }
                                    }
                                }
                            }
                        }
                        if (confirmations == ingredientSize && addRecipe) {
                            event.getInventory().setResult(itemMap.getItem((Player) event.getView().getPlayer()));
                            isBreak = true;
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : ItemMap(me.RockinChaos.itemjoin.item.ItemMap) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 99 with ItemMap

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

the class Stackable method onClickStackable.

/**
 * Stacks custom items with the Stackable itemflag defined.
 *
 * @param event - InventoryClickEvent
 */
@EventHandler(ignoreCancelled = true)
private void onClickStackable(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();
    if (event.getCurrentItem() != null && event.getCursor() != null && event.getCurrentItem().getType() != Material.AIR && event.getCursor().getType() != Material.AIR) {
        ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(event.getCursor(), null, player.getWorld());
        if (itemMap != null && itemMap.isSimilar(event.getCurrentItem()) && !ItemUtilities.getUtilities().isAllowed(player, event.getCursor(), "stackable")) {
            event.setCancelled(true);
            ItemHandler.stackItems(player, event.getCursor(), event.getCurrentItem(), -1);
        }
    } else if (event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) && event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && !ItemUtilities.getUtilities().isAllowed(player, event.getCurrentItem(), "stackable")) {
        ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(event.getCurrentItem(), null, player.getWorld());
        event.setCancelled(true);
        int REMAINING_STACK_SIZE = event.getCurrentItem().getAmount();
        if (itemMap != null && event.getSlot() > 8 && event.getView().getType().name().equalsIgnoreCase("CRAFTING")) {
            for (int i = 0; i < 8; i++) {
                if (itemMap.isSimilar(player.getInventory().getItem(i))) {
                    REMAINING_STACK_SIZE = ItemHandler.stackItems(player, event.getCurrentItem(), player.getInventory().getItem(i), event.getSlot());
                    if (REMAINING_STACK_SIZE <= 0) {
                        break;
                    }
                }
            }
        } else if (itemMap != null && event.getView().getType().name().equalsIgnoreCase("CRAFTING")) {
            for (int i = 8; i < 36; i++) {
                if (itemMap.isSimilar(player.getInventory().getItem(i))) {
                    REMAINING_STACK_SIZE = ItemHandler.stackItems(player, event.getCurrentItem(), player.getInventory().getItem(i), event.getSlot());
                    if (REMAINING_STACK_SIZE <= 0) {
                        break;
                    }
                }
            }
        }
        if (REMAINING_STACK_SIZE > 0) {
            event.setCancelled(false);
        }
        PlayerHandler.updateInventory(player, 1L);
    }
}
Also used : Player(org.bukkit.entity.Player) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) EventHandler(org.bukkit.event.EventHandler)

Example 100 with ItemMap

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

the class Stackable method onPickupStackable.

/**
 * Stacks custom items with the Stackable itemflag defined.
 *
 * @param event - EntityPickupItemEvent
 */
@EventHandler(ignoreCancelled = true)
private void onPickupStackable(EntityPickupItemEvent event) {
    Entity entity = event.getEntity();
    ItemStack item1 = event.getItem().getItemStack();
    if (entity instanceof Player && item1 != null && item1.getType() != Material.AIR && !ItemUtilities.getUtilities().isAllowed((Player) event.getEntity(), item1, "stackable")) {
        Player player = (Player) event.getEntity();
        ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(item1, null, player.getWorld());
        int REMAINING_STACK_SIZE = item1.getAmount();
        event.setCancelled(true);
        for (int i = 0; i < 36; i++) {
            if (itemMap != null && itemMap.isSimilar(player.getInventory().getItem(i))) {
                REMAINING_STACK_SIZE = ItemHandler.stackItems(player, item1, player.getInventory().getItem(i), -2);
                if (REMAINING_STACK_SIZE <= 0) {
                    break;
                }
            }
        }
        if (REMAINING_STACK_SIZE > 0) {
            event.setCancelled(false);
        } else {
            event.getItem().remove();
        }
        PlayerHandler.updateInventory(player, 1L);
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

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