Plugin already initialized

Discussion in 'Plugin Development' started by _Shadod, Apr 2, 2024.

  1. Offline

    _Shadod

    Hi everybody! (sorry for bad english) i need help with bukkit, i have written plugin, and it cant be uploaded, it says that plugin is already initialized. there is a log

    Code:
    [16:44:44 ERROR]: Error occurred while enabling Pholo v1.0-SNAPSHOT (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-794]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[patched_1.16.5.jar:git-Paper-794]
            at pholo.pholo.PholoCommands.<init>(PholoCommands.java:15) ~[?:?]
            at pholo.pholo.Pholo.onEnable(Pholo.java:27) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:500) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugin(CraftServer.java:518) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugins(CraftServer.java:432) ~[patched_1.16.5.jar:git-Paper-794]
            at net.minecraft.server.v1_16_R3.MinecraftServer.loadWorld(MinecraftServer.java:599) ~[patched_1.16.5.jar:git-Paper-794]
            at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:298) ~[patched_1.16.5.jar:git-Paper-794]
            at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1074) ~[patched_1.16.5.jar:git-Paper-794]
            at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-794]
            at java.lang.Thread.run(Thread.java:840) [?:?]
    Caused by: java.lang.IllegalStateException: Initial initialization
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:236) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[patched_1.16.5.jar:git-Paper-794]
            at pholo.pholo.Pholo.<init>(Pholo.java:19) ~[?:?]
            at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
            at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
            at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
            at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
            at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) ~[?:?]
            at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) ~[?:?]
            at java.lang.Class.newInstance(Class.java:645) ~[?:?]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:94) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:153) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:414) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:322) ~[patched_1.16.5.jar:git-Paper-794]
            at org.bukkit.craftbukkit.v1_16_R3.CraftServer.loadPlugins(CraftServer.java:393) ~[patched_1.16.5.jar:git-Paper-794]
            at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:269) ~[patched_1.16.5.jar:git-Paper-794]
            ... 3 more
    idk what to do, and there are no copy of plugin. Pls help!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @_Shadod
    Pholo has a constructor, remove it.
     
  3. Offline

    _Shadod

    thanks, i will test it now, give me two seconds

    bruh, i cant it remove, cause i have
    private final ProtectedRegion prg;
    i need ProtectedRegion from WG to use isOwner

    do u need his code???

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 2, 2024
  4. Offline

    timtower Administrator Administrator Moderator

    That is not a constructor.
     
  5. Offline

    _Shadod

    bruh, maybe i some stupid, but, where is constructor???


    Code:
    package pholo.pholo;
    
    import org.bukkit.Bukkit;
    
    import org.bukkit.plugin.java.JavaPlugin;
    import pholo.pholo.commands.PholoCommands;
    
    public final class Pholo extends JavaPlugin {
    
    
        @Override
        public void onEnable() {
            // Plugin startup logic
    
    
            getCommand("pholo").setExecutor(new PholoCommands());
            Bukkit.getConsoleSender().sendMessage("Pholo plugin has been enabled");
        }
        @Override
        public void onDisable() {
            // Plugin shutdown logic
        }
    
    }
    Code:
    package pholo.pholo.commands;
    import com.sk89q.worldguard.WorldGuard;
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    import com.sk89q.worldguard.protection.regions.ProtectedRegion;
    import net.luckperms.api.LuckPerms;
    import net.luckperms.api.LuckPermsProvider;
    import net.luckperms.api.model.user.User;
    import net.luckperms.api.node.Node;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class PholoCommands extends JavaPlugin implements CommandExecutor {
    
        public WorldGuardPlugin wg;
        public ProtectedRegion prg;
    
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("Only players can use this command");
                return true;
            } else {
                WorldGuard wg = WorldGuard.getInstance();
                if (prg.isOwner(sender.getName()) == true) {
    
                    Player p = ((Player) sender).getPlayer();
                    User user = LuckPermsProvider.get().getPlayerAdapter(Player.class).getUser(p);
    
                    Player player = ((Player) sender).getPlayer();
                    if (label.equalsIgnoreCase("pholo")) {
                        if (args.length < 2) {
                            player.sendMessage("Usage: /pholo create (name) (text)");
                            return true;
                        }
    
                        String subCommand = args[0];
                        String name = args[1];
    
                        switch (subCommand) {
                            case "create":
                                if (args.length < 3) {
                                    player.sendMessage("Usage: /pholo create (name) (text)");
                                    return true;
                                }
                                String text = args[2];
                                createHologram(player, name, text);
                                break;
                            case "move":
                                moveHologram(player, name);
                                break;
                            case "addline":
                                if (args.length < 3) {
                                    player.sendMessage("Usage: /pholo addline (name) (text)");
                                    return true;
                                }
                                String addText = args[2];
                                addLine(player, name, addText);
                                break;
                            case "removeline":
                                if (args.length < 3) {
                                    player.sendMessage("Usage: /pholo removeline (name) (line number)");
                                    return true;
                                }
                                int lineNumber = Integer.parseInt(args[2]);
                                removeLine(player, name, lineNumber);
                                break;
                            case "del":
                                deleteHologram(player, name);
                                break;
                            default:
                                player.sendMessage("Invalid command. Usage: /pholo create|move|addline|removeline|del");
                                break;
                        }
                    }
    
                    return true;
                }
            }
            return true;
        }
    
    
        private void createHologram(Player player, String name, String text) {
            // Create hologram logic
    
            User user = LuckPermsProvider.get().getPlayerAdapter(Player.class).getUser(player);
            LuckPerms lp = LuckPermsProvider.get();
            user.data().add(Node.builder("holographicdisplays.create").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
            player.performCommand("/hd create " + name + text);
            user.data().remove(Node.builder("holographicdisplays.create").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
    
        }
    
        private void moveHologram(Player player, String name) {
            // Move hologram logic
            User user = LuckPermsProvider.get().getPlayerAdapter(Player.class).getUser(player);
            LuckPerms lp = LuckPermsProvider.get();
            user.data().add(Node.builder("holographicdisplays.movehere").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
            player.performCommand("/hd movehere " + name);
            user.data().remove(Node.builder("holographicdisplays.movehere").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
        }
    
        private void addLine(Player player, String name, String text) {
            // Add line to hologram logic
            User user = LuckPermsProvider.get().getPlayerAdapter(Player.class).getUser(player);
            LuckPerms lp = LuckPermsProvider.get();
            user.data().add(Node.builder("holographicdisplays.addline").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
            player.performCommand("/hd movehere " + name + text);
            user.data().remove(Node.builder("holographicdisplays.addline").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
        }
    
        private void removeLine(Player player, String name, int lineNumber) {
            // Remove line from hologram logic
            User user = LuckPermsProvider.get().getPlayerAdapter(Player.class).getUser(player);
            LuckPerms lp = LuckPermsProvider.get();
            user.data().add(Node.builder("holographicdisplays.removeline").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
            player.performCommand("/hd removeLine " + name + lineNumber);
            user.data().remove(Node.builder("holographicdisplays.removeline").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
        }
    
        private void deleteHologram(Player player, String name) {
            // Delete hologram logic
            User user = LuckPermsProvider.get().getPlayerAdapter(Player.class).getUser(player);
            LuckPerms lp = LuckPermsProvider.get();
            user.data().add(Node.builder("holographicdisplays.delete").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
            player.performCommand("/hd delete " + name);
            user.data().remove(Node.builder("holographicdisplays.delete").build());
    
            // Now we need to save changes.
            lp.getUserManager().saveUser(user);
        }
    }
     
  6. Offline

    timtower Administrator Administrator Moderator

    @_Shadod PholoCommands also extends JavaPlugin, only the main class can do that.
    And to be honest: everything in there can be moved to the main class.
     
  7. Offline

    _Shadod

    Bruh, thanks, I'll be test it tomorrow, and i know that it can be moved to main class, but it's easier for me to navigate this way
     
  8. Offline

    _Shadod

    thx, it works, you can close thread
     

Share This Page