diff --git a/src/main/java/pw/kaboom/extras/Commands.java b/src/main/java/pw/kaboom/extras/Commands.java index 23c3201..bfc4830 100644 --- a/src/main/java/pw/kaboom/extras/Commands.java +++ b/src/main/java/pw/kaboom/extras/Commands.java @@ -19,6 +19,9 @@ import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -252,9 +255,19 @@ class CommandSkin implements CommandExecutor { class CommandSpawn implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { Player player = (Player) sender; - World world = Bukkit.getWorld("world"); - player.teleport(world.getSpawnLocation()); + Location spawnLoc = world.getSpawnLocation(); + + for (double y = spawnLoc.getY(); y <= 257; y++) { + Block coordBlock = world.getBlockAt(new Location(world, spawnLoc.getX(), y, spawnLoc.getZ())); + + if (coordBlock.getType() == Material.AIR && + coordBlock.getRelative(BlockFace.UP).getType() == Material.AIR) { + player.teleport(spawnLoc.add(0, y - spawnLoc.getY(), 0)); + break; + } + } + player.sendMessage("Successfully moved to the spawn"); return true; } diff --git a/src/main/java/pw/kaboom/extras/Events.java b/src/main/java/pw/kaboom/extras/Events.java index 48c8952..272a151 100644 --- a/src/main/java/pw/kaboom/extras/Events.java +++ b/src/main/java/pw/kaboom/extras/Events.java @@ -439,18 +439,16 @@ class Events implements Listener { } } - /*@EventHandler + @EventHandler void onEntityDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); if (entity.getType() == EntityType.PLAYER) { - if ((event.getCause() == DamageCause.VOID && entity.getLocation().getY() > -64) || - event.getCause() == DamageCause.CUSTOM || - event.getCause() == DamageCause.SUICIDE) { - event.setCancelled(true); + if (event.getCause() == DamageCause.VOID && entity.getLocation().getY() > -64) { + event.setDamage(0); } } - }*/ + } @EventHandler void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) { @@ -608,11 +606,30 @@ class Events implements Listener { void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); - if ((player.getLastDamageCause().getCause() == DamageCause.VOID && player.getLocation().getY() > -64) || - player.getLastDamageCause().getCause() == DamageCause.CUSTOM || - player.getLastDamageCause().getCause() == DamageCause.SUICIDE) { - event.setReviveHealth(20); - event.setCancelled(true); + player.setHealth(20); + player.setFoodLevel(20); + player.setFireTicks(0); + player.setRemainingAir(player.getMaximumAir()); + player.getActivePotionEffects().clear(); + + if (player.getLastDamageCause().getCause() != DamageCause.CUSTOM && + player.getLastDamageCause().getCause() != DamageCause.SUICIDE) { + Bukkit.getScheduler().scheduleSyncDelayedTask(main, new Runnable() { + public void run() { + World world = Bukkit.getWorld("world"); + Location spawnLoc = world.getSpawnLocation(); + + for (double y = spawnLoc.getY(); y <= 257; y++) { + Block coordBlock = world.getBlockAt(new Location(world, spawnLoc.getX(), y, spawnLoc.getZ())); + + if (coordBlock.getType() == Material.AIR && + coordBlock.getRelative(BlockFace.UP).getType() == Material.AIR) { + player.teleport(spawnLoc.add(0, y - spawnLoc.getY(), 0)); + break; + } + } + } + }); } }