Solved Clear Inventory

Discussion in 'Plugin Development' started by Forseth11, Jun 5, 2013.

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

    Forseth11

    Hello. I am trying to clear certain items from my inventory, but for some reason it doesn't work on voltz. Since that didn't work I want to clear the full inventory BUT NOT THE ARMOR.

    Here is my code:
    Version 1:

    Code:
    double x = event.getFrom().getX();
            double y = event.getFrom().getY();
            double z = event.getFrom().getZ();
           
           
            if((x <= 297) && (x >= 291) && (y <= 163) && (y >= 154) && (z <= 112) && (z >= 105)){
                    player.sendMessage(ChatColor.RED + "Clearing inventory!");
                    player.getInventory().clear();
            }

    Version 2:
    Code:
    double x = event.getFrom().getX();
            double y = event.getFrom().getY();
            double z = event.getFrom().getZ();
           
           
            if((x <= 297) && (x >= 291) && (y <= 163) && (y >= 154) && (z <= 112) && (z >= 105)){
                    player.sendMessage(ChatColor.RED + "Clearing tinker inventory!");
                    player.getInventory().clear(264);
                    player.getInventory().clear(35);
                    player.getInventory().clear(25031);
                    player.getInventory().clear(265);
            }
    How do I clear the inventory and not the armor?
     
  2. Offline

    chasechocolate

    player.getInventory().clear().
     
    TheGamesHawk2001 likes this.
  3. Offline

    Wingzzz

    Forseth11
    If you want to clear the inventory yet not the armor slots, you can't use the player.getInventory().clear(); method as it clears the full inventory. You will need to get the inventory and loop through each item and remove it (I believe you can just check the slot of the item and if it's an armor slot skip that item).
     
  4. Offline

    Forseth11

    chasechocolate I tried that. It gets rid of the armor too.

    WiredWingzzz can you give me an example and do you know if that would work on voltz?
     
  5. Offline

    JoTyler

    By looking at that code it seems your trying to ONLY remove certain items ... ? You can save the armor to a hashmap clear inventory and give the armor back. Not at my computer so can't type out the code but something like that
     
  6. Offline

    Forseth11

    JoTyler I am trying to remove certain items. If you ever played voltz before you would know you you can dupe items at the tinker table and I am trying to remove the tinker upgrades from the players inventory, but that seems to not work.
    I haven't used a hashmap before, but there is always a first. I'll try your idea. Thanks

    JoTyler can you even add armor from a mod onto a player with bukkit?

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

    Wingzzz

    Forseth11
    No, Bukkit works with vanilla items, graphics, etc... only. It does not support textures outside of Minecraft's defaults unless you use other mods/plugins with it ie: Spout.
     
  8. Offline

    Forseth11

    WiredWingzzz it runs with tekkit and bukkitforge. I'm just trying to make a simple plugin that will help stop duping items in the game.

    Is there a way to just remove certain items? I couldn't get it to work with just iron, wool, or diamonds.

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

    Wingzzz

    I wasn't aware, but if you're using the Bukkit API solely it will not work for anything outside of vanilla Minecraft. Now if you're using something that will bridge bukkit or do something to make it work, I'm not entirely sure you if could then do it with Bukkit code, although feel free to give it a shot. If anyone else knows any information on this it'd be great to know, or Forseth11, if you could explain a bit more about how you use the Bukkit API with tekkit/voltz etc... that'd help me (to help you?) hehe
     
  10. Offline

    Forseth11

    Is there just a simple way to remove all of one kind of item from someone's inventory?

    Thanks for trying to help. I figured it out. (AND IT WORKS FOR VOLTZ!!!!)
    JoTyler Your idea worked. I saved it to an itemstack instead.

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

    CakeProgrammer

    Try this:
    Code:
                        player.getEquipment().clear();
                        player.getInventory().clear();
     
  12. Offline

    kreashenz

    Try looping through the player.getContents() and then remove the itemstack?
     
  13. Offline

    Forseth11

  14. Offline

    JoTyler

    I was reason the thread and I was like maybe he should try an item stack because that's what I used for my plugins .... Then I read your post :) and your welcome
     
  15. Offline

    Forseth11

    oh JoTyler do you know of the plugin name that has a sign shop like this:
    Code:
    Line 1 - [buy] or [sell]
    Line 2 - <amount>
    Line 3 - <ID>
    Line 4 - <$>
     
  16. Offline

    JoTyler

    Sign shop or maybe essentials not 100% sure
     
  17. Offline

    Forseth11

    JoTyler Essentials has a shop?
     
  18. Offline

    JoTyler

  19. Offline

    oasis9

    Sorry for bumping an old thread, as the author probably found the answer, but in Essentials config.yml, you find the section marked "enabled-signs:" and take the hashes (#) from the front of each type of sign you would like to enable.
     
    ItsLeoFTW likes this.
  20. Offline

    oasis9

    Sorry for the bump, yet again, but I'm not sure why I posted that here...
     
Thread Status:
Not open for further replies.

Share This Page