GUI Permissions

Discussion in 'Plugin Development' started by KoolzSkillz, Aug 13, 2014.

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

    KoolzSkillz

    Ok.
    Is this possible,
    Say I had a GUI inventory with several items, let's just say their is, Kill, Burn, and Heal
    I want it so they can see the kill icon BUT it won't let them use it if they don't have a permission
     
  2. Offline

    fireblast709

    KoolzSkillz do a permission check when they attempt to use it. Player#hasPermission(String permission)
     
  3. Offline

    KoolzSkillz

    fireblast709
    i have this so far, it ALMOST works, it doesnt let me do it if they dont have permission BUT it also runs the LAVA_BUCKET case
    Code:
            switch(event.getCurrentItem().getType()) {
            case PAPER:
                player.closeInventory();
                player.sendMessage(ChatColor.GREEN
                        + "[News] : "
                        + getConfig().getString("news"));
                break;
            case WATER_BUCKET:
                if (!player.hasPermission("ICommands.Enderchest")) {
                    player.sendMessage(ChatColor.RED + "No Permission To Use This");
                } else {
                player.closeInventory();
                player.setHealth(20);
                player.setFireTicks(0);
                player.sendMessage(ChatColor.GREEN + "Healed");
                break;
            case LAVA_BUCKET:
                player.closeInventory();
                player.setHealth(0);
                player.sendMessage(ChatColor.GREEN + "Killed");
                break;
                default:
                    player.closeInventory();
                    break;
            }
        }
     
  4. Offline

    fireblast709

    KoolzSkillz where did the closing brace for the else clause go? (in the WATER_BUCKET case). The break; should be after that closing brace.
     
  5. Offline

    KoolzSkillz

    fireblast709
    It Works Now Thank you, the only problem is that it says the no permission msg twice :D
     
  6. Offline

    fireblast709

    KoolzSkillz Updated code? (Perhaps also a bit more of the code, like the whole event handler)
     
  7. Offline

    KoolzSkillz

    fireblast709 here

    Full Code
    Show Spoiler

    Code:
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if (!ChatColor.stripColor(event.getInventory().getName())
                    .equalsIgnoreCase("ICommands Commands"))
                return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
     
            if (event.getCurrentItem() == null
                    || event.getCurrentItem().getType() == Material.AIR
                    || !event.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
         
            switch(event.getCurrentItem().getType()) {
            case PAPER:
                player.closeInventory();
                player.sendMessage(ChatColor.GREEN
                        + "[News] : "
                        + getConfig().getString("news"));
                break;
            case WATER_BUCKET:
                if (!player.hasPermission("ICommands.Heal")) {
                    player.sendMessage(ChatColor.RED + "No Permission To Use This");
                } else {
                player.closeInventory();
                player.setHealth(20);
                player.setFireTicks(0);
                player.sendMessage(ChatColor.GREEN + "Healed");
                }
                break;
            case LAVA_BUCKET:
                if (!player.hasPermission("ICommands.Kill")) {
                    player.sendMessage(ChatColor.RED + "No Permission To Use This");
                } else {
                player.closeInventory();
                player.setHealth(0);
                player.sendMessage(ChatColor.GREEN + "Killed");
                }
                break;
               
               
               
               
                default:
                    player.closeInventory();
                    break;
        }
     
  8. Offline

    fireblast709

    KoolzSkillz Did you perhaps registered the Listener twice by accident?
     
  9. Offline

    KoolzSkillz

    fireblast709
    I had it registered twice, I was gonna make another class with another GUI but haven't got around to it XD
    Thx a lot for your help :)

    fireblast709
    I have one more question, with the GUI if I click kill, can I get it to open another inventory with all the online players and I click the one I want to kill?

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

    fireblast709

    KoolzSkillz schedule a task with runTask(Plugin), close the inventory within that task. After you've done that, schedule another task (yay task-ception) that opens the new inventory. For some clarification:
    Code:
    new BukkitRunnable()
    {
        @Override
        public void run()
        {
            // Close old inventory
            new BukkitRunnable()
            {
                @Override
                public void run()
                {
                    // Open new inventory
                }
            }.runTask(plugin instance);
        } 
    }.runTask(plugin instance);
     
  11. Offline

    KoolzSkillz

  12. Offline

    thomasb454


    You don't need to do that. Close the inventory above the task, then within it (meaning only one task needed) open the new inventory. (Only 1 tick is needed)
     
  13. Offline

    fireblast709

    thomasb454 read the documentation before you correct people :p
    Source: http://jd.bukkit.org/dev/apidocs/org/bukkit/event/inventory/InventoryClickEvent.html
     
    L33m4n123 and AdamQpzm like this.
  14. Offline

    thomasb454

  15. thomasb454 "isn't safe" generally implies that it will work sometimes and will go horrifically other times. Otherwise, they would have said that it doesn't work. Take async method calls for example, they could work perfectly fine 99 times out of 100 and then corrupt the world the other time
     
  16. Offline

    mythbusterma

    thomasb454

    But you should. If you don't, you could crash the client (at least, I think that's the side effect of that).
     
  17. Offline

    thomasb454

    How I've ALWAYS done it, and so have many others. Works fine, I understand that I'm not going to get anywhere, so /thread, for me, at least.
     
  18. Offline

    mythbusterma

    thomasb454

    And it's against the specification and could break things. There's a reason they don't recommend doing it and you should follow the recommendation.
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page