How could I tell who placed tnt with EntityExplodeEvent? Heres the code I use to put the TNT down... Code: @EventHandler public void place(BlockPlaceEvent event) { if (list.contains(event.getPlayer())) if (!event.getPlayer().isSneaking()) if (event.getBlock().getType() == Material.TNT) { event.getBlock().setType(Material.AIR); ((TNTPrimed)event.getPlayer().getWorld().spawn(event.getBlock().getLocation(), TNTPrimed.class)).setFuseTicks(40); } } Heres my EntityExplodeEvent right now Code: @EventHandler public void onEntityExplode(EntityExplodeEvent event) { if (event.getEntity().getType() == EntityType.PRIMED_TNT) { Iterator it = event.blockList().iterator(); int count = 0; while (it.hasNext()) { count = count + 1; it.next(); } Bukkit.broadcastMessage("Debug Score: " + count); } } I want to add "count" to a HashMap<Player, Integer>, how would I do this? http://bukkit.org/threads/tnt-blow-up-specific-blocks.205236/ Any help is Awesome
Code: @EventHandler public void place(BlockPlaceEvent event) { Code: @EventHandler public void onEntityExplode(EntityExplodeEvent event) {
He's saying to keep track of who placed TNT where, and when one goes off, refer back to your tracking. Using a Map would benefit you here.
I made a HashMap<Location, String> for loc and player.getName(). It works when I place 1 tnt at a time, but when I place 2 tnt at a time the hashmap dosn't take the 2nd location... I get the error from my code "No Loc" for all the tnt that blow up except the first one... Code: static ArrayList<String> list = new ArrayList<String>(); HashMap<String, Integer> score = new HashMap<String, Integer>(); HashMap<Location, String> placed = new HashMap<Location, String>(); Code: @EventHandler public void place(BlockPlaceEvent event) { Player player = event.getPlayer(); if (list.contains(player.getName())) if (!player.isSneaking()) if (event.getBlock().getType() == Material.TNT) { event.getBlock().setType(Material.AIR); ((TNTPrimed)player.getWorld().spawn(event.getBlock().getLocation(), TNTPrimed.class)).setFuseTicks(40); placed.put(event.getBlock().getLocation(), player.getName()); } } Code: @SuppressWarnings("rawtypes") @EventHandler public void onEntityExplode(EntityExplodeEvent event) { if (event.getEntity().getType() == EntityType.PRIMED_TNT) { Iterator it = event.blockList().iterator(); int count = 0; while (it.hasNext()) { count = count + 1; it.next(); } Location loc = new Location(event.getLocation().getWorld(), Math.round(event.getLocation().getX()), Math.round(event.getLocation().getY()), Math.round(event.getLocation().getZ())); if (placed.get(loc) != null) { if (score.get(placed.get(loc)) == null) score.put(placed.get(loc), 0); score.put(placed.get(loc), score.get(placed.get(loc)) + count); Bukkit.broadcastMessage(" " + score.get(placed.get(loc))); placed.remove(loc); } else Bukkit.broadcastMessage(ChatColor.RED + "No loc"); } }