Plugin Not Working

Discussion in 'Plugin Development' started by Ugonnadie, Aug 31, 2020.

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

    Ugonnadie

    Hi,
    I am creating a plugin that makes you breathe underwater and drown in air. The server says that the plugin is enabled in the server, and I can see the server trying execute the code. Please help.
    Here's my code:
    Code:
    package me.Ugonnalive.UnderWater;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Main extends JavaPlugin implements Listener {
       
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent join){
            Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable(){
                public void run(){
                    Player player = join.getPlayer();
                    Material m = join.getPlayer().getLocation().getBlock().getType();
                    boolean damage = false;
                   
                    if (m == Material.WATER) {
                        player.addPotionEffect(new PotionEffect(PotionEffectType.CONDUIT_POWER, Integer.MAX_VALUE, 3, false, false));
                        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2, false, false));
                    }
                    else {
                        player.removePotionEffect(PotionEffectType.CONDUIT_POWER);
                        player.removePotionEffect(PotionEffectType.SPEED);
                        if (damage == false) {
                            damage = true;
                            for (int i = 10; i > 0; i--) {
                                if (m != Material.WATER || player.isDead() == false) {
                                    player.setRemainingAir(i);
                                }
                                else {
                                    damage = false;
                                }
                            }
                            damage = false;
                        }
                    }
                }
            }, 0l, 20l);
        }
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Ugonnadie

    Nothing is happening. The plugin isn't working. It's just a normal minecraft server.
     
    Last edited: Sep 1, 2020
  4. Offline

    Strahan

    It must not be loading then, because if it actually loaded as soon as someone logged in your console would start to fill with exceptions.

    That aside, you should be using the move event and not a task in the login. Also you have no provision to terminate when the player logs off either.
     
  5. Offline

    Ugonnadie

    I already changed it to move before I made this last post. It does take a long time to connect, but how do I fix this.
     
Thread Status:
Not open for further replies.

Share This Page