Java Code Examples for org.bukkit.entity.Item#setCustomName()

The following examples show how to use org.bukkit.entity.Item#setCustomName() . 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: 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 2
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 3
Source File: ItemListener.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onItemDrop(PlayerDropItemEvent event) {
	if (MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.DisableDroppingBehaviour")) {
		return;
	}

	Item item = event.getItemDrop();
	ItemStack is = item.getItemStack();

	boolean isMineTinker = false;

	if (MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.ForModItems")) {
		isMineTinker = modManager.isModifierItem(is);
	}
	if (modManager.isArmorViable(is) || modManager.isToolViable(is) || modManager.isWandViable(is)) {
		isMineTinker = true;
	}

	if (!isMineTinker) {
		return;
	}

	if (MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.ShowName") && is.getItemMeta() != null) {
		item.setCustomName(is.getItemMeta().getDisplayName());
		item.setCustomNameVisible(true);
	}

	if (MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.SetGlowing")) {
		item.setGlowing(true);
	}

	if (MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.SetInvulnerable")) {
		item.setInvulnerable(true);
	}
}
 
Example 4
Source File: QuadCrate.java    From Crazy-Crates with MIT License 4 votes vote down vote up
@EventHandler
public void onChestClick(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    if (QuadCrateSession.inSession(player)) {
        QuadCrateSession session = QuadCrateSession.getSession(player);
        if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
            Block block = e.getClickedBlock();
            if (session.getChestLocations().contains(block.getLocation())) {
                e.setCancelled(true);
                if (!session.hasChestBeenOpened(block.getLocation())) {
                    nms.openChest(block, true);
                    Crate crate = session.getCrate();
                    Prize prize = crate.pickPrize(player, block.getLocation().add(.5, 1.3, .5));
                    cc.givePrize(player, prize);
                    ItemBuilder itemBuilder = ItemBuilder.convertItemStack(prize.getDisplayItem());
                    itemBuilder.addLore(new Random().nextInt(Integer.MAX_VALUE) + "");//Makes sure items don't merge
                    ItemStack item = itemBuilder.build();
                    NBTItem nbtItem = new NBTItem(item);
                    nbtItem.setBoolean("crazycrates-item", true);
                    item = nbtItem.getItem();
                    Item reward = player.getWorld().dropItem(block.getLocation().add(.5, 1, .5), item);
                    reward.setMetadata("betterdrops_ignore", new FixedMetadataValue(cc.getPlugin(), true));
                    reward.setVelocity(new Vector(0, .2, 0));
                    reward.setCustomName(prize.getDisplayItem().getItemMeta().getDisplayName());
                    reward.setCustomNameVisible(true);
                    reward.setPickupDelay(Integer.MAX_VALUE);
                    session.getDisplayedRewards().add(reward);
                    session.setChestOpened(block.getLocation(), true);
                    if (session.allChestsOpened()) {//All 4 crates have been opened
                        new BukkitRunnable() {
                            @Override
                            public void run() {
                                session.endCrate();
                                player.playSound(player.getLocation(), cc.getSound("BLOCK_STONE_STEP", "STEP_STONE"), 1, 1);
                            }
                        }.runTaskLater(cc.getPlugin(), 60);
                    }
                }
            }
        }
    }
}