Development Assistance SignChangeEvent plz help!

Discussion in 'Plugin Help/Development/Requests' started by Dara007, Mar 29, 2015.

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

    Dara007

    OK. im trying to make a sign plugin.and i researched and i found out that i should use OnSignChange method.
    but my problem is its not workin.even most simple things wont work.

    Code:
    package com.Dara.Sign;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class Main extends JavaPlugin {
       
        public void OnEnable(){
            System.out.println("enabled");
           
        }
            @EventHandler
        public void onSignChange(SignChangeEvent event){
           
            Player p =event.getPlayer();
                p.sendMessage("yoohoo");
               
               
                   
        }
       
       
    }
    
    this is just a simple code . i wrote that to check if even my OnSignChange works or not!!!

    and it didnt work.
    plz help me im a begginer in these stuff.
    i already learned VB,c#,C++ and javascript but i just started java .
    plz help!

    and i forgot to say . i use 1.8.3 bukkit api.is that the problem?

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Mar 29, 2015
  2. Offline

    FisheyLP

    Use code/syntax tags to make your code better readable:
    Code:
    [syntax=java]
    
    Your code
    
    [/syntax]
    .
    You didn't register the Listener.
    Don't print out "enabled". Bukkit already does that for every plugin!
     
  3. Offline

    Dara007

    how to register listener?

    Code:java
    1.  
    2. package com.Dara.Sign;
    3.  
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.block.SignChangeEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9.  
    10. public class Main extends JavaPlugin {
    11.  
    12. public void OnEnable(){
    13. System.out.println("enabled");
    14.  
    15. }
    16. @EventHandler
    17. public void onSignChange(SignChangeEvent event){
    18.  
    19. Player p =event.getPlayer();
    20. p.sendMessage("yoohoo");
    21.  
    22.  
    23.  
    24. }
    25.  
    26.  
    27. }
    28.  


    implements Listener?
    if u mean that i actually tried it before but didnt work
     
  4. Online

    timtower Moderator Moderator

  5. Offline

    FisheyLP

  6. Offline

    Dara007

    tnx but the wiki i just showing the code. can u guys explain why i should do this. i mean something about it and what exactly i should do.
    tnx for ur help.
     
  7. Offline

    FisheyLP

  8. Offline

    Dara007

    tnx dude i did that this is my code but it still wont working . i place a sign but nothing happens.

    SignListener class :

    Code:java
    1.  
    2. package com.Dara.Sign;
    3.  
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.block.SignChangeEvent;
    7.  
    8. public class SignListener implements Listener{
    9.  
    10. @EventHandler
    11. public void OnSignChange(SignChangeEvent event){
    12.  
    13. event.getPlayer().sendMessage("You have finaly done it");
    14.  
    15. }
    16.  
    17. }
    18.  



    my main class:
    Code:java
    1.  
    2. package com.Dara.Sign;
    3.  
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6.  
    7. public class Main extends JavaPlugin{
    8.  
    9. public void OnEnable(){
    10.  
    11. getServer().getPluginManager().registerEvents(new SignListener(), this);
    12.  
    13. }
    14.  
    15.  
    16.  
    17. }
    18.  
     
  9. Offline

    FisheyLP

    lol thats strange. Are there any errors in the console?
     
  10. Offline

    Dara007

    no there isnt
    could there be a problem with my imports or 1.8.3 api?
    i mean its a simple code but it wont work
     
  11. Offline

    FisheyLP

    SignChangeEvent fires, if you press the Done button after changing the text on the sign...
     
  12. Offline

    Dara007

    do you mean i should another method?
    can u tell what it is.
    and tnx for ur fast answering .
     
  13. Offline

    FisheyLP

    If you want to detect, if a block(sign) is placed, use the BlockPlaceEvent.
    If you want to detect, if sign text is changed, use the SignChangeEvent
     
  14. Offline

    Dara007

    im going to make a sing XpShop plugin.its a shop but uses xp .which method u guys think i should use?
    btw i wrote a code with BlockPlaceEvent but its not working.

    listener class:
    Code:java
    1.  
    2. package com.Dara.Sign;
    3.  
    4. import org.bukkit.Material;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.BlockPlaceEvent;
    8.  
    9. public class SignListener implements Listener{
    10.  
    11. @EventHandler
    12. public void OnBlockPlace(BlockPlaceEvent event){
    13.  
    14. if (event.getBlockPlaced().getType().equals(Material.TNT)) {
    15. event.getBlockPlaced().setType(Material.AIR);
    16. }
    17.  
    18. }
    19.  
    20. }
    21.  
    22.  


    main class:
    Code:java
    1.  
    2. package com.Dara.Sign;
    3.  
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6.  
    7. public class Main extends JavaPlugin{
    8.  
    9. public void OnEnable(){
    10.  
    11. getServer().getPluginManager().registerEvents(new SignListener(), this);
    12.  
    13. }
    14.  
    15.  
    16.  
    17. }
    18.  
     
  15. Offline

    FisheyLP

    Thats strange. I tested your code and it worked. Do you have a correct plugin.yml?
     
  16. Offline

    Dara007

    yes i think so.

    plugin yml:
    name: Sign
    main: com.Dara.Sign.Main
    version: 1.0


    after i export this in plugin folder i run my 1.8.3 server.then i launch 1.8optfine and join the server.after i place a tnt i expect to it change to air(nothing) but like always it not works.it just stay like that.can be problem because of the version i play with?can this be because im oped in server?
     
  17. Dara try doing this
    Code:
    @EventHandler
    public void onSignChangeEvent(SignChangeEvent event) {
    Player player = event.getPlayer();
    if(event.getLine(0).contains("Hello")) {
    player.sendMessage(ChatColor.GREEN + "You did it!");
    }
    
     
  18. Offline

    Dara007

    it wont work.
     
  19. Offline

    2008Choco

    @Dara007
    In your onEnable method, put the following line of code to register events:
    Code:
    getServer().getPluginManager().registerEvents(this, this);
    The final onEnable method in your case should be:
    Code:
    @Override
    public void onEnable(){
        getServer().getPluginManager().registerEvents(this, this);
    }
    And also, something else you'll definitely need:
    Code:
    public class Main extends JavaPlugin implements Listener{
    As a whole, your entire main class should look like this:
    Code:
    package com.Dara.Sign;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
    
        @Override
        public void OnEnable(){
            getServer().getPluginManager().registerEvents(this, this);
        }
    }
    
    Try and mess around with the Bukkit API. If you can't register events, you should read up in the JavaDocs:
    hub.spigotmc.org/javadocs/bukkit
    Or you can also read up on.. well... at this rate... all of the wiki page on Bukkit Documentation. Don't get me wrong, I'm still new too, but this is pretty basic stuff.
     
    Last edited: Mar 30, 2015
  20. Offline

    FisheyLP

    I have found why its not working. You wrote the method like this:
    OnEnable
    it should start with a lowercased o:
    onEnable
     
  21. Offline

    Dara007

    thank u very much . i cant believe but its actually workin.thank u very much.Luv Ya
     
    FisheyLP likes this.
  22. Offline

    Dara007

    I was making a xpshop as i said so this is my listener codebut i have a problem.if i click air or other things and stuff there will be an error in comsole.why?

    listener:
    Code:java
    1.  
    2. package com.Dara.Sign;
    3.  
    4.  
    5.  
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.block.Sign;
    9. import org.bukkit.enchantments.Enchantment;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.block.SignChangeEvent;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15.  
    16.  
    17. public class SignListener implements Listener{
    18.  
    19. @EventHandler
    20. public void OnSignChange(SignChangeEvent event){
    21.  
    22. if(event.getLine(0).equalsIgnoreCase("[SCWSHOP]")){
    23. if(event.getPlayer().hasPermission("scw.creatsign")){
    24. event.setLine(0,"§2[§6SCW§4SHOP§2]");
    25. }
    26.  
    27. }
    28.  
    29. return ;
    30.  
    31. }
    32. @EventHandler
    33. public void OnPlayerInteract(PlayerInteractEvent e){
    34. Action action=e.getAction();
    35. Block block=e.getClickedBlock();
    36. if(block.getType().equals(Material.SIGN_POST ) || block.getType().equals(Material.WALL_SIGN ) ){
    37. if(action==Action.RIGHT_CLICK_BLOCK){
    38. Sign sign=(Sign) block.getState();
    39. if(sign.getLine(0).equalsIgnoreCase("§2[§6SCW§4SHOP§2]")){
    40. if(sign.getLine(1).equals("")){
    41. e.getPlayer().sendMessage("§6Please Enter Enchantment Level");
    42. }
    43. int lvl = Integer.parseInt(sign.getLine(1));
    44. if(sign.getLine(2).equalsIgnoreCase("")){
    45. e.getPlayer().sendMessage("§6lease Enter Enchantment ID");
    46.  
    47. }
    48. Enchantment id = Enchantment.getByName(sign.getLine(2));
    49. if(sign.getLine(3).equals("")){
    50. e.getPlayer().sendMessage("§6Please Enter Xp Price(Level)");
    51. }
    52. int xp = Integer.parseInt(sign.getLine(3));
    53. int playerxp= e.getPlayer().getLevel();
    54. if(playerxp==xp || playerxp>xp){
    55. int newxp= playerxp-xp;
    56. e.getPlayer().setLevel(newxp);
    57. e.getPlayer().getInventory().getItemInHand().addEnchantment(id,lvl);
    58.  
    59. }
    60. else{
    61. e.getPlayer().sendMessage("§6You Dont Have Enough Experience");
    62. }
    63. }
    64. }
    65. }
    66. return ;
    67. }
    68. }
    69.  
    70.  



    the error is"could not pass PlayerInteractEvent to Sign v1.0"
    my plugin name is sign and version is 1.0 but what is wrong with player interact event . imean everything is working fine except this error.
     
  23. Offline

    2008Choco

    @Dara007 You put
    Code:
                if(action==Action.RIGHT_CLICK_BLOCK){
    which is right, but I don't see an else. What happens if it ISN'T a right click event.

    Put this as an else for the if statement above:
    Code:
    else{
        return;
    }
    That should fix it
     
  24. Offline

    FisheyLP

    It seems like you have no idea what youre doing :rolleyes:
    return; cancels a method, not an event.
    If it ISN'T a right click, then nothing happens because he only checks IF it is a right click
     
  25. Offline

    2008Choco

    Aha it was only a guess, @FisheyLP xD Worth a shot I suppose, amirite?
     
Thread Status:
Not open for further replies.

Share This Page