Sign interact problem

Discussion in 'Plugin Development' started by MasterSteve26, Jul 27, 2014.

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

    MasterSteve26

    Hello everyone, i'm having a problem with sign interactions... here's everything i got...
    Code:java
    1. package net.MasterSteve26.listeners;
    2.  
    3. import net.MasterSteve26.main.MultiTP;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.block.SignChangeEvent;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14.  
    15. public class SignListener implements Listener {
    16.  
    17. MultiTP plugin;
    18.  
    19. public SignListener(MultiTP plugin) {
    20. this.plugin = plugin;
    21. }
    22.  
    23. @EventHandler
    24. public void onSignChange(SignChangeEvent e) {
    25. if (e.getLine(0).equalsIgnoreCase("[pvp]")) {
    26. e.setLine(0, "[pvp]");
    27. e.getPlayer().sendMessage("pvp sign created...");
    28. }
    29. }
    30. @EventHandler
    31. public void onPlayerInteract1(PlayerInteractEvent e) {
    32. Player player = e.getPlayer();
    33. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    34. Block b = e.getClickedBlock();
    35. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    36. Sign sign = (Sign) b.getState();
    37. String[] lines = sign.getLines();
    38. if(lines[0].equalsIgnoreCase("[pvp]")) {
    39. player.performCommand("pvp");
    40. }
    41. }
    42. }
    43. }
    44. }
    45.  

    And the main class...
    Code:java
    1. package net.MasterSteve26.main;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.plugin.PluginManager;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. import net.MasterSteve26.commands.MultiTPCommands;
    8. import net.MasterSteve26.listeners.SignListener;
    9.  
    10. public class MultiTP extends JavaPlugin{
    11.  
    12. @Override
    13. public void onDisable() {
    14. System.out.println(ChatColor.RED + "MultiTP plugin has been disabled");
    15. }
    16.  
    17. @Override
    18. public void onEnable() {
    19. System.out.println(ChatColor.GREEN + "MultiTP plugin has been enabled");
    20.  
    21. PluginManager pm = getServer().getPluginManager();
    22.  
    23. pm.registerEvents(new SignListener(this), this);
    24.  
    25. //Commands
    26. getCommand("faq").setExecutor(new MultiTPCommands(this));
    27. getCommand("pvp").setExecutor(new MultiTPCommands(this));
    28.  
    29. //setCommands
    30. getCommand("setpvp").setExecutor(new MultiTPCommands(this));
    31. getCommand("setfaq").setExecutor(new MultiTPCommands(this));
    32.  
    33. }
    34.  
    35. }
    36.  

    the sign change does work perfectly, but the sign interaction thing doesn't work for some reason and i don't have a single clue why it doesn't work... if have something that you need to know to solve this, i'll give it... Thanks :)
     
  2. Offline

    Locercus

    You may wanna change line 35 of the first bit of code to include Material.SIGN in your if statement. You could well be right clicking on a sign your code doesn't consider a sign.
     
  3. Offline

    Necrodoom

    Locercus Material.SIGN is an unplaced sign.
     
  4. Offline

    Locercus

    Ah yes, that's correct. Ignore my comment.
     
  5. Offline

    OracleTarget

    MasterSteve26

    You did this:
    Code:
                   
    String[] lines = sign.getLines();
          if(lines[0].equalsIgnoreCase("[pvp]")) {
               player.performCommand("pvp");
          }
    
    What about just:
    Code:
               
    if(s.getLine(0).equalsIgnoreCase("thing")){
                    //do stuff!
                }
    
     
    crzytlp likes this.
  6. Offline

    crzytlp


    this will work i think
     
  7. Offline

    AoH_Ruthless

    MasterSteve26
    Is the event getting called? (Maybe other conflicting plugins)
    Try adding debug statements in your event.
     
  8. Offline

    MasterSteve26

    AoH_Ruthless not sure how to make debug thing, but i added player.sendMessage("works"); some places at the code and tested if it passes it, but none of them worked so it might be just a conflict with other plugin... how do i prevent conflicts from happening... i'm a beginner so i'm not sure and thanks all the help everyone :)
     
Thread Status:
Not open for further replies.

Share This Page