Code:java Block bl = loc.getBlock().getRelative(BlockFace.UP); bl.setType(Material.SIGN_POST); Sign s = (Sign) bl; s.setLine(0, altar); Im having trouble with this. I'm being told that i cannot cast Sign to Block. I'm sure i've done that before, has something changed, or am i just wrong? Thanks!
I believe you need to get the BlockState of that block and cast THAT to a Sign. Or at least I would suppose so, since Sign extends BlockState... Try that. Hope I could help.
Code:java Block bl = loc.getBlock().getRelative(BlockFace.UP); bl.setType(Material.SIGN_POST); Sign s =(Sign) bl.getState(); s.setLine(0, altar); s.update(true);
Yeah I got it working Thanks for the replies. It's really messy, but i'll share. Code:java public static void create(Location loc, String name) { ClassPlugin.log.info(ClassPlugin.prefix + " " + name + " created, X:" + loc.getX() + ", Y:" + loc.getY() + ", Z:" + loc.getZ()); loc.getBlock().setType(Material.OBSIDIAN); Block bl = loc.getBlock().getRelative(BlockFace.UP); bl.setType(Material.SIGN_POST); Sign s = (Sign) bl.getState(); s.setLine(0, name); String query = "INSERT INTO attrib_altars (altar,locX,locY,locZ) values ('" + name + "', '" + loc.getX() + "','" + loc.getY() + "', '" + loc.getZ() + "');"; try { ClassPlugin.manageMySQL.insertQuery(query); } catch (MalformedURLException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
Doesn't look that bad to me One comment though: where does your name parameter come from? Is it something directly (or even indirectly) taken from what a player can type in? If so, you have a SQL injection vulnerability there. I recommend looking into using parameterised SQL statements (a good idea both for security and performance). http://xkcd.com/327/ http://bobby-tables.com/java.html
The name is just something i can use to check if a specific altar exists in the database Thanks for the response. @desht