Hi! I'm working on a sign editor, but I can't replace text: Code (Text): @EventHandler public void placeSign(SignChangeEvent sign) { Player p = sign.getPlayer(); Sign s = (Sign) sign.getBlock().getState(); for(String l : s.getLines()) { if(p.hasPermission("coloredsigns.position")) { l.replaceAll("<x>", (int)sign.getBlock().getLocation().getX()+""); l.replaceAll("<y>", (int)sign.getBlock().getLocation().getY()+""); l.replaceAll("<z>", (int)sign.getBlock().getLocation().getZ()+""); } } } Can you help me?
But that's not how Java works. You're replacing the text represented in the String Object, but you still have to connect it to the actual sign with the set method. Also, I think you should add s.update() at the end of the method sothat the changes get visible.
Normally I don't write the code myself, but I couldn't think of a way to explain this clearly. Understand what it does before you use it. EDIT, didn't work. Now it does. Code (Text): @EventHandler public void placeSign(SignChangeEvent sign) { Player p = sign.getPlayer(); Sign s = (Sign) sign.getBlock().getState(); String[] lines = s.getLines(); for (int i = 0; i < lines.length; i++) { if (p.hasPermission("coloredsigns.position")) { String line = lines[i]; line = line.replaceAll("<x>", (int) sign.getBlock().getLocation().getX() + ""); line = line.replaceAll("<y>", (int) sign.getBlock().getLocation().getY() + ""); line = line.replaceAll("<z>", (int) sign.getBlock().getLocation().getZ() + ""); s.setLine(i, line); } } s.update(); }
Like I said, I couldn't think of a way to explain this clearly. Apparently you didn't either, because he most likely didn't understand anything of it after reading what you said, neither did I.
you didn't because like what you've said you even don't understand what is the shit with the code you've been copied with.
In this example I think it's fine to "spoonfeed". I wouldn't neccessarily call it that in this instance.