Entity Permissions?

Discussion in 'Plugin Development' started by Minecraft93, Jul 5, 2011.

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

    Minecraft93

    Im trying to setup permissions on an entity event. is it possible? if so how? of course my point is to make it so when the player has this node they cant be damaged.



    Code:
        public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event){
    
                      if ((this.isperm) &&
                        (!Permissions.has(player, "almighty.god"))) {
            event.setCancelled(true);
        }
     
  2. Offline

    Jaker232

    You are missing an else function. I recommend this:

    Code:
        public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event){
    
                      if ((this.isperm) &&
                        (!Permissions.has(player, "almighty.god"))) {
            event.setCancelled(true);
        }
    else {
        event.setCancelled(false);
    }
     
  3. Offline

    Minecraft93

    oh woops thanks for that. My issue is that the "player" in (player, "almighty.god"))){ is throwing an error saying it cant be called as a variable. so how do i make the player become and entity player? im not sure if that makes since or not. if i called this permission line in a player listener then it wouldnt throw any errors.
     
  4. Offline

    Jaker232

    I do permissions this way:
    Code:
    if (permissionHandler.has((Player)sender, "almighty.god")) {
    
    I configured the node to the one you have in your code snippet, so your welcome to copy and paste w/o editing it.
     
  5. Offline

    Connor Mahaffey

    You never initialize the variable player.

    You can you event.getEntity() to get an entity, and then make that a player like so:
    Code:
    Entity e = event.getEntity();//entity that got hit (I think)
    if (e instanceof Player){//is the entity a player, i.e. not a zombie shooting a spider
         Player player = (Player)e;//make that entity a player
         if (this.isperm && !Permissions.has(player, "almighty.god"){//your code from before
               event.setCancelled(true);//cancel the event
         }
    }
    
    Now question, don't you want to cancel the event if they ARE an almighty god? Right now it cancels the event if they are NOT an almighty god.
     
  6. Offline

    Jaker232

    Ohhh, I get it now.
     
  7. Offline

    Minecraft93

    Yes thats the plan im trying to setup a permissions node so that when the player has it they cannot be hurt. if they dont have it then hurt them.
     
  8. Offline

    Connor Mahaffey

    Then you want to use Permissions.has(player, "almighty.god") not !Permissions.has(player, "almighty.god")
     
  9. Offline

    Jaker232

    Do you make sure you have an "Else" function?
    You might want to do player.sendMessage("[Almighty] You now have god mode on."); or something like that, then return true; for the first part.
    If you want to give it color, just do
    player.sendMessage(ChatColor.color+"[Almighty] You now have god mode on.");
    Replace "color" with your color you want IN CAPS.

    You can configure what you want it to say. It's up to you.

    If you are wondering about the else function, try
    Code:
    else {
    player.sendMessage(ChatColor.RED+"You do not have permission to use this command!");
    return false;
    
     
  10. Offline

    Minecraft93

    then with the has in permissions.has(player, "almighty.god") its throwing out an error



    Code:
    package us.william.almighty;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.entity.EntityDamageByProjectileEvent;
    import org.bukkit.event.entity.EntityListener;
    import com.nijikokun.bukkit.Permissions.Permissions;
    
    public class AlEntityListener extends EntityListener {
        public static almighty plugin;
        public AlEntityListener(almighty instance)
        {
          plugin = instance;
        }
        public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event){
            Entity e = event.getEntity();
            if (e instanceof Player){
                 Player player = (Player)e;
                 if (Permissions.has(player, "almighty.god"))
                       event.setCancelled(true);
                 }
            }
        }
    }
     
  11. Offline

    Connor Mahaffey

    Last edited by a moderator: May 17, 2016
  12. Offline

    Jaker232

  13. Offline

    Minecraft93

    nice thanks for the help
     
Thread Status:
Not open for further replies.

Share This Page