Bukkit Runnable Issues

Discussion in 'Spigot Plugin Development' started by KingDotCom, Jan 11, 2017.

  1. So this is my code,

    Code (Text):

                            new BukkitRunnable() {

                                public void run() {
                                    if (hashmap.get(e.getPlayer().getUniqueId()) == 1) {
                                       "You have a headache from the *** going up your nose and it's getting worse!");
                                        e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 15, 3));
                                        headache.put(e.getPlayer().getUniqueId(), 2);
                                    }
                                    if (hashmap.get(e.getPlayer().getUniqueId()) == 2) {
                                        "You don't feel good! Enter a bed for 10 seconds for it to feel better");
                                        e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 15, 3));
                                        hashmap.put(e.getPlayer().getUniqueId(), 3);
                                    }
                                    if (hashmap.get(e.getPlayer().getUniqueId()) == 3) {
                                        this.cancel();
                                    }
                                }

                            }.runTaskTimer(BukkitPlugin.getPlugin(BukkitPlugin.class), 20L, 20L * 200L);
    and once it executes, it executes all at once, how can I Fix that?
     
  2. Use:
    else if
    instead of if.

    You're setting the value to 2 and then checking if it's 2. The same thing for 3. Put an else before the second and third if statement.
     
    • Agree Agree x 1
    • Useful Useful x 1