Solved Need Help With Signs!!!

Discussion in 'Plugin Development' started by Mr_toaster111, Apr 23, 2014.

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

    Mr_toaster111

    So im trying to make a plugin where when you create a sign with the first line "Ws" it tells you that you created it just to make sure its working. whenever i try it nothing happens, but the plugin still loads. Heres the code.

    Code:java
    1. package me.toaster;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.SignChangeEvent;
    8. import org.bukkit.plugin.PluginManager;
    9.  
    10. public class main implements Listener{
    11.  
    12.  
    13. PluginManager pm = Bukkit.getServer().getPluginManager();
    14.  
    15.  
    16. public static Bukkit plugin;
    17.  
    18. public void BukkitListener(Bukkit instance) {
    19. plugin = instance;
    20. }
    21. @EventHandler
    22. public void onSignCreate(SignChangeEvent sign){
    23. Player player = sign.getPlayer();
    24. if(sign.getLine(0).equalsIgnoreCase("Ws")){
    25. player.sendMessage("Sign Worked");
    26. sign.setLine(0, "WaterShow");
    27. }
    28. }
    29. }
    30.  
     
  2. Offline

    TGRHavoc

    Mr_toaster111
    You need to register the events. Create a "onEnable" method and add the following:
    Code:java
    1. pm.registerEvents(this, this);
     
  3. Offline

    Mr_toaster111

    I added it still nothing
    :/
     
  4. Offline

    xBlazeTECH


    Hello Mr. Toaster,
    It seems to me that you are not doing anything when the plugin is enabled, or disabled. In order to register events, the events need to be registered onEnable. Here is how I believe you should be writing your code! ;)
    Code:java
    1. /*
    2. ** I would recommend placing this plugin in a directory lower than what you have here.
    3. ** For example: package me.toaster.pluginname;
    4. */
    5. package me.toaster;
    6.  
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.SignChangeEvent;
    11.  
    12. public class main implements Listener{
    13.  
    14. @Override
    15. public void onEnable() {
    16. getServer().getPluginManager().registerEvents(this,this);
    17. }
    18.  
    19. @EventHandler
    20. public void onSignChange(SignChangeEvent event){
    21. Player player = event.getPlayer();
    22. if(event.getLine(0).equalsIgnoreCase("Ws")){
    23. player.sendMessage("Sign Worked");
    24. event.setLine(0, "WaterShow");
    25. }
    26. }
    27. }
     
  5. Offline

    Mr_toaster111

    Thanks for the Reply!, unfortunately i tried creating an onEnable() with the registering in it like you did but again when i tested it, put Ws on the first line it did nothing :( i dont understand why its not working!

    Well i followed a simple Events Video and it worked ;) thx to all contributers!

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

    Seadragon91

    He forgot to add the "extends JavaPlugin" to the "public class main" - line.

    @Mr_toaster111 Please close this thread as solved. Ty
     
Thread Status:
Not open for further replies.

Share This Page