Solved Help With Sign Manipulation

Discussion in 'Plugin Development' started by boysnnoco, Nov 21, 2013.

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

    boysnnoco

    This is the code I have, the top part works fine and dandy but the interact event doesnt seem to be firing any help?

    Code:
    package me.boysnnoco.utils;
     
    import me.boysnnoco.CheesyKits.Main;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    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 SignListener implements Listener {
        public Main plugin;
        public SignListener(Main instance) {
            plugin = instance;
        }
        @EventHandler
        public void onSignCreate(SignChangeEvent sign){
            //Player player = sign.getPlayer();
            if(sign.getLine(0).equalsIgnoreCase("warp")){
                sign.setLine(0, "");
                String test = sign.getLine(1);
                sign.setLine(1,ChatColor.BLUE +"Warp");
                sign.setLine(2,ChatColor.LIGHT_PURPLE+test);
                sign.setLine(3, "");
            }
        }
     
    //Need Help Here
    @EventHandler(ignoreCancelled =true) // Just in case it is getting cancelled somewhere else
        public void onSignClick(PlayerInteractEvent event){
            Player player = (Player)event.getPlayer();
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK){
                if(event.getClickedBlock().getState() instanceof Sign){
                    Sign sign = (Sign) event.getClickedBlock().getState();
                    if(sign.getLine(1).equals(ChatColor.BLUE+"Warp")){
                        if(sign.getLine(2).equalsIgnoreCase(ChatColor.LIGHT_PURPLE+ "arena")){
                            player.teleport(new Location(player.getWorld(),0,10,0));
                        }else{
                            //Debug to see if sign.getLine(2) wasnt working
                            player.sendMessage("Not arena");
                        }
                    }else{
                      //Debug to see if the text was warp
                        player.sendMessage("No warp!");
                    }
                }else{
                    //Debug to see if it was a sign
                    player.sendMessage("Debug not sign");
                }
            }else{
                //Debug sure it was a right click (or left click)
                player.sendMessage("MUST RIGHTCLICK")
            }
        }
     
    }
    
     
  2. Offline

    adam753

    Have you tried putting in debug messages to check whether the event is actually being fired at all, and if so, what part of the code is being reached?
    Are any errors showing up in the console?
    Wild guess, but are you aware that lines of a sign are zero-indexed? The top line of a sign is line 0, but not line 1.
     
  3. Offline

    JRL1004

    adam753 boysnnoco I feel like you are both missing the obvious. He does not have his events registered (or even an onEnable to register them in).
     
  4. Offline

    jboy44

    JRL1004
    That isn't his main class. He stated in his post that some of his code worked, which wouldn't even be possible if this was his only class considering he doesn't even have an "extends JavaPlugin" at the top.
     
  5. Offline

    JRL1004

    Thanks for telling me, jboy44, I wasn't aware of that.

    boysnnoco Would changing
    Code:java
    1. if(event.getClickedBlock().getState() instanceof Sign){

    to
    Code:java
    1. if(event.getClickedBlock().getType() == Material.WALL_SIGN || event.getClickedBlock().getType() == Material.SIGN_POST){

    make a difference?
     
  6. Offline

    boysnnoco

    This is just a single class of mine, I have a main class where I register the events :p

    I just tried this and it still didn't seem to make a differnce the event seems like it isnt getting fired :/

    Code:java
    1. @EventHandler(ignoreCancelled =true)
    2. public void onSignClick(PlayerInteractEvent event){
    3. Player player = (Player)event.getPlayer();
    4. player.sendMessage("DEBUG FIRED");
    5. if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK){
    6. if(event.getClickedBlock().getType().equals(Material.WALL_SIGN)){
    7. Sign sign = (Sign) event.getClickedBlock().getState();
    8. if(sign.getLine(1).equals(ChatColor.BLUE+"Warp")){
    9. if(sign.getLine(2).equalsIgnoreCase(ChatColor.LIGHT_PURPLE+ "arena")){
    10. player.teleport(new Location(player.getWorld(),0,10,0));
    11. }else{
    12. player.sendMessage("Not arena");
    13. }
    14. }else{
    15. player.sendMessage("No warp!");
    16. }
    17. }else{
    18. player.sendMessage("Debug not sign");
    19. }
    20. }else{
    21. player.sendMessage("MUST RIGHTCLICK");
    22. }
    23. }

    I added the debug and it seems as though the event isn't even firing there isn't any errors nothing o_o any help?

    Here's my main class:
    Code:java
    1. package me.boysnnoco.CheesyKits;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import me.boysnnoco.Commands.CommandAbsorber;
    6. import me.boysnnoco.Commands.CommandArcher;
    7. import me.boysnnoco.Commands.CommandFisherman;
    8. import me.boysnnoco.Commands.CommandGrandpa;
    9. import me.boysnnoco.Commands.CommandKanga;
    10. import me.boysnnoco.Commands.CommandKit;
    11. import me.boysnnoco.Commands.CommandPhantom;
    12. import me.boysnnoco.Commands.CommandPing;
    13. import me.boysnnoco.Commands.CommandPvp;
    14. import me.boysnnoco.Commands.CommandRod;
    15. import me.boysnnoco.Commands.CommandStomper;
    16. import me.boysnnoco.Commands.CommandStrafer;
    17. import me.boysnnoco.Commands.CommandViper;
    18. import me.boysnnoco.Commands.CommandWitherman;
    19. import me.boysnnoco.utils.EntityListeners;
    20. import me.boysnnoco.utils.Lists;
    21. import me.boysnnoco.utils.SignListener;
    22.  
    23. import org.bukkit.plugin.PluginManager;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25.  
    26. public class Main extends JavaPlugin{
    27. public Lists list;
    28. public Main(){
    29. list = new Lists(plugin);
    30. }
    31. public Main plugin;
    32. public Logger logger = Logger.getLogger("Minecraft");
    33. public String noPerm = "You do not have permission for this kit!";
    34. public void onEnable(){
    35. logger.info("CheesyKits has been enabled!");
    36. PluginManager pm = getServer().getPluginManager();
    37. pm.registerEvents(new PlayerListeners(this), this);
    38. pm.registerEvents(new InventoryListener(this), this);
    39. pm.registerEvents(new EntityListeners(this), this);
    40. //Event Class
    41. pm.registerEvents(new SignListener(this), this);
    42. registerCommands();
    43. }
    44. public void onDisable(){
    45. logger.info("CheesyKits has been disabled!");
    46. }
    47. public static String getMessage(final String[] args, final int start){
    48. final StringBuilder stringbuilder = new StringBuilder();
    49.  
    50. for(int i = start; i < args.length; i++){
    51. if(i != start){
    52. stringbuilder.append(" ");
    53. }
    54. stringbuilder.append(args[I]);[/I]
    55. [I] }[/I]
    56. [I] return stringbuilder.toString();[/I]
    57. [I] }[/I]
    58. [I] public void registerCommands(){[/I]
    59. [I] getCommand("pvp").setExecutor(new CommandPvp(this));[/I]
    60. [I] getCommand("kit").setExecutor(new CommandKit(this));[/I]
    61. [I] getCommand("absorber").setExecutor(new CommandAbsorber(this));[/I]
    62. [I] getCommand("archer").setExecutor(new CommandArcher(this));[/I]
    63. [I] getCommand("fisherman").setExecutor(new CommandFisherman(this));[/I]
    64. [I] getCommand("kangaroo").setExecutor(new CommandKanga(this));[/I]
    65. [I] getCommand("grandpa").setExecutor(new CommandGrandpa(this));[/I]
    66. [I] getCommand("ping").setExecutor(new CommandPing(this));[/I]
    67. [I] getCommand("rod").setExecutor(new CommandRod(this));[/I]
    68. [I] getCommand("stomper").setExecutor(new CommandStomper(this));[/I]
    69. [I] getCommand("phantom").setExecutor(new CommandPhantom(this));[/I]
    70. [I] getCommand("viper").setExecutor(new CommandViper(this));[/I]
    71. [I] getCommand("witherman").setExecutor(new CommandWitherman(this));[/I]
    72. [I] getCommand("strafer").setExecutor(new CommandStrafer(this));[/I]
    73. [I] }[/I]
    74. [I]}[/I]
    75. [I][/I]


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

    JRL1004

    boysnnoco Are any of the debug messages you added being output?
     
  8. Offline

    jboy44

    JRL1004
    That wouldn't prevent the event from not firing.
    boysnnoco
    Try to change this in your SignChangeEvent:
    Code:java
    1. sign.setLine(2,ChatColor.LIGHT_PURPLE+test);

    To this:
    Code:java
    1. sign.setLine(2,ChatColor.LIGHT_PURPLE+ "arena");

    I noticed it doesn't match this if statement in your InteractEvent:
    Code:java
    1. if(sign.getLine(2).equalsIgnoreCase(ChatColor.LIGHT_PURPLE+ "arena")){
     
  9. Offline

    boysnnoco

    ok ill try it :)

    yay it worked!! Thanks so much!
     
  10. Offline

    jboy44

    boysnnoco
    You're welcome! I'm glad it worked.
    Make sure to mark the thread as "solved"!
     
Thread Status:
Not open for further replies.

Share This Page