1.16.5 Having an error trying to launch a plugin

Discussion in 'Spigot Plugin Development' started by StTrigger, Jul 15, 2021.

  1. P.S. im very new in this so my code is garbage and ik that:)

    Btw eclipse cant see any errors there

    Error:
    Code (Java):
    [20:47:13 ERROR]: Error occurred while enabling Nuker v1.0 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:233) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[patched_1.16.5.jar:git-Paper-778]
    at nuker.nuker.Nuker.<init>(Nuker.java:10) ~[?:?]
    at Listeners.BombTrigger.<init>(BombTrigger.java:11) ~[?:?]
    at nuker.nuker.Nuker.onEnable(Nuker.java:15) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:500) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugin(CraftServer.java:518) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugins(CraftServer.java:432) ~[patched_1.16.5.jar:git-Paper-778]
    at net.minecraft.server.v1_16_R3.MinecraftServer.loadWorld(MinecraftServer.java:594) ~[patched_1.16.5.jar:git-Paper-778]
    at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:298) ~[patched_1.16.5.jar:git-Paper-778]
    at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1069) ~[patched_1.16.5.jar:git-Paper-778]
    at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-778]
    at java.lang.Thread.run(Thread.java:834) [?:?]
    Caused by: java.lang.IllegalStateException: Initial initialization
    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:236) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[patched_1.16.5.jar:git-Paper-778]
    at nuker.nuker.Nuker.<init>(Nuker.java:10) ~[?:?]
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
    at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?]
    at java.lang.Class.newInstance(Class.java:584) ~[?:?]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:94) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:153) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:414) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:322) ~[patched_1.16.5.jar:git-Paper-778]
    at org.bukkit.craftbukkit.v1_16_R3.CraftServer.loadPlugins(CraftServer.java:393) ~[patched_1.16.5.jar:git-Paper-778]
    at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:269) ~[patched_1.16.5.jar:git-Paper-778]
    ... 3 more



    Main class:
    Code (Java):
    package nuker.nuker;

    import Listeners.BombTrigger;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Nuker extends JavaPlugin {
    public boolean b = false;
        @Override
        public void onEnable() {
            System.out.println("enabled!");
            getServer().getPluginManager().registerEvents(new BombTrigger(),this);

        }

        @Override
        public void onDisable() {
            System.out.println("disabled!");
        }


        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
                if (command.getName().equals("bombStart")) {
                    player.sendMessage(ChatColor.YELLOW + "The nuke was activated!");
                    b = true;


                }
            }


            if (sender instanceof Player) {
                Player player = (Player) sender;
                if (command.getName().equals("bombStop")) {
                    player.sendMessage(ChatColor.YELLOW + "The nuke was deactivated!");
                    b = false;

                }
            }

            return false;
        }
    }
     

    Listener class:

    Code (Java):

    package Listeners;

    import nuker.nuker.Nuker;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class BombTrigger extends Nuker implements Listener {

        @EventHandler
        public void wither60(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            float y = (float) p.getLocation().getBlockY();
            if (b = true) {
                if (y >= 60.0F) {
                    p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 20, 2));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20, 2));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 2));
                }
            }

        }

        @EventHandler
        public void wither50(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            float y = (float) p.getLocation().getBlockY();
            if (b = true) {
                if (y >= 50.0F) {
                    p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20, 1));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20, 2));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 2));
                }
            }

        }

        @EventHandler
        public void wither40(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            float y = (float) p.getLocation().getBlockY();
            if (b = true) {
                if (y >= 40.0F) {
                    p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 20, 1));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20, 1));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 2));
                }
            }

        }

        @EventHandler
        public void wither30(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            float y = (float) p.getLocation().getBlockY();
            if (b = true) {
                if (y >= 50.0F) {
                    p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 1));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 1));
                }
            }

        }

        @EventHandler
        public void wither20(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            float y = (float) p.getLocation().getBlockY();
            if (b = true) {
                if (y >= 50.0F) {
                    p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 1));
                }
            }

        }
    }
     
    Line im getting error in
    Code (Java):
    getServer().getPluginManager().registerEvents(new BombTrigger(),this);

    Many thanks!
     
    #1 StTrigger, Jul 15, 2021
    Last edited: Jul 16, 2021
  2. First of all, what is this class? Why are you extending it?
    Secondly, why are you comparing a boolean to a true/false? And where does that b come from?
    Thirdly, you can inline the y variable just in the if statement. If you use it only once, you don't need to declare a variable.
    Lastly, what the heck is this?
    It looks like something is wrong with that bomber class. Publish it here
     
  3. You have probably uploaded the same plugin twice
     

  4. well first of all im importing the class to use the same boolean in listener and the command

    secondly b come from bomber class as i said, also im checking true/false to make listener disable/enable with command

    thirdly ill fix that

    lastly that thing is checking the Y cord of the player and applying effects, deeper you go, less bad effects become

    and bomber class is the main class. and its published
     
  5. explain?
     
  6. No mate, the main class is nuker.
     
  7. You may have two copies of the same plugin in one folder.
     
  8. dude i accidently posted wrong class... i changed it in code few hours ago, basicly listener is extending Nuker not the BOMBer, its just an old version. ill fix the thread. gimme moment
     
  9. only one
     
  10. i fixed that
     
  11. No, what you're doing is assigning to the variable "b" the value true, and then checking if its value is true, which obviously is. You need to use two equals ( == ), but they're not required in a condition since a boolean is already a... boolean
     
    #11 TheSniper99, Jul 16, 2021
    Last edited: Jul 16, 2021
  12. oh...
     
  13. i fixed that but its still crashing
     
  14. oh. you're from Russia too?
     
  15. You are extending an already loaded instance of JavaPlugin, which you are not allowed to do. Maybe you should rethink your plugin structure (avoiding the one-letter public variables that go against any code standard)
     
  16. So, what should i do?
     
  17. Code (Java):
    public class Nuker extends JavaPlugin {
       
        private boolean isBombActivated;
        ...
       
        public boolean isBombActivated() {
            return isBombActivated;
        }
    }

    public class BombTrigger implements Listener {
       
        private Nuker nuker;
       
        public BombTrigger(Nuker nuker) {
            this.nuker = nuker;
        }
       
        @EventHandler
        public void on(/* something */ event) {
            if (nuker.isBombActivated() && ...) {
                ...
            }
        }
    }
    something like this
     
    • Useful Useful x 1
  18. Code (Java):
     if (nuker.isBombActivated() && ...) {

    i didnt really get this part
     
  19. Code (Text):
        private Nuker nuker;
     
        public BombTrigger(Nuker nuker) {
            this.nuker = nuker;v
    this part is breaking all the events somehow
     
  20. I assume you are new to Java?