mirror of
https://github.com/kaboomserver/extras.git
synced 2025-02-19 18:54:30 -05:00
Initial respawn system
This commit is contained in:
parent
6e0acfab97
commit
75b12abe0b
2 changed files with 43 additions and 13 deletions
|
@ -19,6 +19,9 @@ import org.bukkit.Particle;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -252,9 +255,19 @@ class CommandSkin implements CommandExecutor {
|
||||||
class CommandSpawn implements CommandExecutor {
|
class CommandSpawn implements CommandExecutor {
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
World world = Bukkit.getWorld("world");
|
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");
|
player.sendMessage("Successfully moved to the spawn");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -439,18 +439,16 @@ class Events implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@EventHandler
|
@EventHandler
|
||||||
void onEntityDamage(EntityDamageEvent event) {
|
void onEntityDamage(EntityDamageEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity.getType() == EntityType.PLAYER) {
|
if (entity.getType() == EntityType.PLAYER) {
|
||||||
if ((event.getCause() == DamageCause.VOID && entity.getLocation().getY() > -64) ||
|
if (event.getCause() == DamageCause.VOID && entity.getLocation().getY() > -64) {
|
||||||
event.getCause() == DamageCause.CUSTOM ||
|
event.setDamage(0);
|
||||||
event.getCause() == DamageCause.SUICIDE) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) {
|
void onEntityKnockbackByEntity(EntityKnockbackByEntityEvent event) {
|
||||||
|
@ -608,11 +606,30 @@ class Events implements Listener {
|
||||||
void onPlayerDeath(PlayerDeathEvent event) {
|
void onPlayerDeath(PlayerDeathEvent event) {
|
||||||
Player player = event.getEntity();
|
Player player = event.getEntity();
|
||||||
|
|
||||||
if ((player.getLastDamageCause().getCause() == DamageCause.VOID && player.getLocation().getY() > -64) ||
|
player.setHealth(20);
|
||||||
player.getLastDamageCause().getCause() == DamageCause.CUSTOM ||
|
player.setFoodLevel(20);
|
||||||
player.getLastDamageCause().getCause() == DamageCause.SUICIDE) {
|
player.setFireTicks(0);
|
||||||
event.setReviveHealth(20);
|
player.setRemainingAir(player.getMaximumAir());
|
||||||
event.setCancelled(true);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue