Solved There is a posible way to create mobs who cant drop items?

Discussion in 'Plugin Development' started by Paulaitass, Sep 24, 2016.

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

    Paulaitass

    i want spawn a mob that cant drop anything but only the created mob.
    Like a blaze that dont drop blaze rods.
    I searched on the API but i didn´t find anything for mobs, only for his armor slots.
     
  2. @Paulaitass
    Here's what you need to do:
    1. Subscribe to the EntityDeathEvent
    2. Use the "getDrops()" method to get a List<ItemStack> of all the items that will be dropped.
    3. Modify the list to your liking (in your case clear it, so it is completely empty).
     
  3. Offline

    Paulaitass

    mmm, but then i need set a nbtag to the mob that i want clear drops, no?
     
  4. @Paulaitass
    No, you could always save the UUID of the mob inside a List, and check if the mob is in the list.
     
  5. Offline

    Paulaitass

    mmm, okey i will try it in the night, i hope it will work, thanks you :D

    for get the uuid i need use this, no? : getPersistantID()

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 24, 2016
  6. Offline

    Zombie_Striker

    @Paulaitass
    Use getUniqueId() to get an entity's UUID.
     
  7. Offline

    Paulaitass

    i create a file.yml for store the uuid but i don't know how to store uuids on it.


    okey i think that i solved whit this code:
    Code:
     Main.Entities.set(bla.getUniqueId().toString(), 1);
                            Main.saveYamls();
    and the yml save the uuids like this: https://gyazo.com/a8d13ed53ef67feb82aad1d6cacdcacc
    Now can i use this for check it?
    @AlvinB
     
    Last edited: Sep 24, 2016
  8. Offline

    JanTuck

    Learn how to save to a yml file by reading the Configuration api reference.
    http://wiki.bukkit.org/Configuration_API_Reference

    But you can just use a list.

    Code:java
    1.  
    2. List<UUID> yourList = new ArrayList<UUID>();
    3.  


    Then just add your entity to it with
    java.util.List#add(Object)
    Example
    Code:java
    1.  
    2. yourList.add(UUID);
    3.  


    To check if the list contains the specified UUID you can check with
    java.util.List#contains(Object)
    Example:
    Code:java
    1.  
    2. if (yourList.contains(UUID)){
    3. // STUFF
    4. }
    5.  

    Yes listen on The Entity EntityDeathEvent.

    Then check if the yml contains the uuid like this

    FileConfiguration#contains(Object)
    Example
    Code:java
    1.  
    2. if (FileConfiguration.contains(UUID)){
    3. //Do stuff
    4. // Remove from yml again.
    5. }
    6.  
     
    Last edited: Sep 24, 2016
  9. Offline

    Paulaitass

    @JanTuck
    how can i check it ? Because this do not work:
    Code:
    @EventHandler
       public void onEntityDeathEvent(EntityDeathEvent e) {
         if (Main.Entitiest.contains(e.getEntity().getUniqueId())){
         ((EntityDeathEvent) e.getEntity()).getDrops().clear();}
    
    okey solved myself x)
    correct code:
    Code:
    @EventHandler
        public void onEntityDeathEvent(EntityDeathEvent e) {
            if (Main.Entitiest.contains(e.getEntity().getUniqueId())){
                e.getDrops().clear();
    Thax :
    @JanTuck

    @Zombie_Striker
    @AlvinB


    but one last thing how can i save the remaining uuids on an .yml on the stop and load it on the start and transfer it to the list again
     
    Last edited: Sep 24, 2016
  10. @Paulaitass
    To make it easier to load and save to config I would I actually make the List a List<String> and store/compare UUID#toString() in it. String Lists are easy to save and load from config, look at this example:
    Code:java
    1. List<String> myStringList = new ArrayList....
    2. ...getConfig().set("configPath", myStringList);
    3.  
    4. List<String> listLoadedFromConfig = ...getConfig().getStringList("configPath");
     
  11. Offline

    JanTuck

    Totally forgot this option sry

    Sent from Tapatalk
     
  12. Offline

    Paulaitass

    And in case that i use a hashmap, how can i load it?
    @AlvinB
     
  13. Offline

    JanTuck

  14. @Paulaitass
    HashMaps are actually quite special in Bukkit's YAML implementation. They only work if you the key in the HashMap is a String. The way you get them is like this:
    Code:java
    1. HashMap<String, Object> myHashMap = (HashMap) ...getConfig().getConfigurationSection("path.to.hashmap").getValues(false)
     
  15. Offline

    Paulaitass

  16. Online

    timtower Administrator Administrator Moderator

    @Paulaitass Use the "Tahg user" button, don't copy the link from their profile ;)
     
  17. @Paulaitass
    Like this:
    Code:java
    1. ...getConfig().createSection("path.to.hashmap", hashMap)
     
  18. Offline

    Paulaitass

Thread Status:
Not open for further replies.

Share This Page