Pickup event

Discussion in 'Plugin Development' started by Marcohan, Aug 18, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Marcohan

    Code:
    public class Main extends JavaPlugin implements Listener {
    
    
    booleanseed = false;
    
    Integer count = 0;
    
    
    public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {
    
    if (sender.hasPermission("uhc.seeddodgers")){
    
    if (args.length == 1){
    
    if (cmd.getName().equalsIgnoreCase("seeddodgers")){
    
    if (args[0].equalsIgnoreCase("enable")){
    
    seed = true;
    
    count = 0;
    
    Bukkit.broadcastMessage(ChatColor.GRAY + "Seed Dodgers Enabled");
    
    }
    
    if (args[0].equalsIgnoreCase("disable")){
    
    seed = false;
    
    count = 0;
    
    Bukkit.broadcastMessage(ChatColor.GRAY + "Seed Dodgers Disabled");
    
    }
    
    }
    
    }
    
    }
    
    returnfalse;
    
    }
    
    
    @SuppressWarnings("deprecation")
    
    @EventHandler
    
    public void onPickup(PlayerPickupItemEvent event){
    
      Item i = event.getItem(); 
    
      ItemStack item = i.getItemStack();
    
      Player p = event.getPlayer();
    
      if(item.getType() == Material.SEEDS){
    
      if (seed == true){
    
      if (count < 21){
    
      count ++;
    
      p.damage(20);
    
      Bukkit.broadcastMessage(ChatColor.GRAY + " " + p + " Picked up a seed and is now dead!" );
    
      Bukkit.broadcastMessage(ChatColor.GRAY + "" + count + "/20 Dead");
    
      }else{
    
      p.sendMessage("hi");
    
      }
    
      if (count == 21){
    
      seed = false;
    
      Bukkit.broadcastMessage(ChatColor.GRAY + " Seed Dodger is now off!");
    
      }
    
     
    
      }
    
      else{
    
      p.sendMessage("Hi");
    
      }
    
      }
    
    }
    The Pickup event is not working, but the command is.
     
  2. Offline

    AdobeGFX

    Do you get any errors?
    Code:
    booleanseed = false;
    Lol, you forgot to add a space ;)
     
  3. Offline

    Marcohan

    nope
     
  4. Offline

    bling4525

    have you registered your events in another class? cuz I didn't see it.

    for the pickup event to actually work you need to register your events.
    do this with the following:

    getServer().getPluginManager().registerEvents(this, this);
    have you got an onEnable and everything?
     
  5. Offline

    Marcohan

    There is a space, I made a mistake when i copied the Code
     
  6. Offline

    AdobeGFX

    It's working for me..
    Code:
    Bukkit.broadcastMessage(ChatColor.GRAY + " " + p + " Picked up a seed and is now dead!" );
    And you should use p.getName() here..
     
  7. Offline

    bling4525

    AFAIK there's nothing here that shouldn't work if everything is registered (events and commands.) As for the broadcasting, I know nothing about it but the code @AdobeGFX has seems to look good. Try reloading your server.
     
Thread Status:
Not open for further replies.

Share This Page