Need help with "HEAL plugin"

Discussion in 'Plugin Development' started by demondking23, Feb 23, 2016.

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

    demondking23

    Hi! I was wondering, If someone could help me, I was making a heal plugin, I was trying to set up permissions for it, but this is my first time, and it doesn't want to work : soooo it has a line under 'e' of e .setCancelled(true);
    here is the code on my main

    Code:
    package me.demonicrin;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class main extends JavaPlugin {
       
        public Permission playerPermissions = new Permission("nova.heal");
                                                         
           
       
        @Override
        public void onEnable(){
            getLogger().info("Killheal has been enabled!");
                new PlayerListener(this);
                PluginManager pm = getServer().getPluginManager();
                pm.addPermission(playerPermissions);
               
        }
    
        @Override
        public void onDisable(){
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
           
            if (cmd.getName().equalsIgnoreCase("heal") && sender instanceof Player){
               
                Player player = (Player)sender;
               
                if(!player.hasPermission("nova.heal")){
                    e.setCancelled(true);
                   
                }
               
                player.setHealth(20.0);
               
                player.setFoodLevel(20);
               
                player.sendMessage(ChatColor.AQUA + "You have been healed!");
               
            }
            return false;
        }
    }
    

    for my listener
    Code:
    package me.demonicrin;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class PlayerListener implements Listener {
                                                         
           
            public PlayerListener(main plugin){                                                       
                plugin.getServer().getPluginManager().registerEvents(this, plugin);  
    
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent e){
            Player player = e.getPlayer();
           
            player.sendMessage(ChatColor.BLUE + "Welcome, " + player.getName() + "! " + "Hope you enjoy your stay!" );
        }                                                                                                 
       
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e){
        Player pp = e.getEntity();
        Player killed = pp.getKiller();
        killed.setHealth(killed.getHealth()+6);
        killed.sendMessage(ChatColor.GREEN + "you got 3 hearts for killing " + ChatColor.BLUE + pp.getName());
       
        }
    }
     
  2. Offline

    Zombie_Striker

    Class names should start with an upper case letter.

    Use Player#hasPermission( Permission) to test if the player has the permission.
     
  3. Offline

    demondking23

    WHAT?
     
  4. Offline

    Zombie_Striker

    [Edit] Realized your problem wasn't with setting up permissions. Your problem is that "e" does not exist because "onCommand" is not an event, nor is there any variable called "e". You cannot cancel a command through onCommand, but you can use CommandPreProcessEvent and check and cancel that.
     
  5. Offline

    MOMOTHEREAL

    10/10 feedback

    That's called an error, I believe. If you hover over it, it'll tell you why!
    Also, you are executing "e.setCancelled()" in a command method, use something like "return false;" or something similar.
     
Thread Status:
Not open for further replies.

Share This Page