forked from kaboomserver/extras
Prevent redstone wire from crashing server
This commit is contained in:
parent
87ef009ba6
commit
5c6d4c5ab9
2 changed files with 30 additions and 23 deletions
|
@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockFormEvent;
|
import org.bukkit.event.block.BlockFormEvent;
|
||||||
import org.bukkit.event.block.BlockFromToEvent;
|
import org.bukkit.event.block.BlockFromToEvent;
|
||||||
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
|
||||||
|
@ -66,6 +67,18 @@ public class BlockPhysics implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
void onBlockPhysics(BlockPhysicsEvent event) {
|
||||||
|
if (event.getChangedType() == Material.REDSTONE_WIRE) {
|
||||||
|
for (BlockFace face : blockFaces) {
|
||||||
|
if (event.getBlock().getRelative(face).getType() != event.getChangedType()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockRedstone(BlockRedstoneEvent event) {
|
void onBlockRedstone(BlockRedstoneEvent event) {
|
||||||
final double tps = Bukkit.getServer().getTPS()[0];
|
final double tps = Bukkit.getServer().getTPS()[0];
|
||||||
|
|
|
@ -4,14 +4,9 @@ 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.Attribute;
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
import org.bukkit.entity.AreaEffectCloud;
|
import org.bukkit.entity.AreaEffectCloud;
|
||||||
import org.bukkit.entity.EnderDragon;
|
import org.bukkit.entity.EnderDragon;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
@ -21,16 +16,15 @@ 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;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
||||||
|
|
||||||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||||
|
|
||||||
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.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;
|
||||||
|
@ -46,7 +40,7 @@ public class EntitySpawn implements Listener {
|
||||||
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;
|
break;
|
||||||
case MAGMA_CUBE:
|
case MAGMA_CUBE:
|
||||||
|
@ -68,7 +62,7 @@ public class EntitySpawn implements Listener {
|
||||||
|
|
||||||
if ((entityType != EntityType.PLAYER &&
|
if ((entityType != EntityType.PLAYER &&
|
||||||
isEntityLimitReached(chunkEntityCount, chunkEntityCountLimit, isAddToWorldEvent)) ||
|
isEntityLimitReached(chunkEntityCount, chunkEntityCountLimit, isAddToWorldEvent)) ||
|
||||||
|
|
||||||
(entityType == EntityType.ENDER_DRAGON &&
|
(entityType == EntityType.ENDER_DRAGON &&
|
||||||
isEntityLimitReached(worldDragonCount, worldDragonCountLimit, isAddToWorldEvent))) {
|
isEntityLimitReached(worldDragonCount, worldDragonCountLimit, isAddToWorldEvent))) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -86,7 +80,7 @@ public class EntitySpawn implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +100,7 @@ public class EntitySpawn implements Listener {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOutsideBoundaries(double X, double Y, double Z) {
|
private boolean isOutsideBoundaries(double X, double Y, double Z) {
|
||||||
int maxValue = 30000000;
|
int maxValue = 30000000;
|
||||||
int minValue = -30000000;
|
int minValue = -30000000;
|
||||||
|
@ -126,16 +120,16 @@ public class EntitySpawn implements Listener {
|
||||||
if (cloud.getRadius() > 40) {
|
if (cloud.getRadius() > 40) {
|
||||||
cloud.setRadius(40);
|
cloud.setRadius(40);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloud.getRadiusOnUse() > 0.01f) {
|
if (cloud.getRadiusOnUse() > 0.01f) {
|
||||||
cloud.setRadiusOnUse(0.1f);
|
cloud.setRadiusOnUse(0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cloud.getRadiusPerTick() > 0) {
|
if (cloud.getRadiusPerTick() > 0) {
|
||||||
cloud.setRadiusPerTick(0);
|
cloud.setRadiusPerTick(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void limitFollowAttribute(LivingEntity mob) {
|
private void limitFollowAttribute(LivingEntity mob) {
|
||||||
final AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
|
final AttributeInstance followAttribute = mob.getAttribute(Attribute.GENERIC_FOLLOW_RANGE);
|
||||||
|
|
||||||
|
@ -165,10 +159,10 @@ public class EntitySpawn implements Listener {
|
||||||
Z = maxValue;
|
Z = maxValue;
|
||||||
if (Z < minValue)
|
if (Z < minValue)
|
||||||
Z = minValue;
|
Z = minValue;
|
||||||
|
|
||||||
return new Location(location.getWorld(), X, Y, Z);
|
return new Location(location.getWorld(), X, Y, Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void limitSlimeSize(Slime slime) {
|
private void limitSlimeSize(Slime slime) {
|
||||||
if (slime.getSize() > 50) {
|
if (slime.getSize() > 50) {
|
||||||
slime.setSize(50);
|
slime.setSize(50);
|
||||||
|
@ -215,19 +209,19 @@ public class EntitySpawn implements Listener {
|
||||||
|
|
||||||
final World world = entity.getWorld();
|
final World world = entity.getWorld();
|
||||||
final Chunk chunk = entity.getChunk();
|
final Chunk chunk = entity.getChunk();
|
||||||
|
|
||||||
if (chunk.isLoaded()) {
|
if (chunk.isLoaded()) {
|
||||||
final EntityType entityType = entity.getType();
|
final EntityType entityType = entity.getType();
|
||||||
final boolean isAddToWorldEvent = true;
|
final boolean isAddToWorldEvent = true;
|
||||||
|
|
||||||
if (checkEntityLimits(entityType, chunk, world, isAddToWorldEvent)) {
|
if (checkEntityLimits(entityType, chunk, world, isAddToWorldEvent)) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyEntityChanges(entity);
|
applyEntityChanges(entity);
|
||||||
|
|
||||||
if (chunk.isLoaded()) {
|
if (chunk.isLoaded()) {
|
||||||
checkShouldRemoveEntities(world);
|
checkShouldRemoveEntities(world);
|
||||||
}
|
}
|
||||||
|
@ -249,7 +243,7 @@ public class EntitySpawn implements Listener {
|
||||||
final Chunk chunk = entity.getChunk();
|
final Chunk chunk = entity.getChunk();
|
||||||
final World world = entity.getWorld();
|
final World world = entity.getWorld();
|
||||||
final boolean isAddToWorldEvent = false;
|
final boolean isAddToWorldEvent = false;
|
||||||
|
|
||||||
if (checkEntityLimits(entityType, chunk, world, isAddToWorldEvent)) {
|
if (checkEntityLimits(entityType, chunk, world, isAddToWorldEvent)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
@ -314,7 +308,7 @@ public class EntitySpawn implements Listener {
|
||||||
final Chunk chunk = vehicle.getChunk();
|
final Chunk chunk = vehicle.getChunk();
|
||||||
final World world = vehicle.getWorld();
|
final World world = vehicle.getWorld();
|
||||||
final boolean isAddToWorldEvent = false;
|
final boolean isAddToWorldEvent = false;
|
||||||
|
|
||||||
if (checkEntityLimits(entityType, chunk, world, isAddToWorldEvent)) {
|
if (checkEntityLimits(entityType, chunk, world, isAddToWorldEvent)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue