Sign click event

Discussion in 'Plugin Development' started by dkfredebang, Oct 19, 2013.

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

    dkfredebang

    I just don't get it why this doesn't work. I have no errors in the code but it doesn't wanna load the plugin, did I do the plugin.yml wrong?

    Code:java
    1. @EventHandler
    2. public void playerInteractEvent2(PlayerInteractEvent event) {
    3.  
    4. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5.  
    6. if (event.getClickedBlock().getType() == Material.SIGN) {
    7. Sign sign = (Sign) event.getClickedBlock().getState();
    8. Player player = event.getPlayer();
    9.  
    10. if (sign.getLine(0).equalsIgnoreCase("test")) {
    11. sign.setLine(0, ChatColor.DARK_RED + "[Test]");
    12. player.sendMessage(ChatColor.DARK_RED+ "[Testing] " + ChatColor.BLUE + "Hello");
    13. }
    14. }
    15. }
    16. }

    EDIT: Plugin.yml
    Code:
    name: TestPlugin
    main: me.FroddeB.Youtube
    version: 1.0
    description: >
                Test Plugin, Right click a Sign.
    commands:
      test:
        description: Hello
     
  2. Have you registered Event?
     
  3. Offline

    Seadragon91

    You are checking the wrong material. Use SIGN_POST and WALL_SIGN. SIGN is for itemstacks
     
  4. Offline

    dkfredebang

    Didn't work..

    This is the loading error. I just cant find anywhere in the error where it says why..
    Code:
    19.10 01:28:40 [Server] INFO ... 9 more
    19.10 01:28:40 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
    19.10 01:28:40 [Server] INFO at java.lang.Class.forName(Unknown Source)
    19.10 01:28:40 [Server] INFO at java.lang.Class.forName0(Native Method)
    19.10 01:28:40 [Server] INFO at java.lang.ClassLoader.loadClass(Unknown Source)
    19.10 01:28:40 [Server] INFO at java.lang.ClassLoader.loadClass(Unknown Source)
    19.10 01:28:40 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
    19.10 01:28:40 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
    19.10 01:28:40 [Server] INFO at java.net.URLClassLoader.findClass(Unknown Source)
    19.10 01:28:40 [Server] INFO at java.security.AccessController.doPrivileged(Native Method)
    19.10 01:28:40 [Server] INFO at java.net.URLClassLoader$1.run(Unknown Source)
    19.10 01:28:40 [Server] INFO at java.net.URLClassLoader$1.run(Unknown Source)
    19.10 01:28:40 [Server] INFO Caused by: java.lang.ClassNotFoundException: me.FroddeB.Youtube
    19.10 01:28:40 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    19.10 01:28:40 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:393)
    19.10 01:28:40 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.init(DedicatedServer.java:107)
    19.10 01:28:40 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedPlayerList.<init>(SourceFile:11)
    19.10 01:28:40 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerList.<init>(PlayerList.java:56)
    19.10 01:28:40 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.CraftServer.<init>(CraftServer.java:217)
    19.10 01:28:40 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugins(CraftServer.java:239)
    19.10 01:28:40 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    19.10 01:28:40 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    19.10 01:28:40 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
    19.10 01:28:40 [Server] INFO org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: me.FroddeB.Youtube
    19.10 01:28:40 [Server] SEVERE Could not load 'plugins/TestPlugin.jar' in folder 'plugins'
     
  5. Offline

    user_90854156

    Your plugin.yml is wrong.
    The main should be like this
    me.name.youtube.NAME OF THE MAINCLASS

    Try using this (if your main class is named youtube):


    Code:
    name: TestPlugin
    main: me.FroddeB.Youtube.youtube
    version: 1.0
    description: Test Plugin, Right click a Sign.
    
    commands:
        test:
            description: Hello
     
  6. Offline

    Seadragon91

    Your main point is wrong. I has to be "package path and class name that extends JavaPlugin.
    Example:
    package: me.FroddeB.Youtube
    class name: Youtube
    main point: me.FroddeB.Youtube.Youtube
     
  7. Offline

    tommykins20

    Is the main class for your plugin (where the onEnable() method is where you also register the listener) named Youtube?
    Is it also in the me.FroddeB package?

    EDIT: Seadragon91 beat me lol I hope my message might help anyway :p
     
  8. Offline

    dkfredebang

    So like this?
    Code:
    name: TestPlugin
    package: me.FroddeB.Youtube
    class name: TestPlugin
    main: me.FroddeB.Youtube.TestPlugin
    version: 1.0
    description: >
                Test Plugin, Right click a Sign.
    commands:
      test:
        description: Hello
     
  9. Offline

    Rocoty

    if you remove the package and class name keys
     
    dkfredebang likes this.
  10. Offline

    dkfredebang

    Thank you now it loads except it doesn't do anything :/ (Sorry I am new to Java and Bukkit Plugins)
     
  11. Offline

    Seadragon91

    Did you register the event?
     
  12. Offline

    tommykins20

    Register the listener you mean?


    Also, OP, I recommend checking out some online Java beginning tutorials like thenewboston. You may also consider purchasing a Java book which may help you start out.
    I learnt Java really easily because of prior knowledge to similar languages and syntax. You also gotta have some Java knowledge before starting Bukkit plugins.
    I hope you get your plugin working and good luck with your future endeavours.
     
  13. Offline

    dkfredebang

    Sorry I don't get that, how do I register the event? xD (Sorry because of my newbie attitude)

    EDIT: is it like?
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, this);
     
  14. Offline

    tommykins20

    Yes. But the first paremeter is the listener and the second is the plugin. So keep "this" for the second paremeter if this is being called in the onEnable() method. Change the first paremeter to an instance of the listener class or keep it to "this" if the listener is part of the same class.

    EDIT: Take a look at this.

    EDIT 2: Sorry I keep editing it like 6 times, I kept pasting a facebook link instead of the desired one xD
     
    dkfredebang likes this.
  15. Offline

    dkfredebang

    Couldn't make the plugin work even after registering it, thanks anyways guys!
     
  16. Offline

    user_90854156

    I got it to work.
    The "setline" doesn't work, you must remove the ChatColor.DARK_RED. Also, you must take an event of it's own.
    And yeah, your plugin.yml didn't work either.

    Code:java
    1. public void onEnable() {
    2. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    3. }
    4.  
    5. @EventHandler
    6. public void playerInteractEvent(PlayerInteractEvent event) {
    7. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    8. if (event.getClickedBlock().getState() instanceof Sign) {
    9. Sign sign = (Sign) event.getClickedBlock().getState();
    10. Sign s = (Sign) event.getClickedBlock().getState();
    11. if (s.getLine(0).equalsIgnoreCase("test")) {
    12. sign.setLine(0, "§3[Test]"); //This part must be registered as it's own event for the text to actually change
    13. event.getPlayer().sendMessage(ChatColor.DARK_RED + "[Testing] " + ChatColor.BLUE + "Hello");
    14. }
    15. }
    16. }
    17. }
    18. }


    Code:
    name: TestPlugin
    main: me.mrtang.testplugin.TestPlugin
    version: 1.0
    description: Test Plugin, Right click a Sign.
     
    commands:
        test:
            description: Hello
    Try fix up your code, and try again.
     
  17. Offline

    dkfredebang

    Thank you for helping me!
     
  18. Offline

    lewysryan

    got the sign update to work but you have to get 2 event handlers.

    Code:java
    1. @EventHandler
    2. public void playerInteractEvent(PlayerInteractEvent event) {
    3. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. if (event.getClickedBlock().getState() instanceof Sign) {
    5. Sign sign = (Sign) event.getClickedBlock().getState();
    6. Sign s = (Sign) event.getClickedBlock().getState();
    7. if (s.getLine(0).equalsIgnoreCase("test")) {
    8. sign.setLine(0, "§3[Test]");
    9. sign.update();
    10. event.getPlayer().sendMessage(ChatColor.DARK_RED + "[Testing] " + ChatColor.BLUE + "Hello");
    11. }
    12. }
    13. }
    14. }
    15.  
    16. @EventHandler
    17. public void playerInteractEvent(PlayerInteractEvent event) {
    18. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    19. if (event.getClickedBlock().getState() instanceof Sign) {
    20. Sign sign = (Sign) event.getClickedBlock().getState();
    21. Sign s = (Sign) event.getClickedBlock().getState();
    22. if (s.getLine(0).equalsIgnoreCase("§3[Test]")) {
    23. event.getPlayer().sendMessage(ChatColor.DARK_RED + "[Testing] " + ChatColor.BLUE + "Hello");
    24. }
    25. }
    26. }
    27. }
     
Thread Status:
Not open for further replies.

Share This Page