Solved Need help with adding permissions.

Discussion in 'Plugin Development' started by fRogZy, Oct 12, 2017.

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

    fRogZy

    Hello,

    I want to ask if someone is ready to help me to add permissions to this code. So if player doesn't have permissions they would not be able to create specific sign "heal"

    Code:
    package me.fRogZy.PlexSigns;
    
    
    import org.bukkit.ChatColor;
    import org.bukkit.block.Sign;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    public class Heal implements Listener {
            @EventHandler
            public void onSignChange(SignChangeEvent e) {
                    if (e.getLine(0).equalsIgnoreCase("[Heal]")) {
                            e.setLine(0, "§8(§aHeal§8)");
                    }
            }
          
            @EventHandler
            public void onPlayerInteract(PlayerInteractEvent e) {
                    if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
                    if (e.getClickedBlock().getState() instanceof Sign) {
                            Sign s = (Sign) e.getClickedBlock().getState();
                            if (s.getLine(0).equalsIgnoreCase("§8(§aHeal§8)")) {
                                    e.getPlayer().setHealth(20);
                                    e.getPlayer().sendMessage(ChatColor.BOLD + "" + ChatColor.RED + "PMS" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been healed! ");
                            }
                    }
            }
    }
    I will appreciate form of help.
     
  2. Offline

    MightyOne

    Player#hasPermission(String/Permission) lets you check if a player has a particular permission
     
  3. Offline

    fRogZy

    May you help me a bit more, I know it sounds dumb but I just started like 1 week ago with learning java.

    Code:
    @EventHandler
            public void onSignChange(SignChangeEvent e) {
            Player p = e.getPlayer();
            if(e.getLine(0).equalsIgnoreCase("[Heal]")) {
            if(p.hasPermission("sign.heal")) {
                e.setLine(0, "§8(§aHeal§8)");
            }
            }
            }
    
    I did it. Thank you for your help.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 12, 2017
  4. Offline

    MightyOne

    You did everything correct. What is the problem?
     
  5. Why are you using "§" over "ChatColor?
     
Thread Status:
Not open for further replies.

Share This Page