Disappear Items on the Ground

Discussion in 'Plugin Development' started by ajs333, Nov 3, 2013.

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

    maxben34

    ajs333
    What exactly are these errors?
     
  2. Offline

    ajs333

    maxben34
    It says onItemSpawn() require a body...
     
  3. Offline

    maxben34

    You made the body for that under the itemspawnevent code. You are just calling that event using the method name, which happens to be onItemSpawn() inside another Event.

    It shouldnt be tht difficult.
     
  4. Offline

    ajs333

    maxben34
    Sorry, but I'm sorta new to coding and I'm trying to learn! So when I put it in I got an error... :/
     
  5. Offline

    maxben34

    I can tell that you're new. If you post your whole class i can help you much easier,i also recommend thr you learn java before bukkit if you havent already. To learn the bukkit api better you can watch somebody like pogostick29dev after watching java tutorials from somebody like thenewboston.
     
  6. Offline

    FinalFred

    Try this:

    Code:
        @EventHandler
        public void onDeath(PlayerDeathEvent event) {
            final Location deathLocation = event.getEntity().getLocation();
            final World w = event.getEntity().getWorld();
     
            getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
     
                @Override
                public void run() {
                    for (Item e : w.getEntitiesByClass(Item.class)) {
                        if (e.getLocation().distanceSquared(deathLocation) < 16) {
                            e.remove();
                        }
                    }
                }
     
            }, 100L);
        }
    Shamelessly stole part of The Gaming Grunts code. :)


    For those curious about the first suggestion:
    event.getDrops() is just a list of item stacks that will be dropped as part of the event. If the list isn't cleared before the event finishes nothing will happen... but if you clear the list before the event finishes, then the items won't get dropped at all. So what I'm trying to do is go through all the items currently spawned and see if they're near the death site (4 blocks). If they are near, they're probably from that person's death, so I mark them for deletion.

    I use distanceSquared() instead of distance() to avoid the square root. You can change it to distance if you really want.

    It also seems like bad style to keep an event around (inherently designed to be temporary), which is why I un-finaled the event and made two local variables instead to just keep the information I needed. Keeping the event final will probably work too.
     
  7. Offline

    ajs333

    Hmmm
    I will try that! Thank you!
     
  8. Offline

    FinalFred

    Did it work? Admittedly I didn't test it :(
     
  9. Offline

    ajs333

    FinalFred
    I'm not able to test it now because Minecraft is down... :(

    FinalFred
    I want it so that once the items are on the ground for 7 seconds they disappear..

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

    FinalFred

    What did the code I provided do?
     
  11. Offline

    ajs333

    FinalFred
    It worked so far! :) Thanks!

    FinalFred
    There is one issue tho... when a player throws an item out of his inventory it doesn't clear that item...

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

    FinalFred

    Oh, you want EVERY item that drops, regardless of reason, to disappear after 5 seconds?

    Or what do you mean, why should it disappear after 5 seconds if a player throws it out of their inventory?
     
  13. Offline

    ajs333

    FinalFred
    I want EVERY item that drops to be only on the floor for 10 seconds and then disappear...

    Does anyone know how to do this?

    FinalFred
    Do you also know how to do it with player throwing an item?

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

    FinalFred

    Oh, I thought you just meant the items that someone drops when they die. You said:


    Anyway, if you want EVERY item to disappear, then the code maxben34 provided should work, with a slight modification:
    Code:
        @EventHandler
        public void onItemSpawn(final ItemSpawnEvent e) {
            Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) this, new Runnable() {
                public void run() {
                    e.getEntity().remove();
                }
            }, 10 * 20);
        }
    
    Also, ignore the comment about calling it from inside of your death event. Just put this in your plugin Java file, assuming your plugin is also your event handler.
     
  15. Offline

    ajs333

    FinalFred
    Yeah, It worked but how do I add a little smoke when it disappears...?
     
  16. Offline

    FinalFred

    I believe you just spawn a smoke particle at the location of the ItemStack. Shouldn't be that difficult once you figure out how to spawn particles (I don't know off the top of my head).
     
  17. Offline

    ajs333

  18. Offline

    maxben34

    Use the play effect at the location of it. Smoke is playEffect(loc,Effect.Smoke,0)
     
  19. Offline

    MordorKing78

    maxben34 Don't be rude. People should be open to learn from others. And you are not helping by saying "learn java first"
     
  20. Offline

    fireblast709

    MordorKing78 you do realize that this thread is a little less than a year old, don't you?
     
    MordorKing78 and VG.Developments like this.
  21. Offline

    MordorKing78

    fireblast709
    ………………..,-~*’`¯lllllll`*~,
    …………..,-~*`lllllllllllllllllllllllllll...
    ………,-~*lllllllllllllllllllllllllllllll...
    ……,-*lllllllllllllllllllllllllllllllll...
    ….;*`lllllllllllllllllllllllllll,-~*~-...
    …..\lllllllllllllllllllllllllll/………\;;...
    …...\lllllllllllllllllllll,-*………..`~-~...
    …….\llllllllllll,-~*…………………)_-\..*`*;....
    ……..\,-*`¯,*`)…………,-~*`~.………….../
    ……...|/.../…/~,…...-~*,-~*`;……………./.\
    ……../.../…/…/..,-,..*~,.`*~*…………….*......
    …….|.../…/…/.*`...\...……………………)….)¯`~,
    …….|./…/…./…….)……,.)`*~-,……….../….|..)...
    ……/./.../…,*`-,…..`-,…*`….,---…...\…./...
    …...(……….)`*~-,….`*`.,-~*.,-*……|…/.…/…...
    …….*-,…….`*-,...`~,..``.,,,-*……….|.,*....
    ……….*,………`-,…)-,…………..,-* `...,-*….(`-,...
     
    fireblast709 likes this.
  22. Offline

    maxben34

    Although this is about a year old, I'd be happy to discuss your above statement. First of all, I'm not being rude when I tell people to learn java first. It should be blatantly obvious that bukkit is an API for JAVA and therefore requires java knowledge to use properly. People should be able to learn from others, but posting code that answers somebody's question does the exact opposite. If you give somebody the answer they are looking for without reasoning, by just giving a rookie some code to solve their problem, you're inhibiting them from learning the API or possibly even java. It is the people that give code out just to solve a problem that make the plugin development forum sub par in my opinion. If people didn't ask for code, but instead realized the importance of exploring a programming language and discovering solutions to their problem with some help of knowledgeable people within these forums, then the plugin development section would become a place where anybody can learn something programming related, instead of the place that it currently is in which people with no java programming experience post threads asking for code because they simply don't have the motivation to learn enough about coding to be able to develop their own solution.
     
    MordorKing78 likes this.
Thread Status:
Not open for further replies.

Share This Page