Solved "cannot be resolved or is not a field" in EntityType?

Discussion in 'Plugin Development' started by AidoP, Mar 11, 2013.

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

    AidoP

    This is the error I get.
    ent cannot be resolved or is not a field
    and This is my code:
    int intEnttype = 0;
    EntityType ent = (EntityType.BAT);
    Player player = (Player) sender;
    switch (intEnttype){
    case 1:
    ent = EntityType.BAT;
    break;
    }
    Location blockloc = (player.getLocation());
    Bukkit.getWorld(player.getWorld().getName()).spawnEntity(blockloc, EntityType.ent);

    (Yes thats a HALF FINISHED switch-case block! so please dont comment on that :p)
    Thanks, all help appreciated!
    AidoP
     
  2. This isn't really enough code to give you much help but you're assigning ent t0 be a Bat and then assigning it to be a bat again..

    When I run this code I am not getting any errors so I assume it's due to poor formatting?
    Code:
    int intEnttype = 0;
    EntityType ent = null;
    Player player = (Player)sender;
    switch (intEnttype) {
        case 1:
            ent = EntityType.BAT;
            break;
        case 2:
            ent = EntityType.COW;
            break;
    }
    if(ent != null) player.getWorld().spawnEntity(player.getLocation(), ent);
     
  3. Offline

    AidoP


    Thanks that probably is why...
     
  4. Do you have an import for EntityType?
     
  5. Offline

    AidoP

    yes. Just testing my plugin now...

    Ok solved! (only tested with pigs!) but needs a little tweeking in diferent parts of the command. Thanks AlexLeopioriday. and hapm for helping!

    AidoP

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

    AmShaegar

    Bukkit.getWorld(player.getWorld().getName()).spawnEntity(blockloc, EntityType.ent);

    The red marked part should cause the error.Although every IDE like eclipse should mark that part in the code.
     
Thread Status:
Not open for further replies.

Share This Page