From 464ba92a860582de8210f5ca3d9b88aa32a0e0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sat, 4 May 2019 00:29:08 +0800 Subject: [PATCH] + update particle --- .../me/skymc/taboolib/particle/EffLib.java | 56 +++++++++++++++++-- .../taboolib/particle/pack/ParticleData.java | 6 +- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/main/scala/me/skymc/taboolib/particle/EffLib.java b/src/main/scala/me/skymc/taboolib/particle/EffLib.java index b9e4c95..44b923c 100644 --- a/src/main/scala/me/skymc/taboolib/particle/EffLib.java +++ b/src/main/scala/me/skymc/taboolib/particle/EffLib.java @@ -405,7 +405,7 @@ public enum EffLib { /** * 掉落方块 */ - FALLING_DUST("falling_dust", 46, 11, ParticleProperty.REQUIRES_DATA), + FALLING_DUST("fallingdust", 46, 11, ParticleProperty.REQUIRES_DATA), /** * 不死图腾 @@ -726,13 +726,15 @@ public enum EffLib { * * @param color Color of the particle * @param center Center location of the effect + * @param speed Display speed of the particle + * @param amount Amount of particles * @param range Range of the visibility * @throws ParticleVersionException If the particle effect is not supported by the server version * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect * @see ParticlePacket#ParticlePacket(EffLib, ParticleColor, boolean) * @see ParticlePacket#sendTo(Location, double) */ - public void display(ParticleColor color, Location center, double range) throws ParticleVersionException, ParticleColorException { + public void display(ParticleColor color, Location center, float speed, int amount, double range) throws ParticleVersionException, ParticleColorException { if (!isSupported()) { throw new ParticleVersionException("This particle effect is not supported by your server version"); } @@ -742,7 +744,7 @@ public enum EffLib { if (!isColorCorrect(this, color)) { throw new ParticleColorException("The particle color type is incorrect"); } - new ParticlePacket(this, color, range > 256).sendTo(center, range); + new ParticlePacket(this, color, speed, amount, range > 256).sendTo(center, range); } /** @@ -757,6 +759,23 @@ public enum EffLib { * @see ParticlePacket#sendTo(Location, List) */ public void display(ParticleColor color, Location center, List players) throws ParticleVersionException, ParticleColorException { + display(color, center, 1, 0, players); + } + + /** + * Displays a single particle which is colored and only visible for the specified players + * + * @param color Color of the particle + * @param center Center location of the effect + * @param speed Display speed of the particle + * @param amount Amount of particles + * @param players Receivers of the effect + * @throws ParticleVersionException If the particle effect is not supported by the server version + * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect + * @see ParticlePacket#ParticlePacket(EffLib, ParticleColor, boolean) + * @see ParticlePacket#sendTo(Location, List) + */ + public void display(ParticleColor color, Location center, float speed, int amount, List players) throws ParticleVersionException, ParticleColorException { if (!isSupported()) { throw new ParticleVersionException("This particle effect is not supported by your server version"); } @@ -783,6 +802,22 @@ public enum EffLib { display(color, center, Arrays.asList(players)); } + /** + * Displays a single particle which is colored and only visible for the specified players + * + * @param color Color of the particle + * @param center Center location of the effect + * @param speed Display speed of the particle + * @param amount Amount of particles + * @param players Receivers of the effect + * @throws ParticleVersionException If the particle effect is not supported by the server version + * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect + * @see #display(ParticleColor, Location, List) + */ + public void display(ParticleColor color, Location center, float speed, int amount, Player... players) throws ParticleVersionException, ParticleColorException { + display(color, center, speed, amount, Arrays.asList(players)); + } + /** * Displays a particle effect which requires additional data and is only visible for all players within a certain range in the world of @param center * @@ -1409,7 +1444,20 @@ public enum EffLib { * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536 */ public ParticlePacket(EffLib effect, ParticleColor color, boolean longDistance) { - this(effect, color.getValueX(), color.getValueY(), color.getValueZ(), 1, 0, longDistance, null); + this(effect, color, 1, 0, longDistance); + } + + /** + * Construct a new particle packet of a single colored particle + * + * @param effect Particle effect + * @param color Color of the particle + * @param speed Display speed of the particle + * @param amount Amount of particles + * @param longDistance Indicates whether the maximum distance is increased from 256 to 65536 + */ + public ParticlePacket(EffLib effect, ParticleColor color, float speed, int amount, boolean longDistance) { + this(effect, color.getValueX(), color.getValueY(), color.getValueZ(), speed, amount, longDistance, null); if (effect == EffLib.REDSTONE && color instanceof OrdinaryColor && ((OrdinaryColor) color).getRed() == 0) { offsetX = Float.MIN_NORMAL; } diff --git a/src/main/scala/me/skymc/taboolib/particle/pack/ParticleData.java b/src/main/scala/me/skymc/taboolib/particle/pack/ParticleData.java index 46810fe..4996b0e 100644 --- a/src/main/scala/me/skymc/taboolib/particle/pack/ParticleData.java +++ b/src/main/scala/me/skymc/taboolib/particle/pack/ParticleData.java @@ -40,7 +40,7 @@ public class ParticleData { if (matcher.find()) { particle = EffLib.fromName(matcher.group(1)); particleType = ParticleType.ITEM; - particleData = particle.getName().startsWith("block") ? new EffLib.BlockData(ItemUtils.asMaterial(matcher.group(2).toUpperCase()), NumberConversions.toByte(matcher.group(3))) : new EffLib.ItemData(ItemUtils.asMaterial(matcher.group(2).toUpperCase()), NumberConversions.toByte(matcher.group(3))); + particleData = isBlockParticle(particle.getName()) ? new EffLib.BlockData(ItemUtils.asMaterial(matcher.group(2).toUpperCase()), NumberConversions.toByte(matcher.group(3))) : new EffLib.ItemData(ItemUtils.asMaterial(matcher.group(2).toUpperCase()), NumberConversions.toByte(matcher.group(3))); } else { particle = EffLib.fromName(split[0]); } @@ -70,4 +70,8 @@ public class ParticleData { t.printStackTrace(); } } + + private boolean isBlockParticle(String name) { + return name.equalsIgnoreCase("blockdust") || name.equalsIgnoreCase("blockcrack") || name.equalsIgnoreCase("iconcrack") || name.equalsIgnoreCase("fallingdust"); + } }