Solved Having problem with particle effects :D

Discussion in 'Plugin Development' started by Geekhellmc, Aug 24, 2014.

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

    Geekhellmc

    What I created: A particle class for Paticle inventory

    What I expected to happen: When the player joins a game, the inventory immediatly opens showing 2 particle effects: White and Red! When the player clicks a particle effect it gives it to him for 100 sec.

    What really happened: Player joins the game, inventory immediatly opens showing 2 particle effects: White an Red. When player clicks a particle effect, the inventoru close and nothing happens.

    Particle Class:
    Code:java
    1. package me.Geekhellmc.SSB.listeners;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Effect;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.inventory.InventoryClickEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15. public class Particles implements Listener{
    16.  
    17. public static Inventory Particle = Bukkit.createInventory(null, 9, "Particle Shop");
    18. static{
    19. ItemStack White = new ItemStack(Material.WOOL);
    20. ItemMeta WhiteM = White.getItemMeta();
    21. WhiteM.setDisplayName(ChatColor.WHITE + "White Particle");
    22. White.setItemMeta(WhiteM);
    23. Particle.addItem(White);
    24. ItemStack Red = new ItemStack(Material.REDSTONE_BLOCK);
    25. ItemMeta RedM = White.getItemMeta();
    26. WhiteM.setDisplayName(ChatColor.RED + "RED Particle");
    27. White.setItemMeta(RedM);
    28. Particle.addItem(Red);
    29. }
    30.  
    31. @SuppressWarnings("deprecation")
    32. @EventHandler
    33. public void onInventoryClick(InventoryClickEvent event) {
    34. Player player = (Player) event.getWhoClicked(); // The player that clicked the item
    35. ItemStack clicked = event.getCurrentItem(); // The item that was clicked
    36. Inventory inventory = event.getInventory(); // The inventory that was clicked in
    37. if (inventory.getName().equals(Particle.getName())) {
    38. if (clicked.getType() == Material.WOOL) { // The item that the player clicked
    39. event.setCancelled(true); // Make it so the dirt is back in its original spot
    40. player.closeInventory(); // Closes there inventory
    41. player.playEffect(player.getLocation(),Effect.SMOKE, 100);
    42. player.closeInventory();
    43.  
    44. }
    45. if (clicked.getType() == Material.REDSTONE_BLOCK){
    46. event.setCancelled(true);
    47. player.closeInventory();
    48. player.playEffect(player.getLocation(), Effect.BOW_FIRE, 100);
    49. }
    50. if (clicked.getType() == Material.DIAMOND_SWORD) { // The item that the player clicked
    51. event.setCancelled(true); // Make it so the dirt is back in its original spot
    52. player.closeInventory(); // Closes there inventory
    53. player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD, 1));
    54. player.closeInventory();
    55. }
    56.  
    57. }
    58. }
    59. }
    60.  
     
  2. Offline

    MnMaxon

    I think the problems come from where you have play effect player.playEffect(player.getLocation(),Effect.SMOKE, 100); player.playeffect() only affects player. No one else will see it.

    Another problem is I think you're trying to use something like playeffect(location, effect, time). It should be playeffect(location, effect, data). Honestly I'm not too sure what data does, I usually leave it at 0 (except I use 31 for smoke). Replace player.playEffect(player.getLocation(),Effect.SMOKE, 100); with:
    Code:java
    1. EffectLoop(player, Effect.SMOKE, 20*100);//There are 20 ticks in one second

    And add the method EffectLoop
    Code:java
    1. private static void EffectLoop(final Player p, final Effect effect, final int ticks) {
    2. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    3. public void run() {
    4. if (p.isOnline()&&p.isValid()) {
    5. if (ticks <= 0) {//Stop the loop when time runs out
    6. return;
    7. } else {
    8. p.getWorld().playEffect(p.getLocation(), effect, 0);//world.playeffect plays the effect to everyone
    9. EffectLoop(p, effect, ticks - 5);//Starts the loop again
    10. }
    11. }
    12. }
    13. }, 5L);//This will repeat every 5 ticks (4 times per second)
    14. }


    Tag me if you need any more help/clarification on what I did
     
  3. Offline

    Geekhellmc

    Thanks it worked
     
  4. Offline

    SantaClawz69

    Geekhellmc I think you should prefix this to solved so other members that might need help know that this could be a solution xD
     
  5. Offline

    Geekhellmc

Thread Status:
Not open for further replies.

Share This Page