So, I am making a plugin for a server and I have seen how to do this before but I cant find it again, basically, I need to globally find signs that have [deathmessage] on the first line and if they have that on the sign, it will update the other lines of the sign.
@nico123o If the signs can be retrieved from the SignChangeEvent, then use that. Otherwise: Get all of the loaded chunks in a world with world.getLoadedChunks() Iterate through the chunks and find the loaded tile entities with chunk.getTileEntities() Check if the BlockState (From the TileEntities) is an instanceof Sign If it is, cast it to sign and check if the first line is [deathmessage], then you can update the rest of the sign. Of course, this only works if that chunk is loaded or not.
@nico123o For the sign use SignChangeEvent like this: Code: @EventHandler public void onSignChange(SignChangeEvent e) { if (e.getLines().length > 0 && e.getLine(0).equalsIgnoreCase("[deathmessage]")){ e.setLine(0,"1stline"); e.setLine(1,"2nd line"); e.setLine(2,"3rd line"); e.setLine(3,"4th line"); } }
Was just testing the plugin, uploaded it to multicraft and got the error 'org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: me/nico123o/PvpStats/PvpStats : Unsupported major.minor version 52.0' anyone know how to fix it?
I fixed the error, Currently I have: Code: package me.nico123o.DeathSignsTest; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.plugin.java.JavaPlugin; public class DeathSignsTest extends JavaPlugin { public void onEnable() { System.out.println("[DeathSigns] Enabling"); } public void onDisable() { System.out.println("[DeathSigns] Disabling"); HandlerList.unregisterAll(); } @EventHandler public void onSignChange(SignChangeEvent e) { if (e.getLines().length > 0 && e.getLine(0).equalsIgnoreCase("[deathsigns]")){ e.setLine(0,"[deathsigns]"); e.setLine(1,"2nd line"); e.setLine(2,"3rd line"); e.setLine(3,"4th line"); } } } and I need to it update on a player death Can anyone tell me how to update the sign on a players death, I know how to get the killers name and stuff like that, I just need to know how to update a sign other than when you place it down. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
You need to save the location of the sign. Then, use PlayerDeathEvent and get the killers name using event.getKiller().getName(); With that information, get the block of the sign and cast it to a Sign object. Now you can use sign.setLine() to update the information.