The Mesmer Plugin - NPC

Discussion in 'Plugin Development' started by klofno1, Jul 11, 2013.

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

    savagesun

    Your code... is atrocious. :eek: Practicing proper indentation always helps haha. Also, you're not closing the runnable correctly.. It's just.. terrible..
    It looks like this is closer to what you were trying to write:
    Code:
    Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
     
                @Override
                public void run() {
                    //spawn
                    this.spawnZombie(e.getClickedBlock().getLocation().add(0,3,0));
                    player.sendMessage("blah");
                    player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 40, 2));
               
                    if(target.isAlive()) {
                        Location loc = target.getLocaiton();
                        nav.a(loc.getX(), loc.getY(), loc.getZ());
                    } else {
                        this.cancel();
                    }
                }
           
            }, 200L);//10 seconds
    And why are you opening a new code block for no reason down near the end?
    Code:
    }
    }
    {//<---- ?
    }
    }
    Quick edit: is this.cancel(); not giving you issues? I don't think you can cancel regular Runnable's using a cancel command if that's what you're trying to do.. If you just don't want to set the nav thing then there is no need for the else clause.
     
  2. Offline

    xTrollxDudex

    klofno1
    Add a } there after the brace after this.cancel().
    You also need to add a brace after the if checking for the IRON_SWORD

    And you should be good. Remove the { brace when you start closing up the class with }'s. And you don't really need to have the extra this.spawnZombie. Remove that. Then move the sendMessage and the add potion above the runnable.

    Other than that, you also need to add an entitycombust event and check if it is the zombie you spawned in Zombie zombie.

    Oh and I nearly forgot. You need to make a new:
    Zombie, (entity) (new zombie), and a navigation for the new Zombie entity, and a (navigation for new zombie).a(loc.getX(), loc.getY(), loc.getZ(), 0.3f);.Leave the rest the same.

    Edit: ^that handles the second zombie
    savagesun he's using my code I made for him, which was made on an iPod touch so indentation and charity is hindered....
     
  3. Offline

    JonathanNLD

  4. Offline

    klofno1

  5. Offline

    xTrollxDudex

    klofno1
    Dude, you can do this on your own.
    Btw you need 2 braces under this.cancel(). Remember to add a brace for if(event.getPlayer().getItemInHand().getType() == Material.IRON_SWORD){<--here
    And put a } brace at the bottom of the class
     
  6. Offline

    klofno1


    Yes, but if I do that this comes up (and I don't get that part):

    [​IMG]
     
  7. Offline

    xTrollxDudex

    klofno1
    First of all, why did you remove the Main plugin and the constructor for that?
    Second, when you scroll over the error what's the error in eclipse?
     
  8. Offline

    klofno1


    1.plugin cannot be resolved as a variable
    2.- Cannot refer to a non-final variable target inside an inner class defined in a different
    method
    - The method isAlive() is undefined for the type Entity
    3.- Location cannot be resolved to a type
    - Cannot refer to a non-final variable target inside an inner class defined in a different
    method
    4.Cannot refer to a non-final variable nav inside an inner class defined in a different method
    5- The method isAlive() is undefined for the type Entity
    - Cannot refer to a non-final variable target inside an inner class defined in a different
    method
    6The method cancel() is undefined for the type new Runnable(){}
    and with main plugin, do you mean when it was called Mesmer? Because I only changed the name

    This was the old Listener code :
    (and yes I tried out creepers)

    Code:java
    1. package me.JonathanNLD.Mesmer;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Creeper;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.potion.PotionEffect;
    12. import org.bukkit.potion.PotionEffectType;
    13.  
    14. public class MesmerListener implements Listener {
    15.  
    16. @EventHandler
    17. public void onInteract(PlayerInteractEvent event){
    18. if(event.getAction() == (Action.RIGHT_CLICK_BLOCK) || event.getAction() == (Action.RIGHT_CLICK_AIR)) {
    19. Player player = event.getPlayer();
    20. if(event.getPlayer().getItemInHand().getType()==Material.IRON_SWORD) {
    21. int amount = event.getPlayer().getItemInHand().getAmount();
    22. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 70, 2));
    23. if(amount==1) {
    24. event.getPlayer().getInventory().removeItem(event.getPlayer().getInventory().getItemInHand());
    25. } else {
    26. event.getPlayer().getItemInHand().setAmount(amount-1);
    27. }
    28. this.spawnCreeper(event.getClickedBlock().getLocation().add(0, 1, 0));
    29. this.spawnCreeper(event.getClickedBlock().getLocation().add(2, 1, 0));}}}
    30. private void spawnCreeper(Location spawnLocation) {
    31. spawnLocation.getWorld().spawn(spawnLocation, Creeper.class); }
    32.  
    33.  
    34.  
    35. {
    36. }}
    37.  
    38.  
     
  9. Offline

    xTrollxDudex

    klofno1
    I'm gonna have to play around a bit when I have access to an IDE. In the meantime, keep experimenting.
    1. I meant Mesmer plugin; and public GuildWars2Listener(Mesmer plugin) soz
    2. I have no idea
    3. Import location
    4. I have no idea
    5. I have no idea
    6. Wot? Makes no sense.

    For 2, 4, and 5, I think you need to do is:
    Move the Entity target = ... Line into the run()
    Move the Navigation nav = .. Like into run()
    Don't change the code other than what I said above. Also, take these into consideration:
     
  10. Offline

    klofno1


    The strange thing is, if I remove some braces the errors disappear and these appear :

    [​IMG]
     
  11. Offline

    xTrollxDudex

    klofno1
    Seriously. Can you get some progress? This is like 2 squares back.
     
  12. Offline

    klofno1

    What do you mean :)?
     
  13. Offline

    xTrollxDudex

    klofno1
    Well you just told me removing these braces fixed everything but these.
    I happen to just showed you a different method of fixing things why don't you test it out
     
  14. Offline

    klofno1

    I did try it but it didnt fix it but i do not understand why because it says the code is wrong but when I do something with the braces it says the code is right and there is just a problem wiyh the braces. It just does not make sense to me
     
  15. Offline

    xTrollxDudex

    klofno1
    Wtf. The solution to the brace error produces more errors. Therefore, you would be better off trying to fix the problem after you've already solved the braces problem right? What are the errors for the new code?

    This is a very extreme change, you should not have exactly the same errors as before....
    klofno1 also, this is changing the code from this stage:
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  16. Offline

    klofno1

    xTrollxDudex

    Oke, I am going to try it again from this point :

    1. - plugin cannot be resolved to a variable
    - The method scheduleSyncDelayedTask(Plugin, Runnable, long) in the type BukkitScheduler is not applicable for the arguments (Main, new Runnable(){},
    long, long)
    2. - Cannot refer to a non-final variable target inside an inner class defined in a different
    method
    - The method isAlive() is undefined for the type Entity
    3. - Location cannot be resolved to a type
    - Cannot refer to a non-final variable target inside an inner class defined in a different
    method
    4. - Cannot refer to a non-final variable nav inside an inner class defined in a different
    method
    - Cannot refer to a non-final variable nav inside an inner class defined in a different
    method
    5. - The method isAlive() is undefined for the type Entity
    - Cannot refer to a non-final variable target inside an inner class defined in a different
    method
    6.The method cancel() is undefined for the type new Runnable(){}
    [​IMG]
     
  17. Offline

    microgeek

    You obviously don't have a good understanding of Java, it kinda helps with things like this.
     
    savagesun and chasechocolate like this.
  18. Offline

    klofno1

    microgeek Thank you for your comment but this did not help me at all in any way. If you know something, please help me.
     
  19. Offline

    xTrollxDudex

    klofno1
    Ignore 1/2 for now because I have no idea what is going on there.
    The rest:

    For #6 I have no idea. I'll go check.

    And also when you register the listener, do this in your Main.java:
    Code:java
    1. //in your on enable, REMOVE the original listener registry
    2. //the do this:
    3. getServer().getPluginManager().registerEvents(new GuildWars2Listener(this), this);
     
  20. Offline

    chasechocolate

    klofno1 basic Java knowledge helps. Back on topic, all your variables that you use in a Runnable have to have the final modifier.
     
  21. Offline

    klofno1


    And how do I create this final modifier?
     
  22. Offline

    chasechocolate

    klofno1 add "final" before the variable (e.g. "final int i = 0)
     
  23. Offline

    microgeek


    [​IMG]

    Google, young one, Google.
     
    xTrollxDudex and chasechocolate like this.
  24. Offline

    xTrollxDudex

    chasechocolate klofno1
    The variables would change so a final modifier would probably cause an error. Better to move the fields in the run() because we want to update it.
     
Thread Status:
Not open for further replies.

Share This Page