Sign data.

Discussion in 'Plugin Development' started by CevinWa, Oct 31, 2012.

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

    CevinWa

    How do i get the signs line data when i player clicks it. I've tryed with PlayerInteract event but im stuck so any help would be apreciated :D
     
  2. Offline

    Hoolean

    Something like this:
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent event) {
    3. Block clicked = event.getClickedBlock();
    4. Player player = getPlayer();
    5. if(clicked != null) {
    6. if(clicked.getType().equals(Material.SIGN_POST) || clicked.getType().equals(Material.WALL_SIGN) {
    7. Sign sign = (Sign) clicked;
    8. sign.getLine(/* Whatever line number */);
    9. }
    10. }
    11. }
     
    CevinWa likes this.
  3. Offline

    CevinWa

    You are my hero of the day :D

    Just tested. it isn't working.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
    MrBluebear3 likes this.
  4. Offline

    Timr

    Can you show us the code you tried to use?
     
  5. Offline

    CevinWa

    Sure

    @EventHandler
    public void onInteract(PlayerInteractEvent event) {
    Block clicked = event.getClickedBlock();
    Player player = event.getPlayer();
    if(clicked != null) {
    if(clicked.getType().equals(Material.SIGN_POST) || clicked.getType().equals(Material.WALL_SIGN)) {
    Sign sign = (Sign) clicked;
    if (sign.getLine(1).equalsIgnoreCase("Post!")){
    sign.setLine(1, "Done");
    }

    }
    }
    }


    This gives errors on setLine and getLine cuz they're undefined for type Sign

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

    Hoolean

    Can I see your imports?

    There is
    org.bukkit.material.sign <-- You don't want this one

    and
    org.bukkit.block.sign <-- You want this one
     
  7. Offline

    CevinWa

    Haha thanks it worked i had the materail due to my previous attempts. You just ramade the rank as hero of my day :D
    Thank you

    Now i got this error
    Code:
    12:22:27 [ALLVARLIG] Could not pass event PlayerInteractEvent to LootSigns v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:177)
            at net.minecraft.server.ItemInWorldManager.interact(ItemInWorldManager.java:361)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:650)
            at net.minecraft.server.Packet15Place.handle(SourceFile:58)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:282)
            at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:111)
            at net.minecraft.server.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
            at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:569)
            at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:215)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:486)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:419)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:818)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.block.CraftBlock cannot be cast to org.bukkit.block.Sign
            at me.CevinWa.NoDay.Line_Checker.onInteract(Line_Checker.java:50)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339)
            ... 16 more
    12:22:27 [ALLVARLIG] Could not pass event PlayerInteractEvent to NoDay v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:177)
            at net.minecraft.server.ItemInWorldManager.interact(ItemInWorldManager.java:361)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:650)
            at net.minecraft.server.Packet15Place.handle(SourceFile:58)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:282)
            at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:111)
            at net.minecraft.server.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
            at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:569)
            at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:215)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:486)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:419)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:818)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.block.CraftBlock cannot be cast to org.bukkit.block.Sign
            at me.CevinWa.NoDay.Line_Checker.onInteract(Line_Checker.java:50)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339)
            ... 16 more
    >
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
    MrBluebear3 likes this.
  8. Offline

    Hoolean

    Change:
    Code:
    Sign sign = (Sign) clicked;
    to:
    Code:
    Sign sign = (Sign) clicked.getState();
     
  9. Offline

    CevinWa

    I know i figured it out and it worked
     
    MrBluebear3 likes this.
  10. Offline

    Hoolean

    Good good!
     
  11. Offline

    xXSniperzzXx_SD

    Question, i know the lines are like args, so the first line is line[0] but am i able to put something on a 5th line? line[4] and not have it erase when the server restarts?
     
  12. Offline

    Hoolean

    A fifth line! :confused:

    Never thought of what that might look like :/
     
  13. Offline

    Lolmewn

    It wouldn't show, and most likely give an error, since it will try to write to it.
    If you want to attach information to the sign, just save the location and the information to your config.
     
  14. Offline

    xXSniperzzXx_SD

    Well i know you can exceed the max number of letters on a sign and the server will remember what it all says, up until you restart server, then it goes by the numbers you can see
     
Thread Status:
Not open for further replies.

Share This Page