Hashmaps (Read Last Comment)

Discussion in 'Plugin Development' started by Squid_Boss, Dec 10, 2013.

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

    Squid_Boss

    My console keeps getting spammed with these two things:
    (When a player is moving)
    Code:
    [SEVERE] Could not pass PlayerMoveEvent to WarHexagon vv1.0
    (When a player interacts with things)
    Code:
    [SEVERE] Could not pass PlayerInteractEvent to WarHexagon vv1.0
    There is no stacktrace, it's just those messages spammed over and over again.

    Here is my PlayerMoveEvent and PlayerInteractEvent:
    PlayerMoveEvent (open)

    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent e) {
    3. if (!Join.arenaSigns.get(game).contains(e.getPlayer().getName())) return;
    4. if (override.contains(e.getPlayer().getName())) return;
    5. if (stun.contains(e.getPlayer().getName())) {
    6. e.setCancelled(true);
    7. }
    8. Block damage = e.getPlayer().getWorld().getBlockAt(e.getTo()).getRelative(0, 0, 0);
    9. if (damage.getType() == Material.FIRE) {
    10. double health = e.getPlayer().getHealth();
    11. e.getPlayer().setHealth(health-.5);
    12. damage.setType(Material.AIR);
    13. }
    14. }


    PlayerInteractEvent (open)

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4.  
    5. if (p.getItemInHand().getType() == Material.PAPER) {
    6. Main.classes.show(p);
    7. return;
    8. }
    9.  
    10. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    11. if (e.getClickedBlock().getState() instanceof Sign) {
    12. Sign s = (Sign) e.getClickedBlock().getState();
    13. if (s.getLine(3).equalsIgnoreCase(ChatColor.GREEN + "[OPEN]")) {
    14. String mapline = s.getLine(1).toString();
    15. String line = mapline.replace("Map: ", "");
    16. if (plugin.getConfig().contains("" + line)) {
    17. arenaSigns.get(line).add(p.getName());
    18. Gameplay.game = line;
    19. ItemStack paper = new ItemStack(Material.PAPER);
    20. ItemMeta paperm = paper.getItemMeta();
    21. paperm.setDisplayName(ChatColor.DARK_RED + "Class Chooser");
    22. paper.setItemMeta(paperm);
    23. p.getInventory().addItem(paper);
    24. p.updateInventory();
    25. Location spawn = new Location(Bukkit.getWorld(plugin.getConfig().getString("" + line + ".center.world")), plugin.getConfig().getInt("" + line + ".center.x"), plugin.getConfig().getInt("" + line + ".center.y"), plugin.getConfig().getInt("" + line + ".center.z"), plugin.getConfig().getInt("" + line + ".center.yaw"), plugin.getConfig().getInt("" + line + ".center.pitch"));
    26. p.teleport(spawn);
    27. arenaSigns.get(line).add(p.getName());
    28. Main.objectives.setDisplaySlot(DisplaySlot.SIDEBAR);
    29. Main.objectives.setDisplayName(ChatColor.DARK_RED + "War Hexagon");
    30. p.setScoreboard(Main.board);
    31. Main.prestart.addPlayer(p);
    32. Main.playerCount.setScore(arenaSigns.get(line).size());
    33. if (arenaSigns.get(line).size() == 1) {
    34. Main.prestart.setAllowFriendlyFire(false);
    35. Main.timeuntilStart.setScore(30);
    36. }
    37.  
    38. for (String player : arenaSigns.get(line)) {
    39. Player p1 = plugin.getServer().getPlayerExact(player);
    40. p1.sendMessage(ChatColor.GRAY + "[" + ChatColor.DARK_RED + "WH" + ChatColor.GRAY + "] " + ChatColor.RESET + p.getName() + " has just joined the game!");
    41.  
    42. int sign = Main.signs.getConfig().getInt("signnumber") + 1;
    43. for (int currentSign = 1; currentSign < sign; currentSign++) {
    44. int x = Main.signs.getConfig().getInt("signs." + currentSign + ".x");
    45. int y = Main.signs.getConfig().getInt("signs." + currentSign + ".y");
    46. int z = Main.signs.getConfig().getInt("signs." + currentSign + ".z");
    47. String world = Main.signs.getConfig().getString("signs." + currentSign + ".Map: " + line);
    48. if (world == null) {
    49. continue;
    50. }
    51. Block block = Bukkit.getWorld(world).getBlockAt(x, y, z);
    52. block.getChunk().load();
    53. BlockState state = block.getState();
    54. if ((state instanceof Sign)) {
    55. Sign s1 = (Sign) state;
    56. s1.setLine(2, ChatColor.WHITE + "Players: " + arenaSigns.get(line).size() + "/5");
    57. block.getChunk().load();
    58. s1.update(true);
    59. if (plugin.getConfig().getInt("" + line + ".center.players") == 6) {
    60. s1.setLine(3, ChatColor.DARK_PURPLE + "[FULL]");
    61. block.getChunk().load();
    62. s1.update(true);
    63. }
    64. if (arenaSigns.get(line).size() == 2) {
    65. Start.Startup();
    66. }
    67. }
    68. }
    69. }
    70. }else{
    71. if (s.getLine(3).equalsIgnoreCase(ChatColor.DARK_PURPLE + "[FULL]")) {
    72. p.sendMessage(ChatColor.RED + "The server is full!");
    73. }else{
    74. if (s.getLine(3).equalsIgnoreCase(ChatColor.YELLOW + "[STARTED]")) {
    75. p.sendMessage(ChatColor.RED + "The server has already started!");
    76. }
    77. }
    78. }
    79. }
    80. }
    81. return;
    82. }
    83. }



    I think it may be due to my Hashmap, arenaSigns. I removed the arenaSigns code in my playermoveevent, and the spam stopped.

    Also, I did some testing and it seems that when to "arenaSigns.get(line).add(p.getName());" that's where the code stops running.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  2. Offline

    DailyLove

    Squid_Boss Can you post the full stack traces, They will be located in your server log
     
  3. Offline

    Squid_Boss

    DailyLove I looked at the latest in my server logs, and there are no stacktraces, it's just a continuous spam of those messages (first post).
     
  4. Offline

    Squid_Boss

    Could the issue be related to the fact that when I call my hashmap, "line" and then I add a string to it, instead of a string list ?

    After looking over CubieX 's post (found here), I have ran across another error:
    Whenever I try to put the player into the hashmap's ArrayList like this
    Code:java
    1. myHashMap.put(arenaName, myHashMap.get(arenaName).add(playerName));

    I get an error under "put", saying that "the method put(String, ArrayList<String>) is not applicable for the arguements (String, boolean) because "add(playerName)" is returning as a boolean....is there a work around for this? Here is my code:
    Code:java
    1. if (!arenaPlayers.containsKey(line)) {
    2. arenaPlayers.put(line, new ArrayList<String>());
    3. }
    4. if (!arenaPlayers.get(line).contains(p.getName())) {
    5. arenaPlayers.put(line, arenaPlayers.get(line).add(p.getName()));
    6. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  5. Offline

    Conarnar

    When you use the add method for Lists, it doesn't return the list, instead it returns a boolean that tells if it suceeded.
    Try doing:
    Code:
    if (!arenaPlayers.get(line).contains(p.getName())) {
          ArrayList<String> list = arenaPlayers.get(line);
          list.add(p.getName())
          arenaPlayers.put(line, list);
    }
     
Thread Status:
Not open for further replies.

Share This Page