mirror of
https://github.com/kaboomserver/extras.git
synced 2024-10-31 16:59:24 +00:00
Fix player respawn loop
This commit is contained in:
parent
8540016f9f
commit
fa4868908b
|
@ -49,6 +49,12 @@ public final class BlockCheck implements Listener {
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
/*@Subscribe
|
||||||
|
public void onEditSessionEvent(final EditSessionEvent event) {
|
||||||
|
event.setExtent(new NullExtent());
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onSignChange(final SignChangeEvent event) {
|
void onSignChange(final SignChangeEvent event) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -4,8 +4,6 @@ import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
import org.bukkit.entity.AreaEffectCloud;
|
import org.bukkit.entity.AreaEffectCloud;
|
||||||
import org.bukkit.entity.EnderDragon;
|
import org.bukkit.entity.EnderDragon;
|
||||||
|
@ -13,7 +11,6 @@ import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.entity.LightningStrike;
|
import org.bukkit.entity.LightningStrike;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Slime;
|
import org.bukkit.entity.Slime;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.entity.Vehicle;
|
import org.bukkit.entity.Vehicle;
|
||||||
|
@ -28,25 +25,18 @@ import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||||
import org.bukkit.event.weather.LightningStrikeEvent;
|
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||||
|
|
||||||
import com.destroystokyo.paper.event.block.TNTPrimeEvent;
|
import com.destroystokyo.paper.event.block.TNTPrimeEvent;
|
||||||
import com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason;
|
|
||||||
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
|
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
|
||||||
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
|
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
|
||||||
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
|
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
|
||||||
|
|
||||||
public final class EntitySpawn implements Listener {
|
public final class EntitySpawn implements Listener {
|
||||||
private void applyEntityChanges(final Entity entity) {
|
private void applyEntityChanges(final Entity entity) {
|
||||||
if (entity instanceof LivingEntity) {
|
|
||||||
final LivingEntity mob = (LivingEntity) entity;
|
|
||||||
|
|
||||||
limitFollowAttribute(mob);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (entity.getType()) {
|
switch (entity.getType()) {
|
||||||
case AREA_EFFECT_CLOUD:
|
case AREA_EFFECT_CLOUD:
|
||||||
final AreaEffectCloud cloud = (AreaEffectCloud) entity;
|
final AreaEffectCloud cloud = (AreaEffectCloud) entity;
|
||||||
|
|
||||||
limitAreaEffectCloudRadius(cloud);
|
limitAreaEffectCloudRadius(cloud);
|
||||||
break;
|
return;
|
||||||
case MAGMA_CUBE:
|
case MAGMA_CUBE:
|
||||||
case SLIME:
|
case SLIME:
|
||||||
final Slime slime = (Slime) entity;
|
final Slime slime = (Slime) entity;
|
||||||
|
@ -100,8 +90,8 @@ public final class EntitySpawn implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOutsideBoundaries(final double x, final double y, final double z) {
|
private boolean isOutsideBoundaries(final double x, final double y, final double z) {
|
||||||
int maxValue = 30000000;
|
final int maxValue = 30000000;
|
||||||
int minValue = -30000000;
|
final int minValue = -30000000;
|
||||||
|
|
||||||
if (x > maxValue
|
if (x > maxValue
|
||||||
|| x < minValue
|
|| x < minValue
|
||||||
|
@ -128,22 +118,13 @@ public final class EntitySpawn implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void limitFollowAttribute(final LivingEntity mob) {
|
|
||||||
final AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
|
|
||||||
|
|
||||||
if (followAttribute != null
|
|
||||||
&& followAttribute.getBaseValue() > 40) {
|
|
||||||
followAttribute.setBaseValue(40);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Location limitLocation(final Location location) {
|
public static Location limitLocation(final Location location) {
|
||||||
double x = location.getX();
|
double x = location.getX();
|
||||||
double y = location.getY();
|
double y = location.getY();
|
||||||
double z = location.getZ();
|
double z = location.getZ();
|
||||||
|
|
||||||
int maxValue = 30000000;
|
final int maxValue = 30000000;
|
||||||
int minValue = -30000000;
|
final int minValue = -30000000;
|
||||||
|
|
||||||
if (x > maxValue) {
|
if (x > maxValue) {
|
||||||
x = maxValue;
|
x = maxValue;
|
||||||
|
@ -321,10 +302,16 @@ public final class EntitySpawn implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onTNTPrime(final TNTPrimeEvent event) {
|
void onTNTPrime(final TNTPrimeEvent event) {
|
||||||
if (event.getBlock().getWorld().getEntitiesByClass(TNTPrimed.class).size() > 120) {
|
switch (event.getReason()) {
|
||||||
if (PrimeReason.EXPLOSION.equals(event.getReason())) {
|
case EXPLOSION:
|
||||||
|
case FIRE:
|
||||||
|
case REDSTONE:
|
||||||
|
if (event.getBlock().getWorld().getEntitiesByClass(TNTPrimed.class).size() > 120) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,25 @@
|
||||||
package pw.kaboom.extras.modules.player;
|
package pw.kaboom.extras.modules.player;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
import pw.kaboom.extras.modules.entity.EntitySpawn;
|
import pw.kaboom.extras.modules.entity.EntitySpawn;
|
||||||
|
|
||||||
public final class PlayerTeleport implements Listener {
|
public final class PlayerTeleport implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (player.getMaxHealth() <= 0) {
|
||||||
|
player.setMaxHealth(Double.POSITIVE_INFINITY);
|
||||||
|
player.setHealth(20);
|
||||||
|
player.setMaxHealth(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPlayerTeleport(final PlayerTeleportEvent event) {
|
void onPlayerTeleport(final PlayerTeleportEvent event) {
|
||||||
event.setTo(EntitySpawn.limitLocation(event.getTo()));
|
event.setTo(EntitySpawn.limitLocation(event.getTo()));
|
||||||
|
|
Loading…
Reference in a new issue