2016-03-07 09:52:16 +01:00
From bbbf61ebd7ba02c32dc530777481c57547952769 Mon Sep 17 00:00:00 2001
2014-07-21 22:46:54 +02:00
From: Thinkofdeath <thethinkofdeath@gmail.com>
Date: Fri, 20 Dec 2013 21:36:06 +0000
Subject: [PATCH] Particle API
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftEffect.java b/src/main/java/org/bukkit/craftbukkit/CraftEffect.java
2014-11-30 23:16:48 +01:00
index 7de0de5..13f9e9d 100644
2014-07-21 22:46:54 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftEffect.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftEffect.java
2014-11-30 23:16:48 +01:00
@@ -55,6 +55,9 @@ public class CraftEffect {
2014-07-21 22:46:54 +02:00
Validate.isTrue(((Material) data).isBlock(), "Material is not a block!");
datavalue = ((Material) data).getId();
break;
+ case ITEM_BREAK:
+ datavalue = ((Material) data).getId();
2014-11-30 23:16:48 +01:00
+ break;
2014-07-21 22:46:54 +02:00
default:
datavalue = 0;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2016-03-07 09:52:16 +01:00
index 6d94f48..5b18562 100644
2014-07-21 22:46:54 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2016-03-07 09:52:16 +01:00
@@ -847,28 +847,18 @@ public class CraftWorld implements World {
2014-07-21 22:46:54 +02:00
Validate.isTrue(effect.getData() == null, "Wrong kind of data for this effect!");
}
- int datavalue = data == null ? 0 : CraftEffect.getDataValue(effect, data);
- playEffect(loc, effect, datavalue, radius);
+ if (data != null && data.getClass().equals( org.bukkit.material.MaterialData.class )) {
+ org.bukkit.material.MaterialData materialData = (org.bukkit.material.MaterialData) data;
+ Validate.isTrue( materialData.getItemType().isBlock(), "Material must be block" );
+ spigot().playEffect( loc, effect, materialData.getItemType().getId(), materialData.getData(), 0, 0, 0, 1, 1, radius );
+ } else {
+ int dataValue = data == null ? 0 : CraftEffect.getDataValue( effect, data );
+ playEffect( loc, effect, dataValue, radius );
+ }
}
public void playEffect(Location location, Effect effect, int data, int radius) {
- Validate.notNull(location, "Location cannot be null");
- Validate.notNull(effect, "Effect cannot be null");
- Validate.notNull(location.getWorld(), "World cannot be null");
- int packetData = effect.getId();
2014-11-28 02:17:45 +01:00
- PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(packetData, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), data, false);
2014-07-21 22:46:54 +02:00
- int distance;
- radius *= radius;
-
- for (Player player : getPlayers()) {
- if (((CraftPlayer) player).getHandle().playerConnection == null) continue;
- if (!location.getWorld().equals(player.getWorld())) continue;
-
- distance = (int) player.getLocation().distanceSquared(location);
- if (distance <= radius) {
- ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
- }
- }
+ spigot().playEffect( location, effect, data, 0, 0, 0, 0, 1, 1, radius );
}
public <T extends Entity> T spawn(Location location, Class<T> clazz) throws IllegalArgumentException {
2016-03-07 09:52:16 +01:00
@@ -1489,6 +1479,70 @@ public class CraftWorld implements World {
2014-07-21 22:46:54 +02:00
// Spigot start
private final Spigot spigot = new Spigot()
{
+ @Override
+ public void playEffect( Location location, Effect effect, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount, int radius )
+ {
+ Validate.notNull( location, "Location cannot be null" );
+ Validate.notNull( effect, "Effect cannot be null" );
+ Validate.notNull( location.getWorld(), "World cannot be null" );
+ Packet packet;
+ if ( effect.getType() != Effect.Type.PARTICLE )
+ {
+ int packetData = effect.getId();
2014-11-28 02:17:45 +01:00
+ packet = new PacketPlayOutWorldEvent( packetData, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ() ), id, false );
2014-07-21 22:46:54 +02:00
+ } else
+ {
2014-11-28 02:17:45 +01:00
+ net.minecraft.server.EnumParticle particle = null;
+ int[] extra = null;
+ for ( net.minecraft.server.EnumParticle p : net.minecraft.server.EnumParticle.values() )
2014-07-21 22:46:54 +02:00
+ {
2014-11-28 02:17:45 +01:00
+ if ( effect.getName().startsWith( p.b().replace("_", "") ) )
+ {
+ particle = p;
+ if ( effect.getData() != null )
+ {
+ if ( effect.getData().equals( org.bukkit.Material.class ) )
+ {
+ extra = new int[]{ id };
+ } else
+ {
2014-12-11 05:21:51 +01:00
+ extra = new int[]{ (data << 12) | (id & 0xFFF) };
2014-11-28 02:17:45 +01:00
+ }
+ }
+ break;
+ }
2014-07-21 22:46:54 +02:00
+ }
2014-11-28 02:17:45 +01:00
+ if ( extra == null )
2014-07-21 22:46:54 +02:00
+ {
2014-11-28 02:17:45 +01:00
+ extra = new int[0];
2014-07-21 22:46:54 +02:00
+ }
2014-11-28 02:17:45 +01:00
+ packet = new PacketPlayOutWorldParticles( particle, true, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, particleCount, extra );
2014-07-21 22:46:54 +02:00
+ }
+ int distance;
+ radius *= radius;
+ for ( Player player : getPlayers() )
+ {
+ if ( ( (CraftPlayer) player ).getHandle().playerConnection == null )
+ {
+ continue;
+ }
+ if ( !location.getWorld().equals( player.getWorld() ) )
+ {
+ continue;
+ }
+ distance = (int) player.getLocation().distanceSquared( location );
+ if ( distance <= radius )
+ {
+ ( (CraftPlayer) player ).getHandle().playerConnection.sendPacket( packet );
+ }
+ }
+ }
+
+ @Override
+ public void playEffect( Location location, Effect effect )
+ {
+ CraftWorld.this.playEffect( location, effect, 0 );
+ }
};
public Spigot spigot()
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2016-03-06 04:36:33 +01:00
index a90de6a..9ef1fc4 100644
2014-07-21 22:46:54 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2016-03-02 22:28:13 +01:00
@@ -315,9 +315,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2014-12-21 02:09:49 +01:00
public void playEffect(Location loc, Effect effect, int data) {
if (getHandle().playerConnection == null) return;
- int packetData = effect.getId();
- PacketPlayOutWorldEvent packet = new PacketPlayOutWorldEvent(packetData, new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), data, false);
- getHandle().playerConnection.sendPacket(packet);
2015-01-17 00:08:37 +01:00
+ spigot().playEffect(loc, effect, data, 0, 0, 0, 0, 1, 1, 64); // Spigot
2014-12-21 02:09:49 +01:00
}
@Override
2016-03-02 22:28:13 +01:00
@@ -1435,6 +1433,63 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2014-07-21 22:46:54 +02:00
server.getServer().getPlayerList().moveToWorld( getHandle(), 0, false );
}
}
+
+ @Override
+ public void playEffect( Location location, Effect effect, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount, int radius )
+ {
+ Validate.notNull( location, "Location cannot be null" );
+ Validate.notNull( effect, "Effect cannot be null" );
+ Validate.notNull( location.getWorld(), "World cannot be null" );
+ Packet packet;
+ if ( effect.getType() != Effect.Type.PARTICLE )
+ {
+ int packetData = effect.getId();
2014-11-28 02:17:45 +01:00
+ packet = new PacketPlayOutWorldEvent( packetData, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ() ), id, false );
2014-07-21 22:46:54 +02:00
+ } else
+ {
2014-11-28 02:17:45 +01:00
+ net.minecraft.server.EnumParticle particle = null;
+ int[] extra = null;
+ for ( net.minecraft.server.EnumParticle p : net.minecraft.server.EnumParticle.values() )
2014-07-21 22:46:54 +02:00
+ {
2014-11-28 02:17:45 +01:00
+ if ( effect.getName().startsWith( p.b().replace("_", "") ) )
+ {
+ particle = p;
+ if ( effect.getData() != null )
+ {
+ if ( effect.getData().equals( org.bukkit.Material.class ) )
+ {
+ extra = new int[]{ id };
+ } else
+ {
2014-12-11 05:21:51 +01:00
+ extra = new int[]{ (data << 12) | (id & 0xFFF) };
2014-11-28 02:17:45 +01:00
+ }
+ }
+ break;
+ }
2014-07-21 22:46:54 +02:00
+ }
2014-11-28 02:17:45 +01:00
+ if ( extra == null )
2014-07-21 22:46:54 +02:00
+ {
2014-11-28 02:17:45 +01:00
+ extra = new int[0];
2014-07-21 22:46:54 +02:00
+ }
2014-11-28 02:17:45 +01:00
+ packet = new PacketPlayOutWorldParticles( particle, true, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, particleCount, extra );
2014-07-21 22:46:54 +02:00
+ }
+ int distance;
+ radius *= radius;
+ if ( getHandle().playerConnection == null )
+ {
+ return;
+ }
+ if ( !location.getWorld().equals( getWorld() ) )
+ {
+ return;
+ }
+
+ distance = (int) getLocation().distanceSquared( location );
+ if ( distance <= radius )
+ {
+ getHandle().playerConnection.sendPacket( packet );
+ }
+ }
};
public Player.Spigot spigot()
--
2016-02-29 22:33:06 +01:00
2.5.0
2014-07-21 22:46:54 +02:00