Remove dropped items on ground

Discussion in 'Plugin Development' started by asb1230, Sep 14, 2012.

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

    asb1230

    I am trying to make a command that will remove all drops in the loaded chunks of a world, but I can't seem to find the right way to do it. I looked at the WorldEdit code and it just confused me. If anyone could suggest a few lines for this that would be great!

    Doesn't anyone know how to delete entities on the ground?

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

    Tzeentchful

    Here is a snippet of how to remove all entities in a whole world. If you want to restrict it to a area a few if statements checking the x, z positions should do the trick.
    Code:java
    1. World world = getServer().getWorld("world");//get the world
    2. List<Entity> entList = world.getEntities();//get all entities in the world
    3.  
    4. for(Entity current : entList){//loop through the list
    5. if (current instanceof Item){//make sure we aren't deleting mobs/players
    6. current.remove();//remove it
    7. }
     
  3. Offline

    asb1230

    Thank you so much! You are an amazing person! Have a great day!

    What is the colon doing there?

    another question. I put in this code:
    Code:
    else if(cmd.getName().equalsIgnoreCase("rmdrops")){
                if((args.length == 0) && (sender instanceof Player)){ //for player removing items in current world
                    Player player = (Player) sender;
                    World world = player.getWorld();
                    List<Entity> entList = world.getEntities();
                   
                    for(Entity current : entList){
                        if (current instanceof Item){
                            current.remove();
                        }
                    }
                   
                }
                else if(args.length == 1){ //for either console or player removing drops from another world
                   
                }
                else{ //if console doesn't specify a world
                   
                }
                       
            }
    and when I type /rmdrops, "/rmdrops" shows up in the chat area. Any idea why?

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

    travja

    did you put return true;?
     
  5. Offline

    asb1230

    duh thanks. I was confused since it's the second command under the onCommand method.
     
Thread Status:
Not open for further replies.

Share This Page