Answer to A: Code: @EventHandler public void onPlayerDamage(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { Player p = (Player) e.getEntity(); if (e.getCause() == DamageCause.FALL) { Location center = new Location(Bukkit.getServer().getWorld("world"), 0, 64, 0); // set this to your center point Entity orb = Bukkit.getWorld("world").spawnEntity(center, EntityType.EXPERIENCE_ORB); List<Entity> nearby = orb.getNearbyEntities(10, 10, 10); //will give you a list of all entities within a 10 block radius for (Entity ent : nearby){ if (ent instanceof Player){ if (ent.equals(p)){ p.setFallDistance(0); e.setCancelled(true); } } } orb.remove(); } } }
I believe this will, technically, get all of the entities in a 10 block long cube around the center point. If elementalgodz11 wants a 10 block long cube, then a more efficient way to do it would be like this, so you don't have to spawn an experience orb and iterate through several entities for no good reason. Code: @EventHandler public void onPlayerDamage(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { Player p = (Player) e.getEntity(); Location l = new Location(...); //set arguments here to be your center point. Location pl = p.getLocation(); if (e.getCause() == DamageCause.FALL) { if(Math.abs(pl.getX() - l.getX()) >= 10 && Math.abs(pl.getY() - l.getY()) >= 10 && Math.abs(pl.getY() -l.getY()) >= 10){ e.setCancelled(true); //setting fall distance to 0 here isn't necessary } } } } Alternately, if you want it to be a sphere centered on the center point, this would work fine. Code: @EventHandler public void onPlayerDamage(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { Player p = (Player) e.getEntity(); Location l = new Location(...); //set arguments here to be your center point. Location pl = p.getLocation(); if (e.getCause() == DamageCause.FALL && l.distanceSquare(pl) >= 100) { e.setCancelled(true) } } } No idea why this would be happening. While kind of circuitous, the_merciless 's code shouldn't be canceling any damage other than fall damage.
I believe you need <= not >= I don't see how this can be causing that problem. Let's see your class EDIT by Moderator: merged posts, please use the edit button instead of double posting.
the_merciless You are quite right. Corrected version: Code: @EventHandler public void onPlayerDamage(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { Player p = (Player) e.getEntity(); Location l = new Location(...); //set arguments here to be your center point. Location pl = p.getLocation(); if (e.getCause() == DamageCause.FALL) { if(Math.abs(pl.getX() - l.getX()) <= 10 && Math.abs(pl.getY() - l.getY()) <= 10 && Math.abs(pl.getY() -l.getY()) <= 10){ e.setCancelled(true); //setting fall distance to 0 here isn't necessary } } } } I second mercilless's request for you to post the rest of your code.
You have 3 of the same event. I told you before that that will cause problems. You need to keep all the code in 1 event. What is mlg EDIT by Moderator: merged posts, please use the edit button instead of double posting.
You either need three different listeners, or, like merciless said, put the code for all three in one of your public void onDamage(...) methods.
It's not the fact that he has three different methods using the same Event, it's that in one of the methods, he is always cancelling the EntityDamageEvent without checking the DamageCause.
Code:java @EventHandler public void onDamage(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { Player player = (Player) e.getEntity(); if (e.getCause().equals(DamageCause.FALL)) { Location l = new Location(Bukkit.getServer().getWorld("world"), 1006, 6, 36); if (Math.abs(player.getLocation().getX() - l.getX()) <= 10) { if (Math.abs(player.getLocation().getY() - l.getY()) <= 10) { if (Math.abs(player.getLocation().getZ() - l.getZ()) <= 10) { e.setCancelled(true); return; } } } } else { if (SpawnLocation.isCloseToSpawn(player.getLocation())) { e.setCancelled(true); player.setFireTicks(0); return; } else { Location mlg = new Location(Bukkit.getServer().getWorld("world"), 297, 4.5, 299); if (mlg.distance(player.getLocation()) <= 120) { e.setCancelled(true); player.setFireTicks(0); return; } } } } } I cleared it up a bit. Test it and tell me what's not working... eventually put in debug messages.