jtojnar / SpoutMaterials

0 stars 0 forks source link

Hooking UltraItems #13

Open Ziden opened 12 years ago

Ziden commented 12 years ago

Lets say for example, i would want that if the player touch a block, i would want to drop a ultraitem.

How would i do that ?

Thanx for your attention !

jtojnar commented 12 years ago

It will be implemented for blocks when i add them to ui.

Ziden commented 12 years ago

could u explain this better ? maybe a simple code snipper, would be great

thanx alot for your attention !

jtojnar commented 12 years ago

Sorry i forgot to reply. You mean for destroying block? It would be sth like this (not tested):


import cz.ogion.ultraitems.*
public class BlockListener extends org.bukkit.event.block.BlockListener {
    ItemManager itemManager = new ItemManager();
    @Override
    public void onBlockBreak(BlockBreakEvent event) {
        UICustomItem item = itemManager.getItem(itemName);
        Integer amount = 1;
        if (item != null && event.getBlock().getType() == Material.COAL_ORE) {
            event.setCancelled(true);
            event.getBlock().setType(Material.AIR);
            event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), new SpoutItemStack(item, amount));
        }
    }
}
Ziden commented 12 years ago

hmm on blockBreak ? Isnt it a item ? Im confused hehe

my real intetion is to make a sign, for example, on player interact, he gets a custom item, so i would need to create an ItemStack with that Custom Item and land it into the player inventory.

PS: think i just got it, with that SpoutItemStack heh :D

ill do my tryouts, thanx for your help, keep up the good work on this awesome plugin !!!!

jtojnar commented 12 years ago

You are alright it's SpoutItemStack.

Ziden commented 12 years ago

how could i check, in another plugin, if the item in hand for example, is a custom item ? A cast ?

thanx alot for yout help

Ziden commented 12 years ago

i couldnt find SpoutItemStack class btw

jtojnar commented 12 years ago

itemManager.getItem(player.getItemInHand()) == null

jtojnar commented 12 years ago

It's in dev spoutapi

Ziden commented 12 years ago

im.getItem(itemInHand) is aways returning null, even if i have the item in hand thanx for your time !

ItemStack itemInHand = event.getPlayer().getItemInHand(); ItemManager im = new ItemManager(instancia.getUl()); // return UltraItems javaplugin

jtojnar commented 12 years ago

Actually i didn't realized it creates new manager. It should be sth like this then:


    Plugin ui = this.getServer().getPluginManager().getPlugin("UltraItems");
    if (ui != null) {
        if(ui.itemManager.getItem(player.getItemInHand()) == null) {
           player.chat("I am holding ultraitem");
       }
    }

Although i will focus on SpoutMaterials now so i won't keep this plugin anymore.