Library EffectLib - Manage your effects the nice way. (Text/Image in Particles)

Discussion in 'Resources' started by Slikey, Apr 21, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Slikey

    EffectLib - Manage your effects the nice way.
    Find it on BukkitDev: http://dev.bukkit.org/bukkit-plugins/effectlib/


    Description:
    When I started to program my own games on BukkitAPI, I started to spend a lot of time on effects.
    Back then, I dreamed of my own EffectLibrary and now, it has come. I think that I am ready to release this little tool to help you devs out.
    The library takes care of your effects and you do not need to run any tasks on the scheduler. Just pass your values in the effect and start it. Depended on your effect, it will wait, repeat, start instantly.

    Screenshots:
    Screenshots of currently added effects. This list is not complete.
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    More Screenshots:
    Show Spoiler
    [​IMG]


    Usage:
    This is an example plugin. It'll create a bleeding effect on each joining player.
    http://dev.bukkit.org/paste/9800/

    Source:

    Get all builds on Jenkins (NathanWolf): http://jenkins.elmakers.com/job/EffectLib/
    Get the source on GitHub: https://github.com/Slikey/EffectLib

    Special Thanks:
    DarkBladee12 for the ReflectionHandler and ParticleEffect Lib. It saves me some time, so that I don't have to reinvent the wheel. Thank you. ;)
    LCastr0 for maintaining the Lib, while I am busy. Cheers!

    Help Me:
    This libary comes with a handy bundle of premade effects. You can tweak every effect or create your own. If you want to contribute, please add your own effects to the library by sending them per PM or Ticket.
    You might also send me your ideas for effects. I have some time now and it wants to be filled. ;)
    I appreciate every submission. Thank you!

    I try to take care on every problem. Please include a stacktrace on error.

    Slikey

    How To: Create your own Effect

    1. Create a class which extends de.slikey.effectlib.Effect
    Code:java
    1. public class FlameEntityEffect extends EntityEffect {
    2.  
    3. }
    4.  


    2. Implement unimplemented methods
    Code:java
    1. public class FlameEntityEffect extends EntityEffect {
    2.  
    3. public FlameEntityEffect(EffectManager effectManager, Entity entity) {
    4. super(effectManager, entity);
    5. }
    6.  
    7. @Override
    8. public void onRun() {
    9.  
    10. }
    11.  
    12. }
    13.  


    3. Choose EffectType and corresponding values
    Code:java
    1. public class FlameEntityEffect extends EntityEffect {
    2.  
    3. public FlameEntityEffect(EffectManager effectManager, Entity entity) {
    4. super(effectManager, entity);
    5. // Repeat this effect every "period" ticks and "iterations" times.
    6. type = EffectType.REPEATING;
    7. // Run this effect each tick
    8. period = 1;
    9. // Run this effect 600 times
    10. iterations = 600;
    11. }
    12.  
    13. @Override
    14. public void onRun() {
    15.  
    16. }
    17.  
    18. }
    19.  


    4. Add the visual effect in the .onRun() Method
    Code:java
    1. public class FlameEntityEffect extends EntityEffect {
    2.  
    3. public FlameEntityEffect(EffectManager effectManager, Entity entity) {
    4. super(effectManager, entity);
    5. type = EffectType.REPEATING;
    6. period = 1;
    7. iterations = 600;
    8. }
    9.  
    10. @Override
    11. public void onRun() {
    12. // Create 10 particles per iteration
    13. for (int i = 0; i < 10; i++) {
    14. // Location of effect
    15. Location location = entity.getLocation();
    16. // Randomize the location within a circle from 0 to 0.6 radius
    17. location.add(RandomUtil.getRandomCircleVector().multiply(RandomUtil.random.nextDouble() * 0.6d));
    18. // Randomize height
    19. location.add(0, RandomUtil.random.nextFloat() * 2, 0);
    20. // Create packet, to send to the player
    21. PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(ParticleType.FLAME.getParticleName(), (float) location.getX(), (float) location.getY(), (float) location.getZ(), 0, 0, 0, 0, 0);
    22. // Sends the effect to every player within "visibleRadiusSquared" radius
    23. sendPacket(packet, location, visibleRadiusSquared);
    24. }
    25. }
    26.  
    27. }


    5. We are done!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
    zThana, TheNewTao, MarinD99 and 50 others like this.
  2. Offline

    Slikey

    DOWNLOAD CURRENT VERSION with TEST PLUGIN

    Version 2.5
    Type in your chat /help EffectLibTest to get a list of commands.
     
  3. Offline

    bigteddy98

    This is what I call awesome ;) Only one thing, servers with a limit on the packets per seconds can get in problems when using this often, be careful with it.
     
    Slikey likes this.
  4. Offline

    Slikey


    Of course. Effects are bandwidth-intense. But these servers can control the particles spawned in the effects for themselfes to descrese their amount. Most of the intensive effects have a public variable called "particles". Just change it and you should be fine. ;) Thank you for mentioning!

    VictoryShot Oh.. I compiled EffectLib with the a development build of CraftBukkit..
    http://dl.bukkit.org/downloads/craftbukkit/

    coco5843 I am happy that it helps you :3

    I think I will have to look in an better way to call the NMS-classes. Time for some self-reflection. HAHA. lol.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 4, 2016
    MrKeals likes this.
  5. Offline

    Phasesaber

    Looks neato. I love the big swirl.
     
  6. Offline

    Slikey

    Phasesaber Yeah, it's mine too. If you have some ideas, I'd be happy to implement them.. I am running out of ideas ;)

    If I had a server, I'd put the big swirl around an obelisk on the hub or main city^^
     
    MrKeals likes this.
  7. Offline

    VictoryShot

    Can I have a download! Its still pending! :mad:
     
  8. Offline

    Slikey

    VictoryShot Look at the third post in the Thread. There is a DOWNLOAD. Even though this is not the newest version. ;)
     
    MrKeals likes this.
  9. Offline

    VictoryShot

    Lol I did't even notice that! Can you send me the source for the spiral!
     
  10. Offline

    Slikey

    Of course... Wait for some legendary maths.. 14 years of school to learn that.. aaaand..
    Code:java
    1. import net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles;
    2.  
    3. import org.bukkit.Location;
    4.  
    5. import de.slikey.effectlib.EffectManager;
    6. import de.slikey.effectlib.EffectType;
    7. import de.slikey.effectlib.util.ParticleType;
    8.  
    9. public class HelixLocationEffect extends LocationEffect {
    10. /**
    11.   * Particle to form the helix
    12.   */
    13. public ParticleType particle = ParticleType.FLAME;
    14.  
    15. /**
    16.   * Amount of strands
    17.   */
    18. public int strands = 8;
    19.  
    20. /**
    21.   * Particles per strand
    22.   */
    23. public int particles = 80;
    24.  
    25. /**
    26.   * Radius of helix
    27.   */
    28. public float radius = 10;
    29.  
    30. /**
    31.   * Factor for the curves. Negative values reverse rotation.
    32.   */
    33. public float curve = 10;
    34.  
    35. /**
    36.   * Rotation of the helix (Fraction of PI)
    37.   */
    38. public double rotation = Math.PI / 4;
    39.  
    40. public HelixLocationEffect(EffectManager effectManager, Location location) {
    41. super(effectManager, location);
    42. type = EffectType.REPEATING;
    43. period = 5;
    44. iterations = 10 * 4;
    45. }
    46.  
    47. @Override
    48. public void onRun() {
    49. for (int i = 1; i <= strands; i++) {
    50. for (int j = 1; j <= particles; j++) {
    51. float ratio = (float) j / particles;
    52. double angle = curve * ratio * 2 * Math.PI / strands + (2 * Math.PI * i / strands) + rotation;
    53. double x = Math.cos(angle) * ratio * radius;
    54. double z = Math.sin(angle) * ratio * radius;
    55. location.add(x, 0, z);
    56.  
    57. PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle.getParticleName(), (float) location.getX(), (float) location.getY(), (float) location.getZ(), 0, 0, 0, 0, 0);
    58. sendPacket(packet, location, visibleRadiusSquared);
    59.  
    60. // Subtracting x and z to get to the first location again.
    61. location.subtract(x, 0, z);
    62. }
    63. }
    64. }
    65.  
    66. }
     
  11. Offline

    VictoryShot


    Im getting an error?

    Code:
    [18:23:04 INFO]: mike1665 issued server command: /shield
    [18:23:04 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'shie
    ld' in plugin EffectLibTest vv1.0-TEST
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:17
    5) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:952) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NoClassDefFoundError: net/minecraft/server/v1_7_R3/Packet
            at de.slikey.effectlib.test.command.ShieldCommand.effect(ShieldCommand.j
    ava:16) ~[?:?]
            at de.slikey.effectlib.test.command.CommandBase.onCommand(CommandBase.ja
    va:21) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            ... 13 more
    Caused by: java.lang.ClassNotFoundException: net.minecraft.server.v1_7_R3.Packet
     
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:67) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
            at de.slikey.effectlib.test.command.ShieldCommand.effect(ShieldCommand.j
    ava:16) ~[?:?]
            at de.slikey.effectlib.test.command.CommandBase.onCommand(CommandBase.ja
    va:21) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            ... 13 more
    You know what I would love to see, is this:



    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 23, 2016
  12. Offline

    Slikey

    VictoryShot Wuhahaha.. Nice. I am going to implement this.
     
  13. Offline

    VictoryShot

    Really! That would be AMAZING! Can't wait :3
     
  14. Offline

    coco5843

    Helix Ability is just amazing !Lol
     
  15. Offline

    VictoryShot

    It's also kinda laggy.
     
  16. Offline

    Slikey

    Yeah. You have to control it for yourself... Scale down the particles.. If you create alot of them, you are going to have a problem with the bandwidth the packets use. You might set the period of the helix to 10. I think I left this relict behind, from testing.. I create my effect always with period = 1, to get best visual effect.
     
  17. Offline

    LCastr0

    VictoryShot Slikey I would also like to see that! :p

    By the way, I am trying to do the Helix, but it only shows one strand :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  18. Offline

    Slikey


    LCastr0 Hmm.. Do you have some code for me, or are you using the test-plugin?
     
  19. Offline

    LCastr0


    Code:
    public int strands = 8;
        public int particles = 80;
        public float radius = 10;
        public float curve = 10;
        public double rotation = Math.PI / 4;
        public Plugin pl = this;
     
        public void start(final Player p) {
            getServer().getScheduler().scheduleSyncDelayedTask(this,
                    new Runnable() {
                        public void run() {
                            final int s;
                            s = getServer().getScheduler().scheduleSyncRepeatingTask(pl, new Runnable(){
                                public void run(){
                                    Location location = p.getLocation().add(0, 10, 0);
                                    for (int i = 1; i <= strands; i++) {
                                        for (int j = 1; j <= particles; j++) {
                                            float ratio = (float) j / particles;
                                            double angle = curve * ratio * 2 * Math.PI
                                                    / strands + (2 * Math.PI * i / strands)
                                                    + rotation;
                                            double x = Math.cos(angle) * ratio * radius;
                                            double z = Math.sin(angle) * ratio * radius;
                                            location.add(x, 0, z);
     
                                            ParticleEffect.FLAME.display(location, 0, 0, 0,
                                                    0, particles);
     
                                            // Subtracting x and z to get to the first
                                            // location again.
                                            location.subtract(x, 0, z);
                                        }
                                    }
                                }
                            }, 10L, 10L);
                           
                            getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable(){
                                public void run(){
                                    getServer().getScheduler().cancelTask(s);
                                }
                            }, 40L);
                           
                        }
                    }, 40L);
        }
     
  20. Offline

    Slikey

    LCastr0 Oh.. The copy&paste is strong in this one.. I think you have to figure it out yourself.. I don't know what "ParticleEffect.Flame.display()" does. Sorry
     
  21. Offline

    LCastr0

    This is the lib I use to show the particles :p
     
  22. Offline

    Slikey

    @LCastr0Why do you pass "particles" to it? It is just the amount of particles per strand.
     
  23. Offline

    LCastr0

    I know, just to keep the same amount of particles in each location. I'm still trying to find a way to repeat it :/
     
  24. Offline

    coco5843

    You can make this ?



    if you need the source code , tell me ! :D
     
  25. Offline

    LCastr0

    I want that code :confused:
     
    Dread9Nought likes this.
  26. Offline

    Slikey

    LCastr0 I'll do something similar to that after I finish the cone.
    coco5843 If you have the source, I'd appreciate if you'd open the source to everyone. I'd save some time on doing the math.. ;)
    VictoryShot Maybe, I'll release a new version tonight with the cone.. I just have to turn it around the Z-Axis. Now reading about rotation-matricies.. ;) Current Progress down here.

    [​IMG]
     
    LCastr0 likes this.
  27. Offline

    LCastr0

    Can't wait! :p
     
  28. Offline

    VictoryShot

    Zomg sickk dude cant wait :D
     
  29. Offline

    Slikey

    VictoryShot LCastr0 Just finished it. The cone goes into the direction you pass the player with the location. If you pass the effect a location of a player. It'll fire the cone in the direction the player is looking.

    If someone has the ability to make a video of my effects, please do so. I don't want to install Fraps at the moment.

    EDIT: I don't know, why I don't get approved on BukkitDev.. Too sad, nobody is looking into my project..

    [​IMG]

    DOWNLOAD LINK UPDATED

    EDIT 2:
    I also added these classes: MathUtils, VectorUtil and RandomUtil.
    MathUtils adds extras like degreeToRadians and better cosinus, sinus algorithms.
    VectorUtil includes rotation-matricies and later some projection-matricies (ASAP)
    RandomUtil provides random angles, vectors, circles, etc..
     
    bobacadodl likes this.
  30. Offline

    LCastr0

    Can you post the source?
     
Thread Status:
Not open for further replies.

Share This Page