mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 02:07:37 +01:00
#886: Add new Causes for LightningStrikeEvent
By: Doc <nachito94@msn.com>
This commit is contained in:
parent
18a453f567
commit
e797fdd58a
@ -258,6 +258,7 @@ import org.bukkit.entity.minecart.PoweredMinecart;
|
|||||||
import org.bukkit.entity.minecart.SpawnerMinecart;
|
import org.bukkit.entity.minecart.SpawnerMinecart;
|
||||||
import org.bukkit.entity.minecart.StorageMinecart;
|
import org.bukkit.entity.minecart.StorageMinecart;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||||
|
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||||
import org.bukkit.event.world.SpawnChangeEvent;
|
import org.bukkit.event.world.SpawnChangeEvent;
|
||||||
import org.bukkit.event.world.TimeSkipEvent;
|
import org.bukkit.event.world.TimeSkipEvent;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
@ -674,7 +675,7 @@ public class CraftWorld implements World {
|
|||||||
public LightningStrike strikeLightning(Location loc) {
|
public LightningStrike strikeLightning(Location loc) {
|
||||||
EntityLightning lightning = EntityTypes.LIGHTNING_BOLT.a(world);
|
EntityLightning lightning = EntityTypes.LIGHTNING_BOLT.a(world);
|
||||||
lightning.teleportAndSync(loc.getX(), loc.getY(), loc.getZ());
|
lightning.teleportAndSync(loc.getX(), loc.getY(), loc.getZ());
|
||||||
world.strikeLightning(lightning);
|
world.strikeLightning(lightning, LightningStrikeEvent.Cause.CUSTOM);
|
||||||
return (LightningStrike) lightning.getBukkitEntity();
|
return (LightningStrike) lightning.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,7 +684,7 @@ public class CraftWorld implements World {
|
|||||||
EntityLightning lightning = EntityTypes.LIGHTNING_BOLT.a(world);
|
EntityLightning lightning = EntityTypes.LIGHTNING_BOLT.a(world);
|
||||||
lightning.teleportAndSync(loc.getX(), loc.getY(), loc.getZ());
|
lightning.teleportAndSync(loc.getX(), loc.getY(), loc.getZ());
|
||||||
lightning.setEffect(true);
|
lightning.setEffect(true);
|
||||||
world.strikeLightning(lightning);
|
world.strikeLightning(lightning, LightningStrikeEvent.Cause.CUSTOM);
|
||||||
return (LightningStrike) lightning.getBukkitEntity();
|
return (LightningStrike) lightning.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +594,22 @@ public class CraftEventFactory {
|
|||||||
} else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Vehicle) {
|
} else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Vehicle) {
|
||||||
event = CraftEventFactory.callVehicleCreateEvent(entity);
|
event = CraftEventFactory.callVehicleCreateEvent(entity);
|
||||||
} else if (entity.getBukkitEntity() instanceof org.bukkit.entity.LightningStrike) {
|
} else if (entity.getBukkitEntity() instanceof org.bukkit.entity.LightningStrike) {
|
||||||
LightningStrikeEvent.Cause cause = (spawnReason == SpawnReason.COMMAND ? LightningStrikeEvent.Cause.COMMAND : LightningStrikeEvent.Cause.UNKNOWN);
|
LightningStrikeEvent.Cause cause = LightningStrikeEvent.Cause.UNKNOWN;
|
||||||
|
switch (spawnReason) {
|
||||||
|
case COMMAND:
|
||||||
|
cause = LightningStrikeEvent.Cause.COMMAND;
|
||||||
|
break;
|
||||||
|
case CUSTOM:
|
||||||
|
cause = LightningStrikeEvent.Cause.CUSTOM;
|
||||||
|
break;
|
||||||
|
case SPAWNER:
|
||||||
|
cause = LightningStrikeEvent.Cause.SPAWNER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// This event is called in nms-patches for common causes like Weather, Trap or Trident (SpawnReason.DEFAULT) then can ignore this cases for avoid two calls to this event
|
||||||
|
if (cause == LightningStrikeEvent.Cause.UNKNOWN && spawnReason == SpawnReason.DEFAULT) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
event = CraftEventFactory.callLightningStrikeEvent((LightningStrike) entity.getBukkitEntity(), cause);
|
event = CraftEventFactory.callLightningStrikeEvent((LightningStrike) entity.getBukkitEntity(), cause);
|
||||||
} else if (!(entity instanceof EntityPlayer)) {
|
} else if (!(entity instanceof EntityPlayer)) {
|
||||||
event = CraftEventFactory.callEntitySpawnEvent(entity);
|
event = CraftEventFactory.callEntitySpawnEvent(entity);
|
||||||
|
Loading…
Reference in New Issue
Block a user