Initial respawn system

This commit is contained in:
mathias 2019-06-16 03:34:36 +03:00
parent 6e0acfab97
commit 75b12abe0b
2 changed files with 43 additions and 13 deletions

View file

@ -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;
}

View file

@ -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;
}
}
}
});
}
}