Weird 'plugin already initialized' error

Discussion in 'Plugin Development' started by Eminemboy46, Sep 16, 2014.

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

    Eminemboy46

    So I'm kinda new to bukkit, and I was trying to make a program so that if you type /freeze it freezes you and you cannot move. To do this, I made it find when you move and teleport you back to the coordinates where you type /freeze. Also if you type /freeze again, then you are no longer frozen and can move again :)
    When I tried to start up my server, the console gave me this weird error:
    'Could not load plugins/CantMove.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already intialized!
    Heres the code for the plugin:
    Code:
    package me.Eminemboy46.youtube;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        boolean isFrozen = false;
        Player curPlayer = null;
        int x = 0,
            y = 0,
            z = 0;
        @Override
        public void onDisable() {
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info("[" + pdfFile.getVersion() + "]" + " Has been Disabled!"); 
        }
     
        @Override
        public void onEnable() {
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info("[PluginForMC]" + " Version " + pdfFile.getVersion() + " Has been Enabled!");
        }
        public class MyRunnableTask implements Runnable {
            public void run() {
     
            }
        }
        Thread thread1 = new Thread(new Runnable(){
            public void run(){
                int newx = curPlayer.getLocation().getBlockX(),
                    newy = curPlayer.getLocation().getBlockY(),
                    newz = curPlayer.getLocation().getBlockZ();
                if(x != newx || y != newy || z != newz){
                    curPlayer.teleport(curPlayer.getLocation());
                }
            }
        }, "Thread1");
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            curPlayer = player;
                x = player.getLocation().getBlockX();
            y = player.getLocation().getBlockY();
            z = player.getLocation().getBlockZ();
            thread1.start();
            if(commandLabel.equalsIgnoreCase("freeze")){
                if(isFrozen){
                    isFrozen = false;
                    player.sendMessage(ChatColor.AQUA + "You are no longer frozen");
                }
                else{
                    isFrozen = true;
                    player.sendMessage(ChatColor.AQUA + "You are now frozen");
                }
            }
            return false;
        }
    }
    
    Any help would be greatly appreciated!
    Also, this may be a really dumb mistake, but be patient with me :) I'm new to this
     
  2. Offline

    pookeythekid

    Do you have any other classes in this plugin? Also, my guess for something that would be a "dumb mistake" is that you may or may not have left another test version of that plugin--or perhaps a different plugin with accidentally the same name in the plugin.yml--in your plugins folder.
     
  3. Offline

    Eminemboy46

    No, there aren't any other classes. No, there aren't any other test versions of the plugin. And no, there wasn't any other plugin.yml with the same name.
    Are you sure its not an error with the code?
     
  4. Offline

    pookeythekid

    Eminemboy46 Well, it's certainly been a while since I've had that error. I think I had that error with the last plugin I made, which was months ago. And since then, I completely halted all of my plugin development due to Bukkit being shredded apart.
     
  5. Offline

    hubeb

    Eminemboy46 check all your class for this line: "extends JavaPlugin"
    it should only be in your main class.
     
  6. Offline

    fireblast709

    Eminemboy46 what in the world are you doing in that code...
    • Don't use Logger.getLogger("Minecraft"), use the Logger object you get from JavaPlugin
    • What is it with the instance variables there, there is no reason to use them
    • Enabled/Disabled messages are already done by Bukkit
    • Why are you using Threads to delay stuff
    • Aside that you use Threads, you are using the Bukkit API asynchronously - you simply aren't allowed to do this.
    • Don't cast sender to Player before you know that sender instanceof Player
    • Use cmd.getName() instead of commandLabel for alias support
     
    Garris0n likes this.
  7. Eminemboy46 Youtube videos don't work. Please don't learn from them.
     
  8. Offline

    Eminemboy46

    Can you give me a good source to learn from, please? The tutorial I used worked for the first few tutorials, but then some of the features he used stopped working, so I just winged it and made a few plugins.
     
  9. Eminemboy46 First, I recommend that you learn Java from either the Oracle tutorials or a Java book. Once you have learned enough Java, the plugin tutorial that you'll find on the bukkit wiki combined with the JavaDocs will be more than sufficient to learn how to make plugins :)
     
    Garris0n likes this.
Thread Status:
Not open for further replies.

Share This Page