Solved ItemStack.getDurability doesn't work on the Poison Potion.

Discussion in 'Plugin Development' started by BadBoy6767, Nov 3, 2015.

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

    BadBoy6767

    @StevasaurousREX
    I used your last post and it worked, but that was probably because I skipped brewing the water bottle to an awkward potion.
    Now it's making the poison again.

    @StevasaurousREX
    Ups, sorry. Didn't see the edit.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 4, 2015
  2. Offline

    Scimiguy

    Man there's some really dirty code going on here lol
     
  3. Offline

    BadBoy6767

  4. Offline

    StevasaurousREX

    Okay so I agree with @Scimiguy that what I posted is dirty code. 1 its not scaleable. If you keep adding more potions to block then you eventually will block more potions then you meant.

    This is what I am currently thinking, it makes sure that you are blocking the right potion and that none of the potions in the brewing stand are the bad potions.
    Code:
        @EventHandler
        public void onBrew(BrewEvent e) {
            Map<Short, List<Material>> bannedPotions = new HashMap<Short, List<Material>>();
            // List of all additives to Awkward potions that are used to create banned potions.
            List<Material> awkList = new ArrayList<Material>();
            awkList.add(Material.SPIDER_EYE); // Poison
            awkList.add(Material.FERMENTED_SPIDER_EYE); // Weakness
            bannedPotions.put((short) 16, awkList);
      
            // List of all additives to Thick potions that are used to create banned potions.
            List<Material> thickList = new ArrayList<Material>();
            thickList.add(Material.FERMENTED_SPIDER_EYE); // Weakness
            bannedPotions.put((short) 32, thickList);
      
            // List of all additives to Mundane potions that are used to create banned potions.
            List<Material> munList = new ArrayList<Material>();
            munList.add(Material.FERMENTED_SPIDER_EYE); // Weakness
            bannedPotions.put((short) 8192, munList);
      
            // List of all additives to Mundane Extended potions that are used to create banned potions.
            List<Material> munExList = new ArrayList<Material>();
            munExList.add(Material.FERMENTED_SPIDER_EYE); // Weakness Extended
            bannedPotions.put((short) 64, munExList);
      
            // This is to block 1 way to make Strength 2 potions.
            List<Material> strList = new ArrayList<Material>();
            strList.add(Material.GLOWSTONE_DUST); // Str2
            bannedPotions.put((short) 8201, strList);
      
            // This is to block another way to make Strength 2 potions.
            List<Material> strExList = new ArrayList<Material>();
            strExList.add(Material.GLOWSTONE_DUST); // Str2
            bannedPotions.put((short) 8265, strExList);
      
            // This is to block 1 way to make Weakness potions.
            List<Material> strTwoList = new ArrayList<Material>();
            strTwoList.add(Material.FERMENTED_SPIDER_EYE); // Str2
            bannedPotions.put((short) 8233, strTwoList);
      
            // Must loop to check all 3 potions.
            ItemStack[] items = e.getContents().getContents();
            for(ItemStack item : items) {
                if ((item.getType() == Material.POTION) && bannedPotions.containsKey(item.getDurability())) {
                    if (bannedPotions.get(item.getDurability()).contains(items[3].getType())) {
                        e.setCancelled(true);
                        break;
                    }
                }
            }
        }
    @Scimiguy is this better?


    to add another potion check for a map that currently uses the base potions type (the short key of the map) if it does add the Material to the list created for it.

    If the base potion is not there create a List for it like so
    List<Material> (LIST NAME) = new ArrayList<Material>();

    Add materials to the list
    (LIST NAME).add(Material.(MATERIAL TO CREATE POTION);

    Add it to the HashMap
    bannedPotions.put((short) (ID FOR BASE POTION), (LIST NAME));
    IDs from metadata here http://minecraft-ids.grahamedgecombe.com/potion-calculator
    or here (DV value) http://minecraft.gamepedia.com/Potion_of_Strength#Potion_of_Strength
     
    Last edited: Nov 4, 2015
  5. Offline

    Scimiguy

    Actually that's significantly worse and omg it's gross lol
    Using data values is just inflexible, un-predictable, and needlessly complicated.
     
    Last edited: Nov 4, 2015
  6. Offline

    StevasaurousREX

    PotionType doesnt contain the base potions, and if removing the potions after they brew is all you want then waiting for them to finish is fine and simple but if you dont want to waste the players items then you have to block the event based on the ingredients.

    How would you stop the player from brewing a poison potion with out wasting their items? Also how would you block only strength II?
     
    Last edited: Nov 5, 2015
  7. Offline

    Scimiguy

    @StevasaurousREX
    With proper preparation.

    Want to add support for blocking specific potion combinations? Create a HashSet of Potion ItemStacks and compare them.

    Want to do so without wasting items?
    Put the items back when you're done handling the potion stuff....?
     
  8. Offline

    BadBoy6767

    Dudes, I got it working, I ditched the BukkitRunnable and was just checking if the ingredients needed to make that certain potion was there, and it worked.

    Thanks. Although FileConfiguration.getConfigurationSection(String) is now returning null,
    but that's for another thread.

    Thank you all ^^.
     
  9. Offline

    Scimiguy

    Please edit the title of the thread and mark it as solved then please
     
  10. Offline

    BadBoy6767

Thread Status:
Not open for further replies.

Share This Page