Help on Runnable Task

Discussion in 'Plugin Development' started by George596, Apr 11, 2014.

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

    George596

    Hello, First Post! :)
    Anyways, I am trying to use BukkitRunnable tasks. So far I can't achive what I am doing. I am trying to make it so if you right click a sword with a display name as "Fiery Sword". Then when clicked it, it spawns FallingBlocks with Material Fire.
    The problem is that when I don't keep right clicking the sword it keeps running the task when my code says that is the player is not right clicking the sword it will cancel() the task. It also gives off errors when not holding the sword.

    Code :
    Code:
     public void fire(PlayerInteractEvent e){
    final Player p = e.getPlayer();
    final Action a = e.getAction();
    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
    public void run(){
    FallingBlock b;
    Vector v;
    Random r = new Random();
    boolean contains_fiery_sword = p.getInventory().getItemInHand().getItemMeta().getDisplayName().contains("Fiery Sword");
    System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    System.out.println(contains_fiery_sword);
    if((contains_fiery_sword == true) && (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK)){
    b = p.getWorld().spawnFallingBlock(p.getLocation(), Material.FIRE, (byte) 0);
    v = p.getVelocity().multiply(r.nextInt(Bukkit.getMaxPlayers())).setY(0.3);
    b.setVelocity(v);
    }else{
    cancel();
    }
    }
    }, 0L, 5L);
    }
     
    @EventHandler
    public void onNetherStars(PlayerInteractEvent e){
    Player player = e.getPlayer();
    Action action = e.getAction();
    String name = player.getInventory().getItemInHand().getItemMeta().getDisplayName();
    if(action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK){
    if(name.contains("Fiery Sword")){
    fire(e);
    }
    }
    } 
    Error: http://pastebin.com/xA4EPRPU
     
  2. Offline

    George596

    Please HELP

    Bump (is this how you bump?)

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

    thomasb454

    Please bump your threads only once per 24 hours.

    Also, Spigot isn't supported here. Sorry. Seek advice on the appropriate forum.
     
  4. Offline

    George596

    Sorry for bunmping at the wrong time and I am pretty sure If I use craftbukkit.jar the same error will pop up i will say
     
  5. Offline

    thomasb454

    I'm just telling you what the Administrators/Moderators will tell you.
     
  6. Offline

    Maurdekye

    thomasb454 Then use craftbukkit.jar, and tell us if they do pop up or not.
     
  7. Offline

    George596

    Tested with Craftbukkit, same error

    Maurdekye Tested with craftbukkit

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

    multikus

    Why do you need two PlayerInteractEvents? Try putting both in one.
     
  9. Offline

    thomasb454


    you tagged me why..?
     
  10. Offline

    Maurdekye

    thomasb454 Sorry, been off my computer. Does the error produce a stack trace, or does it just not do what you want it to? If there's a stack trace, then show it.
     
  11. Offline

    thomasb454


    you tagged my why again? Re-read the OP.
     
  12. Offline

    George596

    I am just being more organized but I will try
     
  13. Offline

    Maurdekye

    Why are you against tagging? Also, what's on line 270?
     
  14. Offline

    George596

    new code:
    Code:
     @EventHandler
            public void onNetherStars(PlayerInteractEvent e){
            Player player = e.getPlayer();
            Action action = e.getAction();
            String name = player.getInventory().getItemInHand().getItemMeta().getDisplayName();
            if(action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK){
            if(name.contains("Fiery Sword")){
                final Player p = e.getPlayer();
                final Action a = e.getAction();
                Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BukkitRunnable() {
                public void run(){
                FallingBlock b;
                Vector v;
                Random r = new Random();
                boolean contains_fiery_sword = p.getInventory().getItemInHand().getItemMeta().getDisplayName().contains("Fiery Sword");
                System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
                System.out.println(contains_fiery_sword);
                if((contains_fiery_sword == true) && (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK)){
                b = p.getWorld().spawnFallingBlock(p.getLocation(), Material.FIRE, (byte) 0);
                v = p.getVelocity().multiply(r.nextInt(Bukkit.getMaxPlayers())).setY(0.3);
                b.setVelocity(v);
                }else{
                cancel();
                }
                }
                }, 0L, 5L);
            }
            }
            }
    
    Error: http://pastebin.com/fhVpgYRT

    Yes I coded with Spigot code but all my plugins worked that way... I also switched to bukkit code but no errors or anything poped up

    Line 270 is not part of this error/code or problemo

    My real problem is that my task fails to cancel() when I am not holding the sword or when I am not right clicking the sword. It always give the error [creeper]

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

    George596

  16. Offline

    TnT

    Locked. You have chosen not to use our software, we are unable to help you.
     
Thread Status:
Not open for further replies.

Share This Page