Library [1.8] ParticleEffect v1.7

Discussion in 'Resources' started by DarkBladee12, Jun 20, 2013.

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

    darkness1999

    You should get an error in your code above because you cast to Sheep but you can not be sure that it is a sheep, you should do instead:

    Code:
    public void onSheep(PlayerInteractEntityEvent e) {
        if(e.getRightClicked() instanceof Sheep) {
            Sheep s = (Sheep) e.getRightClicked();
            //DO SOMETHING
        }
    }
    Maybe the particles do not show up because you forgot to register your listener?

    EDIT: But only if the entity you clicked is not a sheep.
     
  2. Offline

    Captain Dory

    It's been registered. I'll try what you said :)

    Dont worry, i found out what was wrong- I had particles turned off in optifine settings
    .________________________.

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

    Hexcept

    How would I make the particles appear for a few seconds?
     
  4. Offline

    97WaterPolo

    Hexcept
    Make a repeating task for it.
    I currently use this code below. I have it set up so if it is running, and you do /snow again, it will disable the particles this way you don't need to use args like /snow on and /snow off. I know its a little messy, made this awhile back.

    Code:java
    1. Map<String, Integer> snow = new HashMap<String, Integer>(); //record scheduler & players
    2. if (cmd.getName().equalsIgnoreCase("snow") || cmd.getName().equalsIgnoreCase("snow")) {//cmd name
    3. if (sender.hasPermission("remc.particle.snow")) {// cmd permission
    4.  
    5. if (!snow.containsKey(sender.getName())) { //if the map does NOT contain them
    6. player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 0); // Plays sound when activated
    7. int snowtask = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() //Repeating task
    8.  
    9. {
    10.  
    11. @Override
    12. public void run() {
    13. ParticleEffect.SNOW_SHOVEL.display(player.getLocation(), .15F, 0.15F, 0.15F, .1F, 10); //plays snow effect
    14.  
    15. }
    16.  
    17. }, 0, 1L); //How often this runs. I have it run every tick, so 20times a second.
    18. player.sendMessage(ChatColor.BLUE + "Snow has been enabled!"); //Enable message
    19. snow.put(sender.getName(), snowtask); //Add them to the Map
    20. else if (snow.containsKey(sender.getName())) { //If they ARE in the map.
    21. player.sendMessage(ChatColor.AQUA + "Snow has been disabled!"); //disable message
    22. player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 0); //disable sound
    23. Bukkit.getScheduler().cancelTask(explosion.get(sender.getName())); //cancels the repeating task
    24. explosion.remove(sender.getName()); //removes then from the Map
     
  5. Offline

    lewysryan

    This is amazing! good job I love it.
     
  6. Offline

    stonebloodtv

    @97waterpolo Hi, how use your code please ? :(
     
  7. Offline

    97WaterPolo

    stonebloodtv
    Thats a command, all you have to do is make it under CommandExecutor or add it to your main class? Need an example?
     
  8. Offline

    stonebloodtv

    ]@97waterpolo I'm benginer (And french.. Sorry for bad english ^^)
    I need make a effect during 10 secondes (example) but i dont know how make this...
    If i enter your code in class, return more error and explosion.get dont work...
    If you have a example of all code (Main), it's so good :/
     
  9. Offline

    97WaterPolo

    stonebloodtv
    Sure, no problem, I will edit it so that you can see how it works. Do you want it to be a trail itself? Or what do you want it to do?

    You will also need to add DarkBlade12's libs to your package and just import them.
     
  10. Offline

    stonebloodtv

    @97waterpolo Thank you so much ! If "trail itself" = particle follow the player, is ok :rolleyes:
     
  11. Offline

    97WaterPolo

    stonebloodtv

    Tried to explain it the best I could, make sure to register the command, as well as add DarkBlade's lib.

    Code:
    package [YOUR PACKAGE HERE];
     
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Random;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Sound;
    import org.bukkit.block.BlockFace;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
     
     
    import [YOUR PACKAGE HERE].ParticleEffect;
     
    public class Explosion extends JavaPlugin {
        public void onEnable()
        {
            Bukkit.getServer().getScheduler().cancelAllTasks(); //Cancels all particle effects that are currently active.
        }
     
        public void onDisable()
        {
            Bukkit.getServer().getScheduler().cancelAllTasks(); //Cancels all particle effects that are currently active.
        }
     
        /**
        * This is the trail, basically its based off a circle.
        * For 360degrees this will always have the particles behind the player
        */
        public BlockFace getDirection(Player player) {
            double rotation = (player.getLocation().getYaw() - 180) % 360;
            if (rotation < 0)
                rotation += 360.0;
            if (0 <= rotation && rotation < 40.0)
                return BlockFace.NORTH;
            else if (40.0 <= rotation && rotation < 80.0)
                return BlockFace.NORTH_EAST;
            else if (80.0 <= rotation && rotation < 120.0)
                return BlockFace.EAST;
            else if (120.0 <= rotation && rotation < 160.0)
                return BlockFace.SOUTH_EAST;
            else if (160.0 <= rotation && rotation < 200.0)
                return BlockFace.SOUTH;
            else if (200.0 <= rotation && rotation < 240.0)
                return BlockFace.SOUTH_WEST;
            else if (240.0 <= rotation && rotation < 280.0)
                return BlockFace.WEST;
            else if (280.0 <= rotation && rotation < 320.0)
                return BlockFace.NORTH_WEST;
            else if (320.0 <= rotation && rotation < 360.0)
                return BlockFace.NORTH;
            else
                return null;
        }
        Map<String, Integer> explosion = new HashMap<String, Integer>(); //The map that controls the scheduler as well as the toggling of the particles
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            final Player player = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("explosion") && (sender.hasPermission("YOUR.PERMISSION.HERE")))
            {
                if (!explosion.containsKey(sender.getName())) //Checking to see if they have it enabled
                {
                    player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 0);//play a sound
                    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();//creating a new scheduler
                    int explosiontask = scheduler.scheduleSyncRepeatingTask(this, new Runnable()//Defining the repeating task
                    {
                        @Override
                        public void run() {
                            //|This is the particle from DarkBlade|  |                    This is the location, this will have it display behind the player                        |  | This is the default values from the method    |
                            ParticleEffect.HUGE_EXPLOSION.display(player.getLocation().getBlock().getRelative(getDirection(player).getOppositeFace()).getLocation().add(0.5, 0.25, 0.5), .15F, 0.15F, 0.15F, .1F, 10);
                        }
                    }, 0, 1L);
                    player.sendMessage(ChatColor.BLUE + "Explosions have been enabled!");
                    explosion.put(sender.getName(), explosiontask);//Adds them to the hashmap
                }
                else if (explosion.containsKey(sender.getName()))
                {
                    player.sendMessage(ChatColor.AQUA + "Explosions have been disabled!");
     
                    player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 0); //Plays a sound
                    Bukkit.getScheduler().cancelTask(explosion.get(sender.getName()));//cancels the trail that follows them
                    explosion.remove(sender.getName());//removes them from the toggle list
     
                }
            }
            else
            {
                player.sendMessage(ChatColor.DARK_RED + "You do not have permission to use this command.");
            }
        }
    }
     
  12. Offline

    stonebloodtv

    @97waterpolo 'An internal error...' NAN ! >_<

    I have add on plugin.yml the command /explosion
    Code:
    commands:
        explosion:
            description: Nianiania
            usage: /explosion
    I have create a second class
    Code:java
    1. package fr.eclozion.rpg;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.util.ArrayList;
    6. import java.util.HashMap;
    7. import java.util.List;
    8. import java.util.Map;
    9. import java.util.Random;
    10.  
    11. import org.bukkit.Bukkit;
    12. import org.bukkit.ChatColor;
    13. import org.bukkit.Effect;
    14. import org.bukkit.Sound;
    15. import org.bukkit.block.BlockFace;
    16. import org.bukkit.command.Command;
    17. import org.bukkit.command.CommandExecutor;
    18. import org.bukkit.command.CommandSender;
    19. import org.bukkit.configuration.file.FileConfiguration;
    20. import org.bukkit.entity.Player;
    21. import org.bukkit.event.inventory.InventoryClickEvent;
    22. import org.bukkit.inventory.Inventory;
    23. import org.bukkit.plugin.Plugin;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25. import org.bukkit.scheduler.BukkitScheduler;
    26.  
    27.  
    28. import fr.eclozion.rpg.api.particule.ParticleEffect;
    29.  
    30. public class Explosion implements CommandExecutor {
    31.  
    32. /**
    33. * This is the trail, basically its based off a circle.
    34. * For 360degrees this will always have the particles behind the player
    35. */
    36. public BlockFace getDirection(Player player) {
    37. double rotation = (player.getLocation().getYaw() - 180) % 360;
    38. if (rotation < 0)
    39. rotation += 360.0;
    40. if (0 <= rotation && rotation < 40.0)
    41. return BlockFace.NORTH;
    42. else if (40.0 <= rotation && rotation < 80.0)
    43. return BlockFace.NORTH_EAST;
    44. else if (80.0 <= rotation && rotation < 120.0)
    45. return BlockFace.EAST;
    46. else if (120.0 <= rotation && rotation < 160.0)
    47. return BlockFace.SOUTH_EAST;
    48. else if (160.0 <= rotation && rotation < 200.0)
    49. return BlockFace.SOUTH;
    50. else if (200.0 <= rotation && rotation < 240.0)
    51. return BlockFace.SOUTH_WEST;
    52. else if (240.0 <= rotation && rotation < 280.0)
    53. return BlockFace.WEST;
    54. else if (280.0 <= rotation && rotation < 320.0)
    55. return BlockFace.NORTH_WEST;
    56. else if (320.0 <= rotation && rotation < 360.0)
    57. return BlockFace.NORTH;
    58. else
    59. return null;
    60. }
    61. Map<String, Integer> explosion = new HashMap<String, Integer>(); //The map that controls the scheduler as well as the toggling of the particles
    62.  
    63. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    64. {
    65. final Player player = (Player) sender;
    66. if (cmd.getName().equalsIgnoreCase("explosion"))
    67. {
    68. if (!explosion.containsKey(sender.getName())) //Checking to see if they have it enabled
    69. {
    70. player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 0);//play a sound
    71. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();//creating a new scheduler
    72. int explosiontask = scheduler.scheduleSyncRepeatingTask((Plugin) this, new Runnable()//Defining the repeating task
    73. {
    74. @Override
    75. public void run() {
    76. //|This is the particle from DarkBlade| | This is the location, this will have it display behind the player | | This is the default values from the method |
    77. ParticleEffect.HUGE_EXPLOSION.display(player.getLocation().getBlock().getRelative(getDirection(player).getOppositeFace()).getLocation().add(0.5, 0.25, 0.5), .15F, 0.15F, 0.15F, .1F, 10);
    78. }
    79. }, 0, 1L);
    80. player.sendMessage(ChatColor.BLUE + "Explosions have been enabled!");
    81. explosion.put(sender.getName(), explosiontask);//Adds them to the hashmap
    82. }
    83. else if (explosion.containsKey(sender.getName()))
    84. {
    85. player.sendMessage(ChatColor.AQUA + "Explosions have been disabled!");
    86.  
    87. player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 0); //Plays a sound
    88. Bukkit.getScheduler().cancelTask(explosion.get(sender.getName()));//cancels the trail that follows them
    89. explosion.remove(sender.getName());//removes them from the toggle list
    90.  
    91. }
    92. }
    93. return false;
    94. }
    95. }

    And i have declared the command on main
    Code:
            this.getCommand("explosion").setExecutor(new Explosion());
    Arrrg, i'm sorry.. You can help me ? :oops:


    Edit: I have add on implements the CommandExecutor for the getcommand of main..
     
  13. Offline

    97WaterPolo

    stonebloodtv
    That looks good, what is the error? I need all of it so I can see whether or not it was in the class I gave to you or an error somewhere else.
     
  14. Offline

    stonebloodtv

    When i have your code, i have a error for declare..
    I think the problem is with the CommandExecutor of the Explosion.class
    Or of the Main..

    this.getCommand("explosion").setExecutor(new Explosion());

    :/
     
  15. Offline

    97WaterPolo

    stonebloodtv
    In console when the command is executed, it would throw an error. I need that error from console, all of it. And instead of using "this.getCommand" try just "getCommand" which is what I use. Also, can with the error, can you send me your main class.


    stonebloodtv
    Please PM me if you have any more questions regarding this, I forgot we were on a Lib forum not a support forum.

    DarkBladee12
    Sorry for having this troubleshooting on your forum, forgot where we were discussing this.
     
  16. Offline

    stonebloodtv

    @97waterpolo Ok thank you.

    I use bukkit but i have got a problem on my heberger, and he have edit my craftbukkit on spigot --'
    I'm going to return on craftbukkit

    (Sorry for spam here :S )
     
  17. Offline

    DarkBladee12

    97waterpolo No problem, this fits perfectly in this thread ;)
     
  18. how can i add a location when im using it in a Bukkit.getScheduler()?
    please help
     
  19. Offline

    97WaterPolo

    Hendrik_the_best
    Same way you would normally do. You can make up your own location like "Location loc = [location stuff]" or you can use "player.getLocation();" which spawns it where the player is.
     
  20. 97WaterPolo
    player.getLocation() doesnt work bc its in a Bukkit.getScheduler() (if it does im sorry)
    how can i make it so i can get the cords from a config with Location loc? right now i have
    Code:java
    1. double x = getConfig().getDouble("TEST" + ".x"), y = getConfig().getDouble("TEST" + ".y"), z = getConfig().getDouble("TEST" + ".z");



    sorry if this is easy everyone needs his start :)
     
  21. Offline

    97WaterPolo

    Hendrik_the_best
    It should, you have to change "Player player = (Player) sender;" to "final Player player = (Player) sender;"

    And I believe coords in that sense should be stored and saved as int, not sure if doubles work as I have never tried, hopefully someone can correct me.
     
  22. @97WaterPolo the whole
    "sender" thing doesnt work

    nvm got the final Player player = (Player) sender; to work but i kinda want to load it from a config how could i do that?

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

    97WaterPolo

    Hendrik_the_best
    Just depends how you saved it to the config. Most common way is to save the x y and z.

    So this to save it,
    this.getConfig().addDefault("Spawn.X", player.getLocation().getX()) ;
    this.getConfig().addDefault("Spawn.Y", player.getLocation().getY()) ;
    this.getConfig().addDefault("Spawn.Z", player.getLocation().getZ()) ;

    and to load
    int locx = this.getConfig().getInt("Spawn.X");
    int locy = this.getConfig().getInt("Spawn.Y");
    int locz = this.getConfig().getInt("Spawn.Z");

    and to teleport
    player.teleport(new Location(player.getWorld(), locx, locy, locz));

    I am totally guessing this code, not sure if it is right or has errors. Need any help/further questions feel free to tahg me!
     
  24. @97WaterPolo
    it wont take the x y z -_- :(

    this is the code (ctrl and space way)
    ParticleEffect.FIREWORKS_SPARK.display(center, offsetX, offsetY, offsetZ, speed, amount);
    http://imgur.com/hsZiQrs
     
  25. Offline

    97WaterPolo

  26. @97WaterPolo i made it just a x at int now i made it locx still doesnt work
    (i did it for the x y and z)
     
  27. Offline

    97WaterPolo

    Hendrik_the_best
    If you need any more help by going into detail, a PM conversation would be best as I don't want to create spam here! :p Mind PMing me your code as well as the issue please?
     
  28. Offline

    bennie3211

    Maybe a weird question, but whats the name of the particle that is displayed when something hits the water? Those tiny blue blocks xD
     
  29. Offline

    DarkBladee12

    bennie3211 likes this.
  30. Offline

    LCastr0

    If I'm too far from the place where the particle is spawned, I can't see it. Why?
     
Thread Status:
Not open for further replies.

Share This Page