Solved How to make it so it rains an item above a player head?!

Discussion in 'Plugin Development' started by HeavyMine13, Dec 19, 2013.

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

    HeavyMine13

    Hai! I need to make a plugin that makes it rain a specific item, when toggled with a command, for a player! But, the item must despawn immediately, so it looks like its raining the item! PS: The player must not pickup the item, its only for show off! And, where can I set the player's name whom I want the potatoes on?

    Code:
    Code:
    package me.HeavyMine13.pot;
     
    import java.util.ArrayList;
    import java.util.HashMap;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Pot extends JavaPlugin implements Listener {
     
            public void onEnable() {
                Bukkit.getServer().getPluginManager().registerEvents(this, (Plugin) this);
        } 
           
            public void onDisable() {
            }
           
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
            private ArrayList<String> rainedOn = new ArrayList<String>();
            private HashMap<String, Integer> tids = new HashMap<String, Integer>();
     
            public void itemRain(final Player player, Material material)
            {
                //they are already being rained on
                if(rainedOn.contains(player.getName()))
                {
                    return;
                }
     
                //get their world
                final World world = player.getWorld();
     
                final ItemStack is = new ItemStack(material, 392);
     
                //create the location, one/two blocks above player
                final Location location = player.getLocation().add(0,3,0);
     
                rainedOn.add(player.getName());
     
                tids.put(player.getName(),
                        this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
                        {
     
                            public void run()
                            {
                                //cancel them if they are no longer being rained on
                                if (!rainedOn.contains(player.getName()))
                                {
                                    this.getServer().getScheduler().cancelTask(tids.get(player.getName()));
                                    tids.remove(player.getName());
                                }
     
                                final Item i = world.dropItemNaturally(location, is);
                                i.setPickupDelay(Integer.MAX_VALUE);
     
                                plugin.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
                                {
                                    @Override
                                    public void run()
                                    {
                                        i.remove();
                                    }
     
                                }, 20L);
                            }
     
                            }
     
                        }, 0L, 10L));
     
            }
     
            public void stopItemRain(Player player)
            {
                rainedOn.remove(player.getName());
            }
        }
     
  2. Offline

    se1by

  3. Offline

    Garris0n

  4. Offline

    HeavyMine13

    Garris0n Im sorry, but Me = TOTAL noob at entities (Because I don't really use them :'() SO I need an example :I :eek:
     
  5. Offline

    Mrawesomecookie

    HeavyMine13
    I think you forgot to use a tag. Its Simple! @ [Enter Username To Tag] and just remove the space bettween the @ and the username
     
  6. Offline

    HeavyMine13

    I did not tag anyone....
     
  7. Offline

    Mrawesomecookie

    Then how is he supposed to respond...
     
  8. Offline

    HeavyMine13

    I know that lol :I
     
  9. Offline

    Bart

  10. Offline

    HeavyMine13

    Thanks, but how can I choose what player is rained on?

    Added my code to original post, and I still need help Please!

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

    Dako

    HeavyMine13 ...You have a method in an EventListener. Before you start making double posts you should check it yourself and not just copying it. Oustore the voids itemRain and stopItemRain. Put the HashMap and the ArrayList in the next line of "public class Pot ext..." line. If a player joins :
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event){
    3. this.startItemRain(event.getPlayer, Material.WHAT_YOU_LIKE);
    4. }
     
  12. Offline

    Garris0n

    This is getting ridiculous, you don't even know what to do with code that you are being given in its complete form(by the way, don't do that...seriously).
    http://docs.oracle.com/javase/tutorial/
     
    AoH_Ruthless likes this.
  13. Offline

    HeavyMine13

    Im sorry :/

    Hai, the code worked except for this: this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() it gives me this error: The method getServer() is undefined for the type new Runnable(){}

    Ok solved!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page