SPIGOT-4372: LightningStrikeEvent cause API

This commit is contained in:
md_5 2018-09-15 19:16:42 +10:00
parent 34caaf6d68
commit a4bdecff65
4 changed files with 48 additions and 13 deletions

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/server/CommandSummon.java
+++ b/net/minecraft/server/CommandSummon.java
@@ -32,7 +32,7 @@
if (EntityTypes.getName(EntityTypes.LIGHTNING_BOLT).equals(minecraftkey)) {
EntityLightning entitylightning = new EntityLightning(commandlistenerwrapper.getWorld(), vec3d.x, vec3d.y, vec3d.z, false);
- commandlistenerwrapper.getWorld().strikeLightning(entitylightning);
+ commandlistenerwrapper.getWorld().strikeLightning(entitylightning, org.bukkit.event.weather.LightningStrikeEvent.Cause.COMMAND); // CraftBukkit
commandlistenerwrapper.sendMessage(new ChatMessage("commands.summon.success", new Object[] { entitylightning.getScoreboardDisplayName()}), true);
return 1;
} else {

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/server/EntityThrownTrident.java
+++ b/net/minecraft/server/EntityThrownTrident.java
@@ -122,7 +122,7 @@
EntityLightning entitylightning = new EntityLightning(this.world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, false);
entitylightning.d(entity1 instanceof EntityPlayer ? (EntityPlayer) entity1 : null);
- this.world.strikeLightning(entitylightning);
+ ((WorldServer) this.world).strikeLightning(entitylightning, org.bukkit.event.weather.LightningStrikeEvent.Cause.TRIDENT); // CraftBukkit
soundeffect = SoundEffects.ITEM_TRIDENT_THUNDER;
f1 = 5.0F;
}

View file

@ -1,7 +1,11 @@
--- a/net/minecraft/server/PathfinderGoalHorseTrap.java
+++ b/net/minecraft/server/PathfinderGoalHorseTrap.java
@@ -21,13 +21,14 @@
this.a.world.strikeLightning(new EntityLightning(this.a.world, this.a.locX, this.a.locY, this.a.locZ, true));
@@ -18,16 +18,17 @@
this.a.s(false);
this.a.setTamed(true);
this.a.setAgeRaw(0);
- this.a.world.strikeLightning(new EntityLightning(this.a.world, this.a.locX, this.a.locY, this.a.locZ, true));
+ ((WorldServer) this.a.world).strikeLightning(new EntityLightning(this.a.world, this.a.locX, this.a.locY, this.a.locZ, true), org.bukkit.event.weather.LightningStrikeEvent.Cause.TRAP); // CraftBukkit
EntitySkeleton entityskeleton = this.a(difficultydamagescaler, this.a);
- entityskeleton.startRiding(this.a);

View file

@ -305,7 +305,7 @@
return false;
} else {
@@ -316,7 +485,7 @@
@@ -316,10 +485,10 @@
entityhorseskeleton.s(true);
entityhorseskeleton.setAgeRaw(0);
entityhorseskeleton.setPosition((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
@ -313,7 +313,11 @@
+ this.addEntity(entityhorseskeleton, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
}
this.strikeLightning(new EntityLightning(this, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, flag2));
- this.strikeLightning(new EntityLightning(this, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, flag2));
+ this.strikeLightning(new EntityLightning(this, (double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, flag2), org.bukkit.event.weather.LightningStrikeEvent.Cause.WEATHER); // CraftBukkit
}
}
@@ -332,11 +501,11 @@
BiomeBase biomebase = this.getBiome(blockposition);
@ -473,12 +477,17 @@
return false;
}
@@ -786,8 +999,16 @@
@@ -785,9 +998,21 @@
}
+ // CraftBukkit start
public boolean strikeLightning(Entity entity) {
+ // CraftBukkit start
+ LightningStrikeEvent lightning = new LightningStrikeEvent(this.getWorld(), (org.bukkit.entity.LightningStrike) entity.getBukkitEntity());
+ return this.strikeLightning(entity, LightningStrikeEvent.Cause.UNKNOWN);
+ }
+
+ public boolean strikeLightning(Entity entity, LightningStrikeEvent.Cause cause) {
+ LightningStrikeEvent lightning = new LightningStrikeEvent(this.getWorld(), (org.bukkit.entity.LightningStrike) entity.getBukkitEntity(), cause);
+ this.getServer().getPluginManager().callEvent(lightning);
+
+ if (lightning.isCancelled()) {
@ -491,7 +500,7 @@
return true;
} else {
return false;
@@ -803,6 +1024,14 @@
@@ -803,6 +1028,14 @@
}
public Explosion createExplosion(@Nullable Entity entity, DamageSource damagesource, double d0, double d1, double d2, float f, boolean flag, boolean flag1) {
@ -506,7 +515,7 @@
Explosion explosion = new Explosion(this, entity, d0, d1, d2, f, flag, flag1);
if (damagesource != null) {
@@ -811,6 +1040,8 @@
@@ -811,6 +1044,8 @@
explosion.a();
explosion.a(false);
@ -515,7 +524,7 @@
if (!flag1) {
explosion.clearBlocks();
}
@@ -837,7 +1068,8 @@
@@ -837,7 +1072,8 @@
BlockActionData blockactiondata = (BlockActionData) this.d.removeFirst();
if (this.a(blockactiondata)) {
@ -525,7 +534,7 @@
}
}
@@ -858,6 +1090,7 @@
@@ -858,6 +1094,7 @@
boolean flag = this.isRaining();
super.w();
@ -533,7 +542,7 @@
if (this.o != this.p) {
this.server.getPlayerList().a((Packet) (new PacketPlayOutGameStateChange(7, this.p)), this.worldProvider.getDimensionManager());
}
@@ -876,6 +1109,21 @@
@@ -876,6 +1113,21 @@
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.p));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.r));
}
@ -555,7 +564,7 @@
}
@@ -909,13 +1157,20 @@
@@ -909,13 +1161,20 @@
}
public <T extends ParticleParam> int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {