Solved Help with eventListener

Discussion in 'Plugin Development' started by OneBillionAndOne, Jul 15, 2013.

Thread Status:
Not open for further replies.
  1. okay, so ive been trying to figure this out for hours and ive searched everywhere. how do i detect when a player picks up a BLUE or RED wool drop ive got the playerpickupitemevent working, and it triggers when i pickup wool, but not a specific color.(I know right now its at Material.WOOL and nothing else, i just cant figure out what to put next :/)
    Code:
    Code:java
    1. package org.gmail.firework4lj.listeners;
    2.  
    3. import org.bukkit.entity.Item;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerPickupItemEvent;
    8. import org.bukkit.inventory.ItemStack;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10. import org.gmail.firework4lj.CtfMain;
    11. import org.bukkit.DyeColor;
    12. import org.bukkit.Material;
    13.  
    14. public class FlagpickupListener extends JavaPlugin implements Listener{
    15.  
    16. public FlagpickupListener(CtfMain ctfmain){
    17. ctfmain.getServer().getPluginManager().registerEvents(this, ctfmain);
    18. }
    19. @EventHandler
    20. public void onPlayerPickupItemEvent(PlayerPickupItemEvent event){
    21. Player p = event.getPlayer();
    22. Item drop = event.getItem();
    23. if(drop.getItemStack() == Material.WOOL){
    24. p.sendMessage("wool");
    25. }else{
    26.  
    27. }
    28. }
    29. }


    any help is appreciated. thanks!
    (also, please don't comment on the code being messy or anything, im fairly new, and ive still got to learn more)
     
  2. Offline

    deery50

    OneBillionAndOne
    One way to do this would be to create a new Itemstack and set the byte value to the color of wool you are using, which means you can either use this:
    Code:
    ItemStack redwool = new ItemStack( Material.WOOL, 1, (byte)4 );
    
    (byte) being the value listed here: http://www.minecraftwiki.net/wiki/Data_values#Wool
    OR you could use the Bukkit DyeColor class which will in the end do the same sort of thing:
    Code:
    ItemStack redwool = new ItemStack(Material.WOOL, 1, DyeColor.RED.getData());
    
     
  3. Offline

    ZeusAllMighty11

    ItemStack != Material

    Also, .equals() not ==
     
  4. Offline

    Ewe Loon

    int itemtypeid = event.getItem().getItemStack().getTypeId();
    byte itemdatavalue = event.getItem().getItemStack().getData().getData();

    if itemtypeid is 35 then its wool
    if itemdatavalue is 14 its red
    if itemdatavalue is 11 its blue

    im sure if you want more colors you can work them out
    also remember the data value is not the same as the dye value
    wooldatavalue =15-dyedatavalue

    dont ask why they did that
     
  5. deery50
    TheGreenGamerHD
    Ewe Loon
    THANK YOU!
    i got it figured out.
    it was:
    Code:java
    1. public void onPlayerPickupItemEvent(PlayerPickupItemEvent event){
    2. Player p = event.getPlayer();
    3. Item drop = event.getItem();
    4. ItemStack redwool = new ItemStack(Material.WOOL, 1, DyeColor.RED.getData());
    5. if(drop.getItemStack().equals(redwool)){
    6. p.sendMessage("wool");
    7. }else{
    8.  
    9. }
    10. }


    Thank you so much, now i can move on with it :D
     
Thread Status:
Not open for further replies.

Share This Page