Right click item in hand perm

Discussion in 'Plugin Development' started by Glass_Eater84, Aug 15, 2014.

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

    Glass_Eater84

    Hey,
    I am wondering how to setup permissions for something that is not a command. Example.

    Click ink sack Im sorry but you do not have access to put on armour

    how would I make it so that if they have the permission they can put on armour but if not it wont?
     
  2. Offline

    xTigerRebornx

    _LB likes this.
  3. Offline

    BeastCraft3

    Glass_Eater84
    One example:
    Code:
    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Server Selector"))
                return;
            Player player = (Player) event.getWhoClicked();
            event.setCancelled(true);
           
            if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR||!event.getCurrentItem().hasItemMeta()){
                player.closeInventory();
                return;
    if(player.hasPermission("test.open")) {
            }
           
            switch (event.getCurrentItem().getType()){
            case IRON_SWORD:
                player.getWorld().playSound(player.getLocation(),
                        Sound.GHAST_FIREBALL, 3f, 3f);
                player.performCommand("server hg");
                player.closeInventory();
                player.sendMessage(String.format("%sTeleported to %sSurvivalGames%s!", ChatColor.GOLD, ChatColor.RED, ChatColor.GOLD));
                break;
     
  4. Offline

    Glass_Eater84

    BeastCraft3
    In my existing event?
    EDit
    Snip of code:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onPlayerJoin(PlayerJoinEvent event){
    4. Player p = event.getPlayer();
    5. ItemStack blaze = new ItemStack(Material.BLAZE_POWDER);
    6. ItemMeta im = blaze.getItemMeta();
    7. im.setDisplayName("§a§lDisco Armour");
    8. blaze.setItemMeta(im);
    9. p.getInventory().addItem(blaze);
    10. p.updateInventory();
    11.  
    12. }
    13. @EventHandler
    14. public void onPlayerQuit(PlayerQuitEvent event){
    15. Player p = event.getPlayer();
    16. p.getInventory().remove(Material.BLAZE_POWDER);
    17. disco.remove(p.getName());
    18.  
    19. }
    20. @SuppressWarnings("deprecation")
    21. @EventHandler(priority=EventPriority.HIGH)
    22. public void onPlayerUse(PlayerInteractEvent event){
    23. Player o = event.getPlayer();
    24.  
    25. Action a = event.getAction();
    26. if(a == Action.RIGHT_CLICK_AIR){
    27. if(o.getItemInHand().getType() == Material.BLAZE_POWDER){
    28. if(o.getItemInHand().getItemMeta().getDisplayName().equals("§a§lDisco Armour")){
     
  5. Offline

    teej107

  6. Offline

    DinosParkour

    Glass_Eater84
    in your event, you have something like
    Code:ReplaceFrom
    1. if(e.getPlayer().getItemInHand().getType() == Material.INK_SACK)...
    well, just make it into this
    Code:ReplaceWith
    1. if(e.getPlayer().getItemInHand().getType() == Material.INK_SACK && e.getPlayer().hasPermission("your.permission"))...
     
  7. Offline

    BeastCraft3

    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
        Player p = event.getPlayer();
        ItemStack blaze = new ItemStack(Material.BLAZE_POWDER);
        ItemMeta im = blaze.getItemMeta();
        im.setDisplayName("§a§lDisco Armour");
        blaze.setItemMeta(im);
        p.getInventory().addItem(blaze);
        p.updateInventory();
     
        }
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent event){
        Player p = event.getPlayer();
        p.getInventory().remove(Material.BLAZE_POWDER);
        disco.remove(p.getName());
     
        }
        @SuppressWarnings("deprecation")
        @EventHandler(priority=EventPriority.HIGH)
        public void onPlayerUse(PlayerInteractEvent event){
        Player o = event.getPlayer();
     
        Action a = event.getAction();
        if(a == Action.RIGHT_CLICK_AIR){
        if(o.getItemInHand().getType() == Material.BLAZE_POWDER && o.hasPermission("Use.Test")){
        if(o.getItemInHand().getItemMeta().getDisplayName().equals("§a§lDisco Armour")){
    Glass_Eater84
    Sorry for double posting, just forgot to add tahg you ;3

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

    Glass_Eater84

    BeastCraft3
    Ok that works...
    A bit off topic but how would I add a cooldown and a cooldown messgae?
     
  9. Offline

    Garris0n

    Create a map of player UUIDs and longs. The long will represent the last time (in milliseconds) that they performed the action. After they perform the action, set the last use time (in the map) to the current time in milliseconds, which you can get via this method. Whenever they attempt to perform the action, check the difference of the current time and last time to see how many milliseconds have passed. Use this to figure out if they're still on cooldown.

    Please note that if anyone ever suggests that you use schedulers and lists (especially of players) to do cooldowns, they are horribly wrong and you should pretend you never heard them.
     
  10. Offline

    Glass_Eater84

  11. Offline

    Glass_Eater84

    Worked thanks guys!
     
Thread Status:
Not open for further replies.

Share This Page