I'm messing a bit with maps and I have came to an issue. I'm trying to make, so everytime you change your held item it will update map. However, I get error in console. As well as that, only one map will update, the first map in taskbar will update while others not. for example, if my taskbar is empty and I get a map to slot 2(taskbar) it will update, if i get another map to slot 1, the map on slot 1 will update but the one on slot 2 won't anymore. stack-trace: http://prntscr.com/1wvq6a Line 143 in Cookies Class: Code:java public static void UpdateMap(Player player) { Map.setRedrawNeed(); player.sendMessage("Before IF"); if (player.getItemInHand().getType().equals(Material.MAP)) { player.sendMessage("Map"); //Line 143 below: if(player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Test")) { player.sendMessage("Pass the IF"); MapView map = Bukkit.getServer().getMap(player.getItemInHand().getDurability()); for (MapRenderer r:map.getRenderers()){ map.removeRenderer(r); } map.addRenderer(new Map()); return; }else { player.sendMessage("Fail If"); } return; } return; } If I remove line 143, it doens't give me any error. But with line 143, it won't even execute the else. My Listener class/Event that calls on player item held change. Code:java @EventHandler public void onItemHeldChange(PlayerItemHeldEvent event) { if(event.getPlayer() == null) { return; } Cookies.UpdateMap(event.getPlayer()); return; } } My Map class: Code:java public class Map extends MapRenderer{ static boolean redrawNeeded = false; public static void setRedrawNeed() { redrawNeeded = true; } @Override public void render(MapView map, MapCanvas canvas, Player player) { if(!redrawNeeded) return; setMap(map, canvas, player); } @SuppressWarnings("deprecation") public static void setMap(MapView map, MapCanvas canvas, Player player) { for(int x = 0; x < 128; x++) { for(int y = 0; y < 128; y++) { canvas.setPixel(x, y, MapPalette.matchColor(255, 132, 255)); } } Damageable dplayer = player; String hp = "Health: " + (int) dplayer.getHealth(); String name = "Name: " + player.getName(); canvas.drawText(3, 5, MinecraftFont.Font, "Profile"); canvas.drawText(3, 25, MinecraftFont.Font, name); canvas.drawText(3, 35, MinecraftFont.Font, hp); redrawNeeded = false; player.sendMap(map); }} So the 2 issues im having is; When updating map it throws error in console & only one map in my inventory will update, the one that's in the 'closest' slot.
This is because you get a NPE in that line. That means that player, getItemInHand(), getItemMeta() or getDisplayName() is null. I think that the item has no item meta or the item meta has no display name. You should check that.
MiniDigger I have added player.getItemInHand().getItemMeta().getDisplayName() != null as if statement and it doesn't throw me that error anymore. I still need help for second issue, Only one map will update, and it doesnt seem to check if it's displayname is 'Test' but updates it no matter what.
MiniDigger Code:java public static void UpdateMap(Player player) { Map.setRedrawNeed(); //player.sendMessage("Before IF"); if (player.getItemInHand().getType().equals(Material.MAP) && player.getItemInHand().getItemMeta().getDisplayName() != null) { //player.sendMessage("Map"); if(player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Test")) { //player.sendMessage("Pass the IF"); MapView map = Bukkit.getServer().getMap(player.getItemInHand().getDurability()); for (MapRenderer r:map.getRenderers()){ map.removeRenderer(r); } map.addRenderer(new Map()); return; }else { //player.sendMessage("Fail If"); } return; } return; } Sorry, forgot. Here it is.
deathknife I think it only changes the map, the player is holding in is hand. You always just check this.
MiniDigger Yes, but let's say player has 2 maps. One is on slot 1 and one is on slot 2. The UpdateMap is activated by command. The player is holding map 1, types the command and it updates. The player is holding map two, types the command and it won't update. If the player swaps map 1 with map 2 (map 1 == slot 2, map 2 == slot 1), then only map 2(slot 1) will render on command, while map 1(slot2) won't.
deathknife well that's interesting . Does UpdateMap() gets called for map in the second slot? If so, where does it stop executing?
MiniDigger Code:java Bukkit.broadcastMessage("test" + map); if(!redrawNeeded) return; I have this inside Map class in render, the redrawNeeded is for map to render instantly. It also broadcastes all maps I have in inventory, not the one in hand. I have came up with one theory; On command, it sets redrawNeeded to true. Then it proceeds to render all maps, but it only renders the first one as when one map gets render it sets redrawNeeded to false (Code in OP). And it needs redrawNeeded to true to do anything. Something like this. I also forgot to mention, that the other maps are blank.