My sign doesn't update, im not have an errors. Here my code of update sign Code (Text): public void updateSign(){ if(this.sign == null)return; this.sign.setLine(0, "Name"); this.sign.setLine(1, getSignGame(this.sign.getLocation())); this.sign.setLine(2, "Test"); this.sign.setLine(2, "Players"); this.sign.update(); } SignEvent Code (Text): @EventHandler public void onChangeSign(SignChangeEvent event){ Player p = event.getPlayer(); if(event.getLine(0).equalsIgnoreCase("[Game]")) { if(event.getLine(1)==null){ p.sendMessage(ChatColor.RED+ "Arena is null! Try again with other name."); event.getBlock().breakNaturally(); return; } String arenaName = event.getLine(1); File file = new File("plugins/MyGame/games/"+arenaName+".yml"); try{ FileConfiguration configSign = new YamlConfiguration().loadConfiguration(file); configSign.set("signLocation", Main.getManager().setLoc(event.getBlock().getLocation())); configSign.save(file); p.sendMessage(ChatColor.GREEN + arenaName+" sign create!"); }catch(Exception e){ p.sendMessage(ChatColor.RED+ "Error occurred when try create an arena sign try again!"); } } } Arena.class (method sign = <loc>) Code (Text): if(config.contains("signLocation")){ this.sign = (Sign)Main.getManager().getLoc(config.getString("signLocation")).getBlock().getState(); }
I think the problem is that you are storing the location of the sign you are creating to configSign (configSign.set(...)) But then you are checking config for the sign location which if those two versions of config are in the same class, the if statement that checks >> if(config.contains("signLocation")){...} It is returning null which results in false and prevents NullPointer Access. change the last section to search configSign
I have a differentes class Arena.class have if(config.contains and SignEvent.class have configSign.set()
Arena.class here have a method updateSign Code (Text): private Sign sign; @SuppressWarnings("static-access") public Arena(String nameArena){ try { this.name = nameArena; this.file = new File("plugins/MyGames/games/" + nameArena + ".yml"); this.config = YamlConfiguration.loadConfiguration(file); if(config.contains("signLocation")){ this.sign = (Sign)Main.getManager().getLoc(config.getString("signLocation")).getBlock().getState(); } }catch(Exception e){ e.printStackTrace(); } } public void updateSign(){ if(this.sign == null)return; this.sign.setLine(0, "Name"); this.sign.setLine(1, getSignGame(this.sign.getLocation())); this.sign.setLine(2, "Test"); this.sign.setLine(2, "Players"); this.sign.update(); }
Quick question. Are you calling updateSign() in your code anywhere? I know it sounds silly, but maybe you forgot to call the method.
Yes in Main class here Code (Text): public void onEnable(){ plugin = this; setupConfig(); setupPlugin(); new BukkitRunnable() { @Override public void run() { for(Arena all : Main.getManager().getGames()){ all.updateSign(); } } }.runTaskTimer(this, 10L, 10L); } }
You ought to put an else after Code (Text): if(config.contains("signLocation")){ this.sign = (Sign)Main.getManager().getLoc(config.getString("signLocation")).getBlock().getState(); } and print out a really silly broadcast if in fact the location of the sign is either not read, writing, or both properly or at all. Because from where I'm sitting, nothing jumps out at me.
Code (Text): if(config.contains("signLocation")){ this.sign = (Sign)Main.getManager().getLoc(config.getString("signLocation")).getBlock().getState(); Main.debugi("&e[Sign] &bSign loaded for game &d"+name); }else { Main.debugi("&e[Sign] &cSign cant load for game &d"+name); } and... http://prntscr.com/b848n0. All work fine, only signs not update (
Do what I like to do. Send yourself a message for key stuff like the sign variable, what the sign is equal to, etc. If one of those messages contains something that doesn't belong, you can go and pinpoint exactly where the problem lies. It's a weird little method I like to use to debug, it's probably not the most efficient way but I have had a 100% success rate with it.
I make a command /look and get a location of Sign, and get a location sign from console print, the both locations is a equals, i'm not found a problem :/
Show us the resulting config after you create an arena with a sign. Interestingly enough, I wrote a really neat Super Smash Bros plugin where, instead of keeping track of the locations of arena signs. The software detects all signs within 20 blocks of the lobby location and uses those signs as lobby and arena status signs, because the signs are live and update in almost real time, with the status of the arenas. What I'm not seeing in your code is the explicit calls to the updateSign() function anywhere aside from right when your plugin starts up. try making a call to it right when you instantiate your arena.
The only other reason that your signs aren't updating is because maybe when you reload your plugin, the arenas list is not getting repopulated?
If the chunk which contains the sign gets unloaded then your Sign object will not reference the sign you want to update but rather a "dead" object. Try storing the location and always getting the Sign object just before modifying it.