Event simply not working

Discussion in 'Plugin Development' started by beeDevop, Feb 25, 2017.

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

    beeDevop

    Hello. I have the following code:

    Code:java
    1. @EventHandler
    2. public void onUse(PlayerInteractEntityEvent event) {
    3. if(Main.shadow.contains(event.getPlayer().getUniqueId())) {
    4. Player shadow = event.getPlayer();
    5. Player target = (Player) event.getRightClicked();
    6. if (shadow.getLevel() == 100) {
    7. Bukkit.getScheduler().scheduleSyncRepeatingTask(core, new Runnable() {
    8. public void run() {
    9. shadow.sendMessage(ChatColor.BOLD + "" + ChatColor.GREEN + "Your STUN skill is ready");
    10. shadow.sendMessage(ChatColor.BOLD + "" + ChatColor.BLUE + "Right click" + ChatColor.GREEN + "any player to use it.");
    11. }
    12. }, 80, 80);
    13.  
    14. if (shadow.getInventory().getItemInHand() != null) {
    15. if (shadow.getInventory().getItemInHand().getItemMeta() != null) {
    16. if (shadow.getItemInHand().getItemMeta().getDisplayName() == ChatColor.BLUE + "Shadow Sword") {
    17. Main.stuned.add(target.getUniqueId());
    18. target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 1));
    19. target.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60, 1));
    20.  
    21. Bukkit.getScheduler().scheduleSyncDelayedTask(core, new Runnable() {
    22. public void run() {
    23. Main.stuned.remove(target.getUniqueId());
    24.  
    25. }
    26. }, 20L*4L);
    27. }
    28. }
    29. }
    30. }
    31. }
    32. }
    33.  


    And it simply does not work when having this exact sword or the 100 xp levels.
    What is incorrect here?
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    beeDevop

    (facepalm)
    No I didn't

    @timtower
    So, what works:

    - When I have 100XP it sends me the messages, but send it like 4-5 times with different delays, but with 101 levels it also works, not supposed to happen. Still I could not manage to give the blindness and nausea effects to the right clicked.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 25, 2017
  4. Offline

    Zombie_Striker

    It is repeating because you told it to repeat. If you only want it to run once, use Delayed tasks.
     
  5. Offline

    beeDevop

    I want it to be repeated every 4 seconds if the player has 100 levels of xp. I want it to repeat, but it's kinda bizzare the delays and spams it's doing, not every 4 seconds as supposed to.
     
Thread Status:
Not open for further replies.

Share This Page