Solved Code Debugging

Discussion in 'Plugin Development' started by BlueMustache, Mar 14, 2014.

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

    BlueMustache

    Hello.
    Can someone see where I am going wrong here?
    I run the function, and an Enderman doesn't spawn.

    Code:java
    1. public void spawnSlendy(Location loc, Player target) {
    2. Entity slender = loc.getWorld().spawnEntity(loc, EntityType.ENDERMAN);
    3. PotionEffect pe = new PotionEffect(PotionEffectType.SLOW, 999999999, 20, true);
    4. final LivingEntity sl = (LivingEntity)slender;
    5. final Creature slendy = (Creature)slender;
    6. final LivingEntity ent = (LivingEntity)target;
    7. sl.addPotionEffect(pe, true);
    8. slendy.setTarget(ent);
    9. getLogger().info("Slendy spawned.");
    10. }


    Thanks!
     
  2. Offline

    alex123099

    BlueMustache
    Does the function execute succesfully? Do you get that "slendy spawned" message?
     
  3. Offline

    Konkz

    This won't help but...

    Code:java
    1. PotionEffect pe = new PotionEffect(PotionEffectType.SLOW, 999999999, 20, true);


    Instead of using the 999999999 just do Integer.MAX_VALUE

    Code:java
    1. PotionEffect pe = new PotionEffect(PotionEffectType.SLOW, Ingeger.MAX_VALUE, 20, true);
     
    BlueMustache likes this.
  4. Offline

    BlueMustache

    That was helpful. Thanks! :)

    I do get the message, but I do not see the creature. I also have a minimap, which could not find him.

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

    rfsantos1996

    Try using spawn method

    Code:java
    1. public void spawnSlendy(Location loc, Player target) {
    2. Enderman slender = loc.getWorld().spawn(loc, Enderman.class);
    3. PotionEffect pe = new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 20, true);
    4. slender.addPotionEffect(pe, true);
    5. slender.setTarget((LivingEntity) target);
    6. getLogger().info("Slendy spawned.");
    7. }


    Since Enderman is a Creature and LivingEntity, you don't need to cast anything. The same as the target, you can just cast right away instead of creating a variable for that.
     
    BlueMustache likes this.
  6. Offline

    MrTwiggy

    Not sure about your spawning problem, but just a heads up, you don't need to cast your objects in order to access methods.

    For instance, at one point, you cast the Player to a LivingEntity (the object called 'ent'), but you don't need to do this, since Player is a subclass of LivingEntity, and provides access to all methods offered by LivingEntity.
     
  7. Offline

    xize

    from testing using addPotionEffect never use high values like 99999 ive tried it once but by that the server ticks got wild and sometimes it even stop executing the code/spawning not sure why but on the other hand it isn't that strange.

    also why are you using final? I guess you go use them for inside a scheduler else I don't see why you should use final there.

    try casting the entity to Enderman and from there add the potion effects note don't use high values

    -edit-
    by high values in potions I do not mean the time but the data or power.
    also a other posibility could be that the Location is null.
     
  8. Offline

    BlueMustache

    Thanks guys, much appreciated!
     
Thread Status:
Not open for further replies.

Share This Page