Solved Simplest Heal Sign plugin not working?

Discussion in 'Plugin Help/Development/Requests' started by NepsName, Jan 5, 2015.

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

    NepsName

    So basically I have this plugin in two different files, shown below.
    I was doing this following one of PogoStick29Dev tutorials, but since they are kinda old, and I am using craftbukkit 1.8, I think that might be the problem, but I have no idea how to fix it.

    So the issue is, when I test this in my localhost server, the plugin is there, with /version Medic it shows, and the console showed it loaded as well, but when I place a sign with just the first line saying [Heal] nothing happens (The text doesn't change color), right clicking obviously doesn't work as well...

    Thanks for reading and I hope someone can help me :)

    Medic.java:

    Code:
    public class Medic extends JavaPlugin {
    
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(new MedicListeners(), this);
        }
    }

    MedicListeners.java:

    Code:
    public class MedicListeners implements Listener {
    
        @EventHandler
        public void onSignChange(SignChangeEvent e) {
            if (e.getLine(0).equalsIgnoreCase("[Heal]")) {
                e.setLine(0, "§3[Heal]");
                e.setLine(1, "§3Click here");
                e.setLine(2, "§3to 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("§3[Heal]")) {
                    e.getPlayer().setHealth(20.0);
                    e.getPlayer().sendMessage(ChatColor.GREEN + "You were healed!");
                }
            }
        }
    }
    Note: All imports and packages are correctly set.
     
  2. Offline

    timtower Moderator Moderator

    Moved to Bukkit alternatives
     
  3. Offline

    nverdier

  4. Offline

    NepsName

    No idea what that is?

    This code is exactly the same as the video, and it worked in the video...
     
  5. Offline

    timtower Moderator Moderator

  6. Offline

    NepsName

    There is not error in the console, simply nothing happens, whenever I place the sign nothing happens.
     
  7. Offline

    timtower Moderator Moderator

    @NepsName Tried debugging it? As in checking where it stops?
     
  8. Offline

    NepsName

  9. Offline

    timtower Moderator Moderator

    @NepsName You put System.out.println in front of if statements with information that will be useful to identify where it stops.
     
  10. Offline

    NepsName

    @timtower Ok, so apparently it stop in the first if statement, my code is now this:

    Code:
    @EventHandler
        public void onSignChange(SignChangeEvent e) {
            System.out.println("stop 1");
            if (e.getLine(0).equalsIgnoreCase("[Heal]")) {
                System.out.println("stop 2");
                e.setLine(0, "§3[Heal]");
                e.setLine(1, "§3Click here");
                e.setLine(2, "§3to get healed!");
            }
        }
    After placing the sign with the first line being [Heal], it says "stop 1" but never says "stop 2"...
    So now I know that if statement is somehow wrong, but I have no idea why or how, any ideas? :|

    This line in specific is wrong, because it works if I remove this if statement:

    Code:
    if (e.getLine(0).equalsIgnoreCase("[Heal]")) {
     
    Last edited: Jan 5, 2015
  11. Offline

    timtower Moderator Moderator

    @NepsName Don't know for sure, never used that event
     
  12. Offline

    nverdier

    @NepsName Are there colors on that line? Try printing out what the first line is, and debug like that.
     
  13. Offline

    NepsName

    @nverdier Got that idea before you said it, and yeah, I had no idea it worked like this, but the console says this:

    [19:01:49] [Server thread/INFO]: §0[Heal]

    Is this a craftbukkit 1.8 thing? In the video it worked without that, can I search for the word [Heal] and make it work even if it has an §0 there? (Basically ignore the color code)

    Now EVEN WORSE, is the fact that after the line is changed to §3[Heal], if I print the line out, the console says this:

    [19:01:49] [Server thread/INFO]: §0§3[Heal]

    Why the hell is it doing this? I mean, the code was "e.setLine(0, "§3[Heal]");" and it managed to put the §0 there? Can I stop it? Can I make it ignore all "§0" it founds in the if statement?
     
    Last edited: Jan 5, 2015
  14. Offline

    nverdier

  15. Offline

    NepsName

    Where do I put that code?

    Ok, I know where to put that code now, and it wasn't ChatColor#stripColor(String) but it was ChatColor.stripColor(String), anyway, that strips all the colors, can I only strip the string "§0" ?
     
    Last edited by a moderator: Jan 5, 2015
  16. Offline

    bwfcwalshy Retired Staff

    @NepsName ChatColor#stopColor() == ChatColor.stripColor().
     
  17. Offline

    NepsName

    @bwfcwalshy Actually, I found an easier way, it works if I do this in all if statements that use the lines:
    Code:
    if (e.getLine(0).replaceAll("§0", "").equalsIgnoreCase("[Heal]")) {
    It sounds stupit that I will have to do this all the time from here on out, whenever I am working with signs, seems like this was a mistake of some sort on craftbukkit 1.8, but I guess it will have to do...

    Thanks for all the help guys
     
Thread Status:
Not open for further replies.

Share This Page