How to update a sign when player joins

Discussion in 'Plugin Development' started by UaVxChallenge, Jul 11, 2014.

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

    UaVxChallenge

    In my plugin I am trying to add in lobby signs.

    Here is my SignListener class!
    and Arena but when players join the dont update the signs

    Code:java
    1.  
    2. private static HashMap<Sign, Integer> signs = new HashMap<Sign, Integer>();
    3.  
    4. public SignListener() {
    5.  
    6. if (!SettingsManager.getLobbySigns().contains("signs")) {
    7. SettingsManager.getLobbySigns().createConfigurationSection("signs");
    8. }
    9.  
    10. for (String str : SettingsManager.getLobbySigns().<ConfigurationSection>get("signs").getKeys(true)) {
    11. ConfigurationSection section = SettingsManager.getLobbySigns().get("signs." + str);
    12.  
    13. Location loc = LocationUtil.locationFromConfig(section.getConfigurationSection("location"), false);
    14. Sign s = (Sign) loc.getBlock().getState();
    15.  
    16. signs.put(s, section.getInt("arenaNumber"));
    17. }
    18. }
    19.  
    20. public static ArrayList<Sign> getSigns(Arena a) {
    21. ArrayList<Sign> s = new ArrayList<Sign>();
    22.  
    23. for (Sign sign : signs.keySet()) {
    24. if (ArenaManager.getInstance().getArena(signs.get(sign)) == a) s.add(sign);
    25. }
    26.  
    27. return s;
    28. }
    29.  
    30. @EventHandler
    31. public void onSignChange(SignChangeEvent e) {
    32. if (e.getLine(0).equalsIgnoreCase("[SuperRun]")) {
    33. e.getPlayer().sendMessage(ChatColor.GREEN + "Test 1");
    34. int id;
    35. try { id = Integer.parseInt(e.getLine(1)); }
    36. catch (Exception ex) { MessageManager.getInstance().msg(e.getPlayer(), MessageType.BAD, "That is not a valid arena number!"); return; }
    37. e.getPlayer().sendMessage(ChatColor.GREEN + "Test 2");
    38. Arena a = ArenaManager.getInstance().getArena(id);
    39. if (a == null) {
    40. MessageManager.getInstance().msg(e.getPlayer(), MessageType.BAD, "That is not a valid arena!");
    41. return;
    42. }
    43. e.getPlayer().sendMessage(ChatColor.GREEN + "Test 3");
    44. ConfigurationSection section = SettingsManager.getLobbySigns().createConfigurationSection("signs." + SettingsManager.getLobbySigns().<ConfigurationSection>get("signs").getKeys(true).size() +1);
    45. e.getPlayer().sendMessage(ChatColor.GREEN + "Test 1");
    46. ConfigurationSection location = section.createSection("location");
    47. location.set("world", e.getBlock().getLocation().getWorld().getName());
    48. location.set("x", e.getBlock().getLocation().getX());
    49. location.set("y", e.getBlock().getLocation().getY());
    50. location.set("z", e.getBlock().getLocation().getZ());
    51. e.getPlayer().sendMessage(ChatColor.GREEN + "Test 4");
    52. section.set("arenaNumber", id);
    53.  
    54. signs.put((Sign) e.getBlock().getState(), a.getID());
    55. e.getPlayer().sendMessage(ChatColor.GREEN + "Test 5");
    56. e.setLine(2, a.getCurrentPlayers() + " Players");
    57. e.setLine(3, a.getState().toString());
    58. }
    59. }
    60.  
    61. @EventHandler
    62. public void onPlayerInteract(PlayerInteractEvent e) {
    63. if (!(e.getAction() == Action.RIGHT_CLICK_AIR) && !(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    64.  
    65. if (e.getClickedBlock() == null || e.getClickedBlock().getState() == null) return;
    66.  
    67. if (e.getClickedBlock().getState() instanceof Sign) {
    68. Sign s = (Sign) e.getClickedBlock().getState();
    69. if (s.getLine(0).equalsIgnoreCase("[SuperRun]")) {
    70. ArenaManager.getInstance().getArena(Integer.parseInt(s.getLine(1))).addPlayer(e.getPlayer());
    71. }
    72. }
    73. }


    Code:java
    1. public void addPlayer(final Player p) {
    2. if (currentPlayers >= numPlayers) {
    3. p.sendMessage(ChatColor.RED + "Too many players!");
    4. return;
    5. }
    6. data.add(new PlayerData(p));
    7. p.getInventory().clear();
    8. p.teleport(Lobby);
    9. p.sendMessage(ChatColor.GREEN + "Game will start once 5 people join!");
    10. currentPlayers++;
    11. for (Sign s : signs) {
    12. s.setLine(2, currentPlayers + "/" + numPlayers);
    13. s.update(true);
    14. }
     
  2. Offline

    THEREDBARON24

    Does the player join the arena? At any rate, on line 12 in your second block, try and add a "" before the integers. It may be this simple. Also, check to see if the list "signs" is empty. Finally, try and use just s.update();
     
  3. Offline

    Pizza371

    how is that going to fix it if the method accepts an integer?
    UaVxChallenge Are you sure everything is registering? Have you tried a test message to make sure these things are bein fired?
     
  4. Offline

    UaVxChallenge

    @THEREDBARRON24
    I already tested both of those before I posted this and they didn't work.
    Pizza371
    Yea I have already tested that
     
  5. Offline

    Pizza371

    UaVxChallenge Are you sure there's things in your signs hashmap? (print them)
     
Thread Status:
Not open for further replies.

Share This Page