sign permissoin

Discussion in 'Plugin Development' started by skullboneslayer, Mar 9, 2014.

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

    skullboneslayer

    ok so i am adding a permission so not everyone can create a heal sign here is my code
    Code:
    package me.skull.skullheal;
     
    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 boolean onSignChange(SignChangeEvent e) {
                    if (e.getLine(0).equalsIgnoreCase("[skullHeal]")) {
                        if (!Player.hasPermission("skull.skullheal.sign.heal")) {
                            Player.sendMessage(ChatColor.RED + "You dont have permission to do this!");
                            return true;
                        }
                            e.setLine(0, "§4[skullHeal]");
                            e.setLine(1, "§4Click here");
                            e.setLine(2, "§4to get healed!");
                    }
            }
         
            @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("§4[SkullHeal]")) {
                                  e.getPlayer().setHealth(20);
                                  e.getPlayer().sendMessage(ChatColor.GREEN + "[SkullHeal] Was created by: skullboneslayer!");
                            }
                    }
            }
    }
    alright so there is my code but it keeps giving me a error ok the player.haspermission and player.sendmessage so if anyone can help that would be greate!
     
  2. Offline

    Gater12

  3. Offline

    Dragonphase

    skullboneslayer

    Replace:
    Code:java
    1. Player.hasPermission

    to:
    Code:java
    1. e.getPlayer().hasPermission


    and replace:
    Code:java
    1. Player.sendMessage

    to:
    Code:java
    1. e.getPlayer().sendMessage


    in your SignChangeEvent.
     
  4. Offline

    skullboneslayer

    Gater12 Dragonphase thanks one mroe thing how do i set it so if they dont have permission the sign will read Dont Have Permission
     
  5. Offline

    Gater12

    Dragonphase likes this.
  6. Offline

    Heirteir

    skullboneslayer
    add an else statement and change the lines to "you don't have permission"
    Simple.
     
  7. Offline

    skullboneslayer

    Heirteir

    hows this?

    Code:
     @EventHandler
            public boolean onSignChange(SignChangeEvent e) {
                    if (e.getLine(0).equalsIgnoreCase("[skullHeal]")) {
                        if (!e.getPlayer().hasPermission("skull.skullheal.sign.heal")) {
                            return true;
                        }
                            e.setLine(0, "§4[skullHeal]");
                            e.setLine(1, "§4Click here");
                            e.setLine(2, "§4to get healed!");
                    }else{
                        e.setLine(0, "§4You");
                        e.setLine(1, "§4Dont");
                        e.setLine(2, "§4Have");
                        e.setLine(3, "§4Permission");
                    }
                    return true;
            }
    also how do i make the
    §
    in windows

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

    Heirteir

    skullboneslayer
    Code:java
    1. e.setLine(0, ChatColor.translateAlternateColorCodes('&', "&4You");

    with that instead of doing the symbol just do &

    Actuall it's
    Code:java
    1. public void onSignChange(SignChangeEvent e) {
    2. if (e.getLine(0).equalsIgnoreCase("[skullHeal]")) {
    3. if (e.getPlayer().hasPermission("skull.skullheal.sign.heal")) {
    4. e.setLine(0, "§4[skullHeal]");
    5. e.setLine(1, "§4Click here");
    6. e.setLine(2, "§4to get healed!");
    7. }else{
    8. e.setLine(0, "§4You");
    9. e.setLine(1, "§4Dont");
    10. e.setLine(2, "§4Have");
    11. e.setLine(3, "§4Permission");
    12. }
    13. }
     
  9. Offline

    skullboneslayer

    Heirteir were in my code do i put thta?
     
  10. Offline

    Heirteir

    skullboneslayer
    i just gave you an example
    instead of doing
    Code:java
    1. e.setLine(3, "§4Permission");

    Do
    Code:java
    1. e.setLine(3, ChatColor.translateAlternateColorCodes('&', "&4Permission"));
     
  11. Offline

    Gater12

    Heirteir
    I don't see any reason to do that...
    His first method would do just fine.
     
  12. Offline

    Heirteir

    Gater12
    I am just making the code shorter and easier to read.
    I like to make code look like a work of art.
    Not just completing the task
    it also makes it easier to read :l
    and actually it wouldn't because it would be returning before it could execute the change.
    His code would make so if they put something other than "[skullheal]" it would change it to "you dont have permission"
     
  13. Offline

    skullboneslayer

    Heirteir Gater12 ok so i did it but if you dont have permission on the sign it dosent say you dont have permission

    what did i do rong?

    Code:
    public boolean onSignChange(SignChangeEvent e) {
                    if (e.getLine(0).equalsIgnoreCase("[skullHeal]")) {
                        if (!e.getPlayer().hasPermission("skull.skullheal.sign.heal")) {
                            return true;
                        }
                            e.setLine(0, "§4[skullHeal]");
                            e.setLine(1, "§4Click here");
                            e.setLine(2, "§4to get healed!");
                    }else{
                        e.setLine(0, "§4You");
                        e.setLine(1, "§4Dont");
                        e.setLine(2, "§4Have");
                        e.setLine(3, "§4Permission");
                    }
                    return true;
     
  14. Offline

    Gater12

    skullboneslayer
    Remove the else block. It only happens if the first line is not [skullHeal] you would want to put that in the if permission check block (Since you are checking if the player doesn't have permission). Why is the method type boolean. It should be void.
     
  15. Offline

    Heirteir

    skullboneslayer
    Change your method to this
    Code:java
    1. public void onSignChange(SignChangeEvent e) {
    2. if (e.getLine(0).equalsIgnoreCase("[skullHeal]")) {
    3. if (e.getPlayer().hasPermission("skull.skullheal.sign.heal")) {
    4. e.setLine(0, "§4[skullHeal]");
    5. e.setLine(1, "§4Click here");
    6. e.setLine(2, "§4to get healed!");
    7. }else{
    8. e.setLine(0, "§4You");
    9. e.setLine(1, "§4Dont");
    10. e.setLine(2, "§4Have");
    11. e.setLine(3, "§4Permission");
    12. }
    13. }
     
  16. Offline

    skullboneslayer

    Heirteir Gater12 omg wow i didnt even notice that its boolean and not void is this better?

    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent e) {
    3. if (e.getLine(0).equalsIgnoreCase("[skullHeal]")) {
    4. if (!e.getPlayer().hasPermission("skull.skullheal.sign.heal")) {
    5. e.setLine(0, "§4[skullHeal]");
    6. e.setLine(1, "§4Click here");
    7. e.setLine(2, "§4to get healed!");
    8. }else{
    9. e.setLine(0, "§4You");
    10. e.setLine(1, "§4Dont");
    11. e.setLine(2, "§4Have");
    12. e.setLine(3, "§4Permission");
    13. }
    14. }
    15.  
     
  17. Offline

    Gater12

  18. Offline

    Heirteir

  19. Offline

    skullboneslayer

    Gater12 alright it is removed i am gonna test it now and tell you all how it goes :D

    @Heirteir i did like now i did

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

    Heirteir

  21. Offline

    skullboneslayer

    im testing it now

    it did not work now whene i place a sign with the command on it View attachment 18482 i get this

    Heirteir it did not work

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

    Heirteir

    skullboneslayer
    dude you need to inset } somewhere...
    What are you using to edit this???
    eclipse will tell you that...
     
  23. Offline

    skullboneslayer

  24. Offline

    coreymichealroy

    Theres a error on line 27...
     
  25. Offline

    GameplayJDK

  26. Offline

    skullboneslayer

    GameplayJDK thank tht seemed to have worked :)

    ill let you know if there is a error now

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

    coreymichealroy

    Wow, did I seriously just figure that out lol
     
  28. Offline

    skullboneslayer

    coreymichealroy what are you talking about what did you just figure out?
     
Thread Status:
Not open for further replies.

Share This Page