Help With Auto Feed

Discussion in 'Plugin Development' started by daniellekush, Dec 31, 2016.

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

    daniellekush

    So I recently started to learn Java and how to make plugins. I started creating a lobby plugin which lets the player toggle night vision, jump boost and auto feed if they have permission. I managed to successfully create the night vision and jump boost part but unfortunately I cannot figure out how to make the auto feed work. If any of you guys could help, that would be great.
     
  2. Offline

    mine2012craft

    @daniellekush If you want to keep up auto feed, or just not make them loose hunger at all, there is a event called the "FoodLevelChangeEvent"

    Simply cancel the event each time it happens, or set their hunger back to 20
     
  3. Offline

    FabeGabeMC

    Listen for a FoodLevelChangeEvent.

    Edit: Ninja'd by @mine2012craft
     
  4. Offline

    daniellekush

    I am trying to make it so that when a player types /ae autofeed is enabled and when they type /ae again then it is disabled (sending them a message that tells them both of those). They also have to have the permission ae.use.

    Code:
    package com.daniellekush.lobbyefx.event;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.FoodLevelChangeEvent;
    
    public class Event implements Listener{
     
        public boolean isEat = false;
     
        @EventHandler
        public void onFoodChange(FoodLevelChangeEvent event){
            Player player = (Player) event.getEntity();
            if(player instanceof Player){
                if (player.hasPermission("ae.use"))
                    if(player.getFoodLevel() == 19){
                        player.setFoodLevel(20);
                    if(!(isEat)){
                        isEat = true;
                        player.sendMessage(ChatColor.GREEN + "You have enabled auto eat");
                    }else if (isEat){
                        isEat = false;
                        player.sendMessage(ChatColor.DARK_RED + "You have disabled auto eat");
                    } else {
                    return;
                }
                player.setFoodLevel(player.getFoodLevel()+1);
            }
        }
    
    }
    }
    EDIT: can someone please help?
     
    Last edited: Jan 1, 2017
  5. Offline

    timtower Administrator Administrator Moderator

    Merged threads
     
Thread Status:
Not open for further replies.

Share This Page