org.bukkit.entity.Item Java Examples

The following examples show how to use org.bukkit.entity.Item. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Soulbound.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Effect if a player drops an item
 *
 * @param event the event
 */
@EventHandler(ignoreCancelled = true)
public void effect(PlayerDropItemEvent event) {
	Item item = event.getItemDrop();
	ItemStack tool = item.getItemStack();

	if (!(modManager.isArmorViable(tool) || modManager.isToolViable(tool) || modManager.isWandViable(tool))) {
		return;
	}

	if (!modManager.hasMod(tool, this)) {
		return;
	}

	if (toolDroppable) {
		return;
	}

	ChatWriter.logModifier(event.getPlayer(), event, this, tool, "Tool not droppable");

	event.setCancelled(true);
}
 
Example #2
Source File: MagnetTask.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void executeTask() {
    boolean playSound = false;

    for (Entity n : p.getNearbyEntities(radius, radius, radius)) {
        if (n instanceof Item) {
            Item item = (Item) n;

            if (!SlimefunUtils.hasNoPickupFlag(item) && item.getPickupDelay() <= 0 && p.getLocation().distanceSquared(item.getLocation()) > 0.3) {
                item.teleport(p.getLocation());
                playSound = true;
            }
        }
    }

    if (playSound) {
        p.playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 0.25F, 0.9F);
    }
}
 
Example #3
Source File: PlayerItemTransferEvent.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
public PlayerItemTransferEvent(
    Event cause,
    Type type,
    Player player,
    @Nullable Inventory fromInventory,
    @Nullable Integer fromSlot,
    @Nullable Inventory toInventory,
    @Nullable Integer toSlot,
    ItemStack itemStack,
    @Nullable Item itemEntity,
    int quantity,
    @Nullable ItemStack cursorItem) {

  super(
      cause, type, fromInventory, fromSlot, toInventory, toSlot, itemStack, itemEntity, quantity);
  this.player = player;
  this.cursorItem = cursorItem;
}
 
Example #4
Source File: ItemListener.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onDespawn(ItemDespawnEvent event) {
	Item item = event.getEntity();
	ItemStack is = item.getItemStack();

	if (!((modManager.isArmorViable(is) || modManager.isToolViable(is) || modManager.isWandViable(is))
			|| (MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.ForModItems")
			&& modManager.isModifierItem(is)))) {
		return;
	}

	if (MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.SetPersistent")) {
		event.setCancelled(true);
		item.setTicksLived(1);
	}
}
 
Example #5
Source File: BonusGoodieManager.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR) 
public void OnItemSpawn(ItemSpawnEvent event) {
	Item item = event.getEntity();
	
	BonusGoodie goodie = CivGlobal.getBonusGoodie(item.getItemStack());
	if (goodie == null) {
		return;
	}
	
	// Cant validate here, validate in drop item events...
	goodie.setItem(item);
	try {
		goodie.update(false);
		goodie.updateLore(item.getItemStack());
	} catch (CivException e) {
		e.printStackTrace();
	}
}
 
Example #6
Source File: Vectors.java    From TabooLib with MIT License 6 votes vote down vote up
public static Item itemDrop(Player player, ItemStack itemStack, double bulletSpread, double radius) {
    Location location = player.getLocation().add(0.0D, 1.5D, 0.0D);
    Item item = player.getWorld().dropItem(location, itemStack);
    double yaw = Math.toRadians((double)(-player.getLocation().getYaw() - 90.0F));
    double pitch = Math.toRadians((double)(-player.getLocation().getPitch()));
    double x;
    double y;
    double z;
    if (bulletSpread > 0.0D) {
        double[] spread = new double[]{1.0D, 1.0D, 1.0D};
        IntStream.range(0, 3).forEach((t) -> {
            spread[t] = (Numbers.getRandom().nextDouble() - Numbers.getRandom().nextDouble()) * bulletSpread * 0.1D;
        });
        x = Math.cos(pitch) * Math.cos(yaw) + spread[0];
        y = Math.sin(pitch) + spread[1];
        z = -Math.sin(yaw) * Math.cos(pitch) + spread[2];
    } else {
        x = Math.cos(pitch) * Math.cos(yaw);
        y = Math.sin(pitch);
        z = -Math.sin(yaw) * Math.cos(pitch);
    }

    Vector dirVel = new Vector(x, y, z);
    item.setVelocity(dirVel.normalize().multiply(radius));
    return item;
}
 
Example #7
Source File: RealDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean removeDupe() {
    if (this.item == null) {
        Util.debugLog("Warning: Trying to removeDupe for a null display shop.");
        return false;
    }

    boolean removed = false;
    // Chunk chunk = shop.getLocation().getChunk();
    for (Entity entity : item.getNearbyEntities(1.5, 1.5, 1.5)) {
        if (entity.getType() != EntityType.DROPPED_ITEM) {
            continue;
        }
        Item eItem = (Item) entity;
        UUID displayUUID = this.item.getUniqueId();
        if (!eItem.getUniqueId().equals(displayUUID)) {
            if (DisplayItem.checkIsTargetShopDisplay(eItem.getItemStack(), this.shop)) {
                Util.debugLog(
                        "Removing a duped ItemEntity " + eItem.getUniqueId() + " at " + eItem.getLocation());
                entity.remove();
                removed = true;
            }
        }
    }
    return removed;
}
 
Example #8
Source File: RealDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void safeGuard(@NotNull Entity entity) {
    if (!(entity instanceof Item)) {
        Util.debugLog("Failed to safeGuard " + entity.getLocation() + ", cause target not a Item");
        return;
    }
    Item item = (Item) entity;
    // Set item protect in the armorstand's hand

    if (plugin.getConfig().getBoolean("shop.display-item-use-name")) {
        item.setCustomName(Util.getItemStackName(this.originalItemStack));
        item.setCustomNameVisible(true);
    } else {
        item.setCustomNameVisible(false);
    }
    item.setPickupDelay(Integer.MAX_VALUE);
    item.setSilent(true);
    item.setPortalCooldown(Integer.MAX_VALUE);
    item.setVelocity(new Vector(0, 0.1, 0));
}
 
Example #9
Source File: EntityPortalEventListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldTeleportBecauseSameGroup() {
    // given
    Group group = mockGroup("test_group", GameMode.SURVIVAL, false);

    Item entity = mock(Item.class);

    World world = mock(World.class);
    given(world.getName()).willReturn("test_group");
    Location from = new Location(world, 1, 2, 3);

    World worldNether = mock(World.class);
    given(worldNether.getName()).willReturn("test_group_nether");
    Location to = new Location(worldNether, 1, 2, 3);

    given(groupManager.getGroupFromWorld("test_group")).willReturn(group);
    given(groupManager.getGroupFromWorld("test_group_nether")).willReturn(group);

    EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class));

    // when
    listener.onEntityPortalTeleport(event);

    // then
    assertThat(event.isCancelled(), equalTo(false));
}
 
Example #10
Source File: EntityPortalEventListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldTeleportBecauseSameGroup() {
    // given
    Group group = mockGroup("test_group", GameMode.SURVIVAL, false);

    Item entity = mock(Item.class);

    World world = mock(World.class);
    given(world.getName()).willReturn("test_group");
    Location from = new Location(world, 1, 2, 3);

    World worldNether = mock(World.class);
    given(worldNether.getName()).willReturn("test_group_nether");
    Location to = new Location(worldNether, 1, 2, 3);

    given(groupManager.getGroupFromWorld("test_group")).willReturn(group);
    given(groupManager.getGroupFromWorld("test_group_nether")).willReturn(group);

    EntityPortalEvent event = new EntityPortalEvent(entity, from, to, mock(TravelAgent.class));

    // when
    listener.onEntityPortalTeleport(event);

    // then
    assertThat(event.isCancelled(), equalTo(false));
}
 
Example #11
Source File: GunGizmo.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void playerInteract(final PlayerInteractEvent event) {
    if(event.getAction() == Action.PHYSICAL
            || !(Gizmos.gizmoMap.get(event.getPlayer()) instanceof GunGizmo)
            || event.getItem() == null || event.getItem().getType() != this.getIcon()) return;

    final Player player = event.getPlayer();
    RaindropUtil.giveRaindrops(Users.playerId(player), -1, new RaindropResult() {
        @Override
        public void run() {
            if(success) {
                Vector velocity = player.getLocation().getDirection().multiply(1.75D);

                Item item = player.getWorld().dropItem(event.getPlayer().getEyeLocation(), new ItemStack(Material.GHAST_TEAR));
                item.setVelocity(velocity);
                item.setTicksLived((5 * 60 * 20) - (5 * 20)); // 5 minutes - 5 seconds
                items.put(item, player.getUniqueId());
            } else {
                player.sendMessage(ChatColor.RED + LobbyTranslations.get().t("gizmo.gun.empty", player));
                player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1f, 1f);
            }
        }
    }, null, false, true, false);
}
 
Example #12
Source File: EnhancedItemListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Prevents enhanced item from dropping.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onItemDrop(PlayerDropItemEvent e) {
    Item droppedItem = e.getItemDrop();
    ItemStack DroppedItemStack = droppedItem.getItemStack();
    Player p = e.getPlayer();
    // Checks if the item is a bounded item
    if ((DroppedItemStack.hasItemMeta()) && (DroppedItemStack.getItemMeta()
            .getLore() != null)) {
        if (DroppedItemStack.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(
                SettingsManager.lang.getString("lore.untradeableLore")))) {
            e.setCancelled(true);
            Util.sendMessage(SettingsManager.lang.getString(
                    "messages.noDrop"), p);
        }
    }
}
 
Example #13
Source File: AncientAltarListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private void insertItem(Player p, Block b) {
    ItemStack hand = p.getInventory().getItemInMainHand();
    ItemStack stack = new CustomItem(hand, 1);

    if (p.getGameMode() != GameMode.CREATIVE) {
        ItemUtils.consumeItem(hand, false);
    }

    String nametag = ItemUtils.getItemName(stack);
    Item entity = b.getWorld().dropItem(b.getLocation().add(0.5, 1.2, 0.5), new CustomItem(stack, "&5&dALTAR &3Probe - &e" + System.nanoTime()));
    entity.setVelocity(new Vector(0, 0.1, 0));
    SlimefunUtils.markAsNoPickup(entity, "altar_item");
    entity.setCustomNameVisible(true);
    entity.setCustomName(nametag);
    p.playSound(b.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.3F, 0.3F);
}
 
Example #14
Source File: BonusGoodieManager.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void OnChunkUnload(ChunkUnloadEvent event) {
	
	BonusGoodie goodie;
	
	for (Entity entity : event.getChunk().getEntities()) {
		if (!(entity instanceof Item)) {
			continue;
		}
		
		goodie = CivGlobal.getBonusGoodie(((Item)entity).getItemStack());
		if (goodie == null) {
			continue;
		}
		
		goodie.replenish(((Item)entity).getItemStack(), (Item)entity, null, null);
	}
}
 
Example #15
Source File: KitLoading.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void StopDrops(PlayerDropItemEvent event)
{
    Player player = event.getPlayer();
    Item item = event.getItemDrop();
    if(item != null)
    {
	    ItemStack stack = item.getItemStack();
	    if(stack != null)
	    {
		    if(KitUtils.isSoulbound(stack))
		    {
			    player.playSound(player.getLocation(), Sound.BLAZE_HIT, 1.0F, 0.3F);
			    event.getItemDrop().remove();
		    }
	    }
    }
}
 
Example #16
Source File: VisualItemProcessor.java    From EliteMobs with GNU General Public License v3.0 6 votes vote down vote up
private void rotateItem(Object itemObject, Vector vector, EliteMobEntity eliteMobEntity) {

        Item item = (Item) itemObject;

        if (!item.isValid())
            return;

        Location currentLocation = item.getLocation().clone();
        Location newLocation = eliteMobEntity.getLivingEntity().getLocation().clone().add(new Vector(0, 1, 0)).add(vector);

//        if (currentLocation.distanceSquared(newLocation) > Math.pow(3, 2)) {
//            item.teleport(newLocation);
//            item.setVelocity(new Vector(0.01, 0.01, 0.01));
//            return;
//        }

        Vector movementVector = (newLocation.subtract(currentLocation)).toVector();
        movementVector = movementVector.multiply(0.3);

//        if (Math.abs(movementVector.getX()) > 3 || Math.abs(movementVector.getY()) > 3 || Math.abs(movementVector.getZ()) > 3) {
//            item.teleport(newLocation);
//        } else {
            item.setVelocity(movementVector);
//        }

    }
 
Example #17
Source File: ItemSpawner.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void remove(Item item) {
	if (maxSpawnedResources > 0 && spawnedItems.contains(item)) {
		spawnedItems.remove(item);
		if (spawnerIsFullHologram && maxSpawnedResources > spawnedItems.size()) {
			spawnerIsFullHologram = false;
			rerenderHologram = true;
		}
	}
}
 
Example #18
Source File: DropProtectListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent e) {
    if (plugin.cfg.dropProtectMode == DropProtectMode.OFF) return;
    UUID id = e.getEntity().getUniqueId();
    if (bypassPlayer.containsKey(id)) return;
    List<ItemStack> dropStacks = e.getDrops();
    Location loc = e.getEntity().getLocation();
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        Collection<Entity> ents = loc.getWorld().getNearbyEntities(loc, 3, 3, 10);
        ents.stream()
            .flatMap(ent -> (ent instanceof Item) ? Stream.of((Item) ent) : Stream.empty())
            .filter(i -> dropStacks.contains(i.getItemStack()))
            .forEach(dropItem -> items.put(dropItem.getEntityId(), id));
    }, 1);
}
 
Example #19
Source File: MajorPowerPowerStance.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
private Object addEffect(Material material) {

        Item item = eliteMobEntity.getLivingEntity().getWorld().dropItem(eliteMobEntity.getLivingEntity().getLocation(),
                new ItemStack(material));
        item.setPickupDelay(Integer.MAX_VALUE);
        if (!VersionChecker.currentVersionIsUnder(1, 11))
            item.setGravity(false);
        item.setInvulnerable(true);
        EntityTracker.registerItemVisualEffects(item);
        return item;

    }
 
Example #20
Source File: EntityPickupItemListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onEntityPickupItem(PlayerPickupItemEvent event) {
    try {
        final Item item = event.getItem();
        final Location location = item.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        final Player player = event.getPlayer();
        final User user = User.getUser(player);
        if (!island.getPermissions(user).pickupItems)
            event.setCancelled(true);
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example #21
Source File: Snowflakes.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onItemDespawnInVoid(EntityDespawnInVoidEvent event) {
    if (!(event.getEntity() instanceof Item) || !event.getEntity().hasMetadata(ITEM_THROWER_META)) return;
    Player player = Bukkit.getPlayer((UUID) event.getEntity().getMetadata(ITEM_THROWER_META).get(0).value());
    Item item = (Item) event.getEntity();
    if (testDestroy(player, item.getItemStack())) {
        addDestroyed(player, ((Wool) item.getItemStack().getData()).getColor());
    }
}
 
Example #22
Source File: AncientAltarTask.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkLockedItems() {
    for (Map.Entry<Item, Location> entry : itemLock.entrySet()) {
        if (entry.getKey().getLocation().distanceSquared(entry.getValue()) > 0.1) {
            return false;
        }
    }

    return true;
}
 
Example #23
Source File: Grenade.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public boolean onRMB(Player thrower, ItemStack usedItem) {
	if (throwItems.containsKey(thrower)) {
		ThrowableHolder holder = throwItems.get(thrower);
		ItemStack grenadeStack = thrower.getItemInHand();
		ItemStack temp = grenadeStack.clone();
		temp.setAmount(1);
		if (thrower.getGameMode() != GameMode.CREATIVE) {
			if (grenadeStack.getAmount() > 1) {
				grenadeStack.setAmount(grenadeStack.getAmount() - 1);
			} else {
				grenadeStack = null;
			}
			thrower.setItemInHand(grenadeStack);
		}
		Item grenade = holder.getHolder().getWorld().dropItem(holder.getHolder().getLocation().add(0, 1.5, 0),
				temp);
		grenade.setPickupDelay(Integer.MAX_VALUE);
		grenade.setVelocity(thrower.getLocation().getDirection().normalize().multiply(1.2));
		holder.setHolder(grenade);
		thrower.getWorld().playSound(thrower.getLocation(), Sound.ENTITY_ARROW_SHOOT, 1, 1.5f);

		throwItems.put(grenade, holder);
		throwItems.remove(thrower);
		QAMain.DEBUG("Throw grenade");
	} else {
		thrower.sendMessage(QAMain.prefix + QAMain.S_GRENADE_PULLPIN);
	}
	return true;
}
 
Example #24
Source File: AsyncWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item dropItemNaturally(final Location location, final ItemStack item) {
    return TaskManager.IMP.sync(new RunnableVal<Item>() {
        @Override
        public void run(Item value) {
            this.value = parent.dropItemNaturally(location, item);
        }
    });
}
 
Example #25
Source File: PGMListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void nerfFishing(PlayerFishEvent event) {
    if (Config.Fishing.disableTreasure() && event.getCaught() instanceof Item) {
        Item caught = (Item) event.getCaught();
        if (caught.getItemStack().getType() != Material.RAW_FISH) {
            caught.setItemStack(new ItemStack(Material.RAW_FISH));
        }
    }
}
 
Example #26
Source File: RaindropListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void handleItemDrop(final PlayerDropItemEvent event) {
    ParticipantState player = PGM.getMatchManager().getParticipantState(event.getPlayer());
    if(player == null) return;

    Competitor team = player.getParty();
    Item itemDrop = event.getItemDrop();
    ItemStack item = itemDrop.getItemStack();

    if (this.isDestroyableWool(item, team)) {
        this.droppedWools.put(itemDrop, player.getPlayerId());
    }
}
 
Example #27
Source File: RadiusBomb.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onExplode(Item item, Location location) {
	Vector locV = item.getLocation().toVector();
	for (Entity entity : item.getNearbyEntities(_radius, _radius, _radius)) {
		if (entity instanceof LivingEntity) {
			Vector delta = ((LivingEntity) entity).getEyeLocation().toVector().subtract(locV);
			double factor = 1 - delta.length()/_radius;
			if (factor > 0) {
				affectEntity(item, location, (LivingEntity) entity, delta, factor);
			}
		}
	}
}
 
Example #28
Source File: Directing.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void effect(BlockDropItemEvent event) {
	Player player = event.getPlayer();
	ItemStack tool = player.getInventory().getItemInMainHand();

	if (!player.hasPermission("minetinker.modifiers.directing.use")) {
		return;
	}

	if (!modManager.isToolViable(tool) || !modManager.hasMod(tool, this)) {
		return;
	}

	Iterator<Item> itemIterator = event.getItems().iterator();

	while (itemIterator.hasNext()) {
		Item item = itemIterator.next();

		HashMap<Integer, ItemStack> refusedItems = player.getInventory().addItem(item.getItemStack());

		if (!refusedItems.isEmpty()) {
			for (ItemStack itemStack : refusedItems.values()) {
				player.getWorld().dropItem(player.getLocation(), itemStack);
			}
		}

		itemIterator.remove();
	}
	Location loc = event.getBlock().getLocation();
	ChatWriter.logModifier(player, event, this, tool,
			String.format("Block(%d/%d/%d)", loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
 
Example #29
Source File: InfusedHopper.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean isValidItem(Location l, Entity entity) {
    if (entity instanceof Item && entity.isValid()) {
        Item item = (Item) entity;
        return !SlimefunUtils.hasNoPickupFlag(item) && item.getLocation().distanceSquared(l) > 0.25;
    }

    return false;
}
 
Example #30
Source File: DroppedItemData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void set(final Item entity) {
	final ItemType t = CollectionUtils.getRandom(types);
	assert t != null;
	ItemStack stack = t.getItem().getRandom();
	if (stack != null)
		entity.setItemStack(stack);
}