Permissions and Giving a killer potion effects

Discussion in 'Plugin Development' started by hanahouhanah, Jul 1, 2013.

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

    hanahouhanah

    So I have been working on this for some time, and basically what I'm trying to do is make it so a player who kills someone will get a potion effect for 10 seconds. But I want to set it up so the player will need a permission to do so.

    This is what I have so far:
    Code:
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
        public class PearlsListener implements Listener{
       
            @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
              public void onPlayerDeath(PlayerDeathEvent event){
                  if (event.getEntity().getLastDamageCause() == null||event.getEntity().getKiller() == null) {
                    return;
                  }
       
                  Player killer = event.getEntity().getKiller();   
                  EntityDamageEvent.DamageCause cause = event.getEntity().getLastDamageCause().getCause();
                  if ((cause == EntityDamageEvent.DamageCause.ENTITY_ATTACK || cause == EntityDamageEvent.DamageCause.PROJECTILE)){
                      killer.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, 10, true));
                      killer.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 10, 10, true));
                      }
               
              }
            @EventHandler
            public void onEntityDamageByEntity(EntityDamageByEntityEvent event){
                Entity e = event.getEntity();
             
                if (e instanceof Player){
                    Player player = (Player) e;
                    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, 10));
                }
            }
    }
    (The reason why I have the second @EventHandler is because I want to test this on a mob - but that's also not working for me)
    And my main class:

    Code:
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin {
       
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Main plugin;
        public final PearlsListener pl = new PearlsListener();
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " has been disabled.");
        }
       
        @Override
        public void onEnable() {   
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " has been enabled.");
           
        }
     
    }
    
    I'm not getting any errors upon starting my test server. I also have no way to test the first EventHandler, so I don't exactly know if that will work.
    What am I doing wrong?
     
  2. Offline

    morha13

    i can help you with the permissions...
    Code:java
    1. if (sender.hasPermission("ThePermissionNode")) {
    2.  
    3.  
    4. //paste here the code that need the permission
    5. } else{
    6.  
    7. player.sendMessage(ChatColor.DARK_RED + "You Dont Have Permissions To Use This
    8.  
    9. }
    10.  
    11.  
     
  3. Offline

    Steffion

    You forgot to register your events in the onEnable()
     
  4. Offline

    hanahouhanah

    Oh, I forgot to mention that the permissions will be constantly running (constantly enabled if they have the permission), so having a command sender is not what I wanted, but I am not exactly sure how to set up a permission without having a command sender.

    Aah, so my onEnable should look something like this?
    Code:
    @Override
        public void onEnable() {   
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " has been enabled.");
            Bukkit.getServer().getPluginManager().registerEvents(pl, this);
        }
     
  5. Offline

    morha13

    so try to use this
    Code:java
    1. if (player.hasPermissions("PermissionNode") {
     
  6. Offline

    Steffion

  7. Offline

    hanahouhanah

    I have thought of that, but that doesn't work. I get this error: http://gyazo.com/77164047c7ef531573acbc66211f7d14.png

    Hmm... This stuff still isn't working for me.

    Code:java
    1. import java.util.logging.Logger;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.plugin.PluginDescriptionFile;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. public class Main extends JavaPlugin {
    8.  
    9. public final Logger logger = Logger.getLogger("Minecraft");
    10. public static Main plugin;
    11. public final PearlsListener pl = new PearlsListener();
    12.  
    13. @Override
    14. public void onDisable() {
    15. PluginDescriptionFile pdfFile = this.getDescription();
    16. this.logger.info(pdfFile.getName() + " has been disabled.");
    17. }
    18.  
    19. @Override
    20. public void onEnable() {
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + " has been enabled.");
    23. Bukkit.getServer().getPluginManager().registerEvents(pl, this);
    24. }
    25.  
    26. }
    27.  


    Code:java
    1. import org.bukkit.entity.Entity;
    2. import org.bukkit.entity.Player;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.EventPriority;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    7. import org.bukkit.event.entity.EntityDamageEvent;
    8. import org.bukkit.event.entity.PlayerDeathEvent;
    9. import org.bukkit.potion.PotionEffect;
    10. import org.bukkit.potion.PotionEffectType;
    11.  
    12. public class PearlsListener implements Listener{
    13.  
    14. @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
    15. public void onPlayerDeath(PlayerDeathEvent event){
    16. if([COLOR=#ff0000]player[/COLOR].hasPermission("berserker")){
    17. if (event.getEntity().getLastDamageCause() == null||event.getEntity().getKiller() == null) {
    18. return;
    19. }
    20.  
    21. Player killer = event.getEntity().getKiller();
    22. EntityDamageEvent.DamageCause cause = event.getEntity().getLastDamageCause().getCause();
    23. if ((cause == EntityDamageEvent.DamageCause.ENTITY_ATTACK || cause == EntityDamageEvent.DamageCause.PROJECTILE)){
    24. killer.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, 10, true));
    25. killer.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 10, 10, true));
    26. }
    27. }
    28.  
    29. }
    30. @EventHandler
    31. public void onEntityDamageByEntity(EntityDamageByEntityEvent event){
    32. Entity e = event.getEntity();
    33.  
    34. if (e instanceof Player){
    35. Player player = (Player) e;
    36. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000, 10));
    37. }
    38. }
    39. }


    Nothing is working at the moment. When killing an entity, I am not getting the potion effect Speed, and I can't figure out why I'm getting the error for "player.hasPermission("berserker")"
    This is the error message: player cannot be resolved.
    I also can't be sure if the first part will work (without permissions) anyway. Still really confused, been reading the wiki's for references, nothing is really helping much.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  8. Offline

    morha13

    hanahouhanah i am not at home now..
    when i will get home i will try to help you with the permissions
     
  9. Offline

    hanahouhanah

  10. Offline

    PixeledCow

    Where are you getting your Player?
     
Thread Status:
Not open for further replies.

Share This Page