Event Permissions.

Discussion in 'Plugin Development' started by coolguy4744, Apr 25, 2014.

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

    coolguy4744

    Hello, I am having trouble with adding permissions to some events, I have tried many things but they are just not woring. Here is the code.

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event)
    3. {
    4. Action a = event.getAction();
    5. ItemStack is = event.getItem();
    6. if ((a == Action.PHYSICAL) || (is == null) || (is.getType() == Material.AIR)) {
    7. return;
    8. }
    9. if (is.getType() == Material.BEDROCK) {
    10. openGUI(event.getPlayer());
    11. }
    12. }
    13.  


    and

    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event)
    3. {
    4. Player player = (Player)event.getWhoClicked();
    5. if ((event.getCurrentItem() == null) ||
    6. (event.getCurrentItem().getType() == Material.AIR) ||
    7. (!event.getCurrentItem().hasItemMeta()))
    8. {
    9. player.closeInventory();
    10. return;
     
  2. Offline

    Serializator

    Just check in a if statement:

    Code:java
    1. if(p.hasPermission("YourPermission")) {
    2. //Do something
    3. }
     
  3. Offline

    coolguy4744

    Serializator
    I tried, it didn't work. :/

    Bumb.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Please show where you tried to check for the permission
     
  5. Offline

    coolguy4744

    AdamQpzm

    public void onPlayerInteract(PlayerInteractEvent event){
    Player player = event.getPlayer();
    player.hasPermission("simplekitpvp.inv.member");

    and the first thing that someone suggested.
     
  6. coolguy4744 That's because that's not an if statement, that just check if a player has a permission and then disregards that knowledge completely.
     
  7. Offline

    coolguy4744

    Ok, th
    It didn't work. :(
     
  8. Offline

    coolguy4744

    Code:java
    1. @EventHandler
    2. public void onInventoryClick1(InventoryClickEvent event)
    3. {
    4. Player player = (Player)event.getWhoClicked();
    5. if(player.hasPermission("simplekitpvp.inv.member")) {
    6. //Do something
    7. }
    8. if ((event.getCurrentItem() == null) ||
    9. (event.getCurrentItem().getType() == Material.AIR) ||
    10. (!event.getCurrentItem().hasItemMeta()))
    11. {
    12. player.closeInventory();
    13. return;
    14. }


    I would also like to do it for,

    Code:java
    1. EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Action a = event.getAction();
    4. ItemStack is = event.getItem();
    5. if ((a == Action.PHYSICAL) || (is == null) || (is.getType() == Material.AIR)) {
    6. return;
    7. }
    8. if (is.getType() == Material.BEDROCK) {
    9. openGUI(event.getPlayer());
    10. }
    11. }
    12.  
     
  9. Offline

    ImPhantom

    coolguy4744
    Code:java
    1. @EventHandler
    2. public void onInventoryClick1(InventoryClickEvent event)
    3. {
    4. Player player = (Player)event.getWhoClicked();
    5. if(player.hasPermission("simplekitpvp.inv.member")) {
    6. if ((event.getCurrentItem() == null) ||
    7. (event.getCurrentItem().getType() == Material.AIR) ||
    8. (!event.getCurrentItem().hasItemMeta()))
    9. {
    10. player.closeInventory();
    11. return;
    12. }
    13. }


    Where it says "do something" you actually have to do something. its not gonna do it for you.

    You may need to fix a couple brackets... I dont have an IDE at hand today.
     
  10. Offline

    Deleted user

    It is very very very important for you to learn Java coolguy4744.
    https://www.google.com/#q=if java
    Very very important.
    https://www.google.com/#q=if java
     
  11. Offline

    ImPhantom

  12. Offline

    Code0

    If you want you can post your code, tell me what you want and I'll do it for you explaining everything.
     
  13. Offline

    Deleted user

    Well done ImPhantom, now coolguy4744 understands better.
     
  14. Offline

    ImPhantom

Thread Status:
Not open for further replies.

Share This Page