Help Type mismatch: cannot convert from void to Entity

Discussion in 'Plugin Development' started by IcyRelic, Jul 10, 2014.

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

    IcyRelic

    im trying to spawn an entity with metadata and getting the error

    Type mismatch: cannot convert from void to Entity

    how can i fix this

    here is how im trying to spawn the entitiy

    Code:java
    1. Entity zombie = loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE).setMetadata("horde", new Metadata(plugin,1));
     
  2. Offline

    _Filip

    Code:java
    1. Entity zombie = loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
    2. zomie.setMetadata("horde", new Metadata(plugin, 1));


    The reason it does that is because setMetadata interacts with the instance, it doesn't return the instance. AKA it's not like a String, whose methods must return a new instance every time, due to it being final.
     
  3. Offline

    IcyRelic

    that sets it after the zombie spawn

    i need it as it spawns or before

    because i have this code

    Code:java
    1. package me.icyrelic.com.Listeners;
    2.  
    3. import me.icyrelic.com.Horde;
    4.  
    5. import org.bukkit.entity.Zombie;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.entity.CreatureSpawnEvent;
    9.  
    10. public class CreatureSpawn implements Listener {
    11.  
    12. Horde plugin;
    13. public CreatureSpawn(Horde instance){
    14. plugin = instance;
    15. }
    16. @EventHandler
    17. public void onCreatureSpawn(CreatureSpawnEvent e){
    18.  
    19. if(e.getEntity() instanceof Zombie){
    20. Zombie zombie = (Zombie) e.getEntity();
    21. if(!zombie.hasMetadata("horde")){
    22. e.setCancelled(true);
    23. }
    24. }else{
    25. e.setCancelled(true);
    26. }
    27. }
    28.  
    29. }
    30.  
     
  4. Offline

    _Filip

    Well that's quite a doozy!
     
  5. Offline

    IcyRelic

    What do u suggest i do? because i only need mobs that my plugin spawns spawning

    could i do it in 2 plugins? could i make a plugin to just stop spawnings and then make this plugin event priority highest or lowest and set the canceled to false?
     
  6. Offline

    feildmaster

    Well.. There's only one way to do this that I can think of from the top of my head.

    - Check if the spawn reason is plugin. (This requires you to be the only plugin that's spawning monsters)

    oh... Now that I think of it, you could use the scheduler too... But I wont get into that method.
     
Thread Status:
Not open for further replies.

Share This Page