Silent Lightning API

This commit is contained in:
drXor 2014-02-23 16:20:51 -04:00 committed by Thinkofdeath
parent 6be881e6c1
commit 505ac3fb4e
2 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,70 @@
From e296443703879cb13a4523119a24d123d6116f90 Mon Sep 17 00:00:00 2001
From: drXor <mcyoungsota@gmail.com>
Date: Sun, 23 Feb 2014 16:16:29 -0400
Subject: [PATCH] Silenceable Lightning API
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index a58eb05..80ca41a 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -1196,6 +1196,30 @@ public interface World extends PluginMessageRecipient, Metadatable {
{
throw new UnsupportedOperationException( "Not supported yet." );
}
+
+ /**
+ * Strikes lightning at the given {@link Location} and possibly without sound
+ *
+ * @param loc The location to strike lightning
+ * @param isSilent Whether this strike makes no sound
+ * @return The lightning entity.
+ */
+ public LightningStrike strikeLightning(Location loc, boolean isSilent)
+ {
+ throw new UnsupportedOperationException( "Not supported yet." );
+ }
+
+ /**
+ * Strikes lightning at the given {@link Location} without doing damage and possibly without sound
+ *
+ * @param loc The location to strike lightning
+ * @param isSilent Whether this strike makes no sound
+ * @return The lightning entity.
+ */
+ public LightningStrike strikeLightningEffect(Location loc, boolean isSilent)
+ {
+ throw new UnsupportedOperationException( "Not supported yet." );
+ }
}
Spigot spigot();
diff --git a/src/main/java/org/bukkit/entity/LightningStrike.java b/src/main/java/org/bukkit/entity/LightningStrike.java
index c8b5154..1ed4ac9 100644
--- a/src/main/java/org/bukkit/entity/LightningStrike.java
+++ b/src/main/java/org/bukkit/entity/LightningStrike.java
@@ -12,4 +12,21 @@ public interface LightningStrike extends Weather {
*/
public boolean isEffect();
+
+ public class Spigot extends Entity.Spigot
+ {
+
+ /*
+ * Returns whether the strike is silent.
+ *
+ * @return whether the strike is silent.
+ */
+ public boolean isSilent()
+ {
+ throw new UnsupportedOperationException( "Not supported yet." );
+ }
+
+ }
+
+ Spigot spigot();
}
--
1.8.5.2.msysgit.0

View File

@ -0,0 +1,105 @@
From 0b6d3f3a88c9d4dbd48127e08b46e087bb4b77fa Mon Sep 17 00:00:00 2001
From: drXor <mcyoungsota@gmail.com>
Date: Sun, 23 Feb 2014 16:16:59 -0400
Subject: [PATCH] Implement Silenceable Lightning API
diff --git a/src/main/java/net/minecraft/server/EntityLightning.java b/src/main/java/net/minecraft/server/EntityLightning.java
index 36923bb..ae8753f 100644
--- a/src/main/java/net/minecraft/server/EntityLightning.java
+++ b/src/main/java/net/minecraft/server/EntityLightning.java
@@ -13,6 +13,8 @@ public class EntityLightning extends EntityWeather {
// CraftBukkit start
public boolean isEffect = false;
+ public boolean isSilent = false; // Spigot
+
public EntityLightning(World world, double d0, double d1, double d2) {
this(world, d0, d1, d2, false);
}
@@ -61,9 +63,17 @@ public class EntityLightning extends EntityWeather {
}
}
+ // Spigot start
+ public EntityLightning(World world, double d0, double d1, double d2, boolean isEffect, boolean isSilent)
+ {
+ this( world, d0, d1, d2, isEffect );
+ this.isSilent = isSilent;
+ }
+ // Spigot end
+
public void h() {
super.h();
- if (this.lifeTicks == 2) {
+ if (!isSilent && this.lifeTicks == 2) { // Spigot
this.world.makeSound(this.locX, this.locY, this.locZ, "ambient.weather.thunder", 10000.0F, 0.8F + this.random.nextFloat() * 0.2F);
this.world.makeSound(this.locX, this.locY, this.locZ, "random.explode", 2.0F, 0.5F + this.random.nextFloat() * 0.2F);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 948e81d..ab87519 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1326,6 +1326,22 @@ public class CraftWorld implements World {
{
CraftWorld.this.playEffect( location, effect, 0 );
}
+
+ @Override
+ public LightningStrike strikeLightning(Location loc, boolean isSilent)
+ {
+ EntityLightning lightning = new EntityLightning( world, loc.getX(), loc.getY(), loc.getZ(), false, isSilent );
+ world.strikeLightning( lightning );
+ return new CraftLightningStrike( server, lightning );
+ }
+
+ @Override
+ public LightningStrike strikeLightningEffect(Location loc, boolean isSilent)
+ {
+ EntityLightning lightning = new EntityLightning( world, loc.getX(), loc.getY(), loc.getZ(), true, isSilent );
+ world.strikeLightning( lightning );
+ return new CraftLightningStrike( server, lightning );
+ }
};
public Spigot spigot()
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLightningStrike.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLightningStrike.java
index 64e346d..be4f10f 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLightningStrike.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLightningStrike.java
@@ -1,7 +1,9 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityLightning;
+
import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LightningStrike;
@@ -27,4 +29,22 @@ public class CraftLightningStrike extends CraftEntity implements LightningStrike
public EntityType getType() {
return EntityType.LIGHTNING;
}
+
+ // Spigot start
+ private final LightningStrike.Spigot spigot = new LightningStrike.Spigot()
+ {
+
+ @Override
+ public boolean isSilent()
+ {
+ return getHandle().isSilent;
+ }
+
+ };
+
+ public LightningStrike.Spigot spigot()
+ {
+ return this.spigot;
+ }
+ // Spigot end
}
--
1.8.5.2.msysgit.0