playEffect only happens once of trails plugin

Discussion in 'Plugin Development' started by AndersonEpic, May 24, 2014.

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

    AndersonEpic

    I'm only getting the these effects for my trails plugin once, here's the code:

    By the way this plugin has multiple classes

    Code:
    package me.anderson.trails;
    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.ItemStack;
    public class ClickListener implements Listener {
     
        @EventHandler
        public void onClick(InventoryClickEvent event){
            HumanEntity entity = event.getWhoClicked();
            if ((entity instanceof Player)){
                Player player = (Player)entity;
           
                if (event.getInventory().getName().equals(MainClass.getCompassInventory().getName())){
               
                    event.setCancelled(true);
               
                    ItemStack clicked = event.getCurrentItem();
                    if (clicked!=null){
                   
                        if (clicked.getType()==Material.FIREWORK_CHARGE){
                       
                            player.closeInventory();
                            player.getLocation().getWorld().playEffect(player.getLocation().add(0, -1, 0), Effect.SMOKE, 1);
                            player.getLocation().getWorld().playEffect(player.getLocation().add(0, -1, 0), Effect.SMOKE, 1);
                        }
                        else if (clicked.getType()==Material.FIRE){
                       
                            player.closeInventory();
                            player.getLocation().getWorld().playEffect(player.getLocation().add(0, -1, 0), Effect.MOBSPAWNER_FLAMES, 1);
                            player.getLocation().getWorld().playEffect(player.getLocation().add(0, -1, 0), Effect.MOBSPAWNER_FLAMES, 1);
                        }
                        else if (clicked.getType()==Material.ENDER_PEARL){
                       
                            player.closeInventory();
                            player.getLocation().getWorld().playEffect(player.getLocation().add(0, -1, 0), Effect.ENDER_SIGNAL, 1);
                            player.getLocation().getWorld().playEffect(player.getLocation().add(0, -1, 0), Effect.ENDER_SIGNAL, 1);
                       
                        }
                   
                    }
               
                }
           
            }
        }
    }
     
  2. Offline

    fireblast709

    AndersonEpic so what is it that you try to achieve? The code should only play the effect twice (but on the same location and at the same time, which might look like it is playing once).
     
  3. Offline

    AndersonEpic

    I'm trying to make so where ever a player moves the trail(effect) follows them.
     
  4. Offline

    mine-care

    Use a array list to store people who have the effect applyed, and use on player move event, then play the effect ;-)
     
  5. Offline

    AndersonEpic

    You mind typing down the code, because I don't know to use ArrayList yet?
     
  6. Offline

    fireblast709

    AndersonEpic Most of it is basic Java and Bukkit. Don't ask to be spoon-fed.
     
  7. Offline

    AndersonEpic

    Well sorry. If I need help I ask. I'd rather bee "spoon-fed" then not knowing

    It would be really nice if you could help me with ArrayLists

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

    fireblast709

    I rather teach you so you know next time, then have you simply copy-paste and learn nothing.

    Despite what was said earlier, I suggest you to read about Sets instead, since they are faster when it comes to checking whether a value is inside a Set or not (Lists are useful when you need random elements, or when you need to loop over the values). The PlayerMoveEvent is just an event you can listen to, just like you did with the InventoryClickEvent.
     
  9. Offline

    AndersonEpic

    Thanks for the help, but copy and pasting it will help me out by reading the code and seeing what I need to do next time i I come across a plugin like this
     
  10. Offline

    mine-care

    Just open a conversation with me and ask me stuff at any time :D I'm on iOS and I can't code tht well but ill search my cloud for a pre made piece of code.
     
  11. Offline

    AndersonEpic

    Okey dokey
     
  12. Offline

    fireblast709

    -facepalms-
     
    L33m4n123 likes this.
  13. Offline

    L33m4n123

    How does your operating System hinder you to type propper code? And as fireblast709 said nicely

    -facepalms-
     
  14. Offline

    Gater12

    Code:java
    1. /* Everyday HashSet */
    2. Set<String> example = new HashSet<>();
    3.  
    4. /* Java 6 */
    5. Set<String> example = new HashSet<String>();
    6.  
    7. /* Adding a value to Set */
    8. example.add(player.getName());
    9.  
    10. /* Chekcing if value is in Set */
    11. /* returns a boolean */
    12. example.contains(player.getName());
    13.  
    14. /* Removing value from set */
    15. example.remove(player.getName());


    Did you know I did this with an iPad?
     
Thread Status:
Not open for further replies.

Share This Page