Food Level Change

Discussion in 'Plugin Development' started by Nogtail, Mar 20, 2013.

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

    Nogtail

    So I need to get the name of the player who's food level changed so I can see if they have the required permission. I am using FoodLevelChangeEvent.
     
  2. Offline

    skipperguy12

    e.getPlayer()
     
  3. Offline

    Nogtail

    It's not liking me, any other ideas?
     
  4. Offline

    wacossusca34

    Please paste your code so we can see what you're doing wrong. You have to get the player from the event object by calling getPlayer() on it.
     
  5. Offline

    Nogtail

    public void FoodLevelChange(FoodLevelChangeEvent event){
    Player = event.getPlayer()
     
  6. Offline

    wacossusca34

    Player player = event.getPlayer()
    String name = player.getName();
     
  7. Offline

    Nogtail

    Got :
    public void FoodLevelChange(FoodLevelChangeEvent event){
    Player player = event.getPlayer();
    if (player.hasPermission("test.permission")){
    player.setFoodLevel(20);
    Bukkit.broadcastMessage("Filled");
    }
    }
    But its still throwing an error at event.getPlayer();
     
  8. Offline

    wacossusca34

    My bad, it's this:
    Player player = event.getEntity();
     
  9. Offline

    Nogtail

    Its not liking that either, never had any problems like this before.
     
  10. Offline

    wacossusca34

    Sorry again, I completely forgot you had to cast it :confused:

    This should work:

    Player player = (Player) e.getEntity();
     
  11. Offline

    Nogtail

    Thanks, I think its all working, now to crush the bugs...
     
Thread Status:
Not open for further replies.

Share This Page