Solved Console error, help

Discussion in 'Plugin Development' started by lilian58660, Apr 8, 2015.

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

    lilian58660

    Hi, i'm creating boss system, when I startup my server the plugin can't load
    here my main class :
    Code:
    package ez.xteam;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Skeleton;
    import org.bukkit.entity.Skeleton.SkeletonType;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.Material;
    public class Main extends JavaPlugin implements Listener {
    public void onEnable(){
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
        getCommand("mobs").setExecutor(new Main());
    }
    @SuppressWarnings("deprecation")
    public void spawnSkeleton(Player player)
    {
    Skeleton skele = (Skeleton) player.getLocation().getWorld().spawn(player.getLocation(), Skeleton.class);
    skele.setCustomName(ChatColor.GOLD + "Roi Squelette");
    skele.setCustomNameVisible(true);
    skele.setSkeletonType(SkeletonType.WITHER);
    skele.getEquipment().setItemInHand(new ItemStack(Material.DIAMOND_SWORD));
    skele.getEquipment().setBoots(new ItemStack(Material.DIAMOND_BOOTS));
    skele.getEquipment().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
    skele.getEquipment().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS));
    skele.setHealth(100);
    skele.setCanPickupItems(false);
    skele.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000000, 1));
    skele.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 10000000, 3));
    skele.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 10000000, 1));
    
    
    
    }
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] a) {
    if (cmd.getName().equalsIgnoreCase("mobs")) {
    if(sender instanceof Player){
    Player p = (Player) sender;
    spawnSkeleton(p);
    return true;
    }
    }
    return false;
    }
    }

    And I get this error:
    Code:
    [09:40:44] [Server thread/ERROR]: Error occurred while enabling xTeam_boss v1.1 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-1649]
        at ez.xteam.Main.<init>(Main.java:17) ~[?:?]
        at ez.xteam.Main.onEnable(Main.java:21) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:476) [spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:394) [spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:866) [spigot.jar:git-Spigot-1649]
        at org.bukkit.Bukkit.reload(Bukkit.java:301) [spigot.jar:git-Spigot-1649]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [spigot.jar:git-Spigot-1649]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) [spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1649]
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-1649]
        at ez.xteam.Main.<init>(Main.java:17) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_65]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_65]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_65]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_65]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_65]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:341) ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:263) ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:369) ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:864) ~[spigot.jar:git-Spigot-1649]
        ... 10 more
    Thanks in advance !
     
  2. Offline

    Xerox262

    Did you stop the server or just reload it? Because when I compiled it, it worked with a minor change to the code (changed the type of the skeleton to a living entity rather than a skeleton)

    Code:
    package ez.xteam;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Skeleton;
    import org.bukkit.entity.Skeleton.SkeletonType;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    public class Main extends JavaPlugin implements Listener {
    public void onEnable(){
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
        getCommand("mobs").setExecutor(new Main());
    }
    @SuppressWarnings("deprecation")
    public void spawnSkeleton(Player player)
    {
    LivingEntity skele = player.getLocation().getWorld().spawn(player.getLocation(), Skeleton.class);
    skele.setCustomName(ChatColor.GOLD + "Roi Squelette");
    skele.setCustomNameVisible(true);
    ((Skeleton) skele).setSkeletonType(SkeletonType.WITHER);
    skele.getEquipment().setItemInHand(new ItemStack(Material.DIAMOND_SWORD));
    skele.getEquipment().setBoots(new ItemStack(Material.DIAMOND_BOOTS));
    skele.getEquipment().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
    skele.getEquipment().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS));
    skele.setHealth(100);
    skele.setCanPickupItems(false);
    skele.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000000, 1));
    skele.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 10000000, 3));
    skele.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 10000000, 1));
    
    
    
    }
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] a) {
    if (cmd.getName().equalsIgnoreCase("mobs")) {
    if(sender instanceof Player){
    Player p = (Player) sender;
    spawnSkeleton(p);
    return true;
    }
    }
    return false;
    }
    }
    
     
  3. Offline

    Rocoty

    You should not, ever, create a new instance of your main plugin class. There should only ever exist one instance and that is created internally by the bukkit framework.
     
    mine-care likes this.
  4. Offline

    mine-care

    Never. Never instanciate the main class that extends JavaPlugin, You dont need to register it as a command executor because onCommand exists in JavaPlugin class that is super class of your main, I sugest you avoid getting everything in the main class like listeners,commands and so on and you create seperate ones.

    @Rocoty You ninja'ed me again :3 You're back! i haven't seen you for awhile :- )
     
  5. Offline

    Rocoty

    @mine-care Aye, I've been more at the spigot forums after this place died down a bit. But truth be told I'm not on either of the forums that much anymore. But it was nice to ninja you ;)
     
    mine-care likes this.
  6. Offline

    mine-care

    @Rocoty Honestly, i LOVE bukkit forums, they are not dead yet -and i hope they never die :3- also since my time is limited, i cannot be on both spigot & bukkit D:
    I am not as active either :- ( mainly because it is the last years before university so... i have a heavy shedule.
    Anyway, glad to see you again! (Time to ninja me some more like the good old days...) :- D
     
    nverdier, bwfcwalshy and Rocoty like this.
  7. Offline

    CheesyFreezy

    If you want to find the error on your own just search for the classname in the error and after that it should say a number, this number is the line in your code.

    Format: [Classname:Number]
    Example: [Main:17]
     
  8. Offline

    lilian58660

    Okay, thanks for your answers,I already read these but line 17, what is the error ><
     
  9. Offline

    teej107

     
  10. Offline

    lilian58660

    I'm actually lost... tell me what's the error, and where :'(:oops:
     
  11. Offline

    teej107

  12. Offline

    Rocoty

  13. Offline

    lilian58660

  14. Offline

    teej107

    CodePlaysMinecraft likes this.
  15. Offline

    lilian58660

    Thanks, working ( sorry, i'm newbie in java )
     
  16. Offline

    Rocoty

    Now, don't take this as a general fix to everything. @teej107 suggested what he did because he knows that the default command executor for all plugin commands is the main instance of the plugin that defines the command. And this is true, which is why removing the line altogether works.

    However, in the future simply removing a line that causes errors won't always fix your problem, and may even end up creating new ones. Which is why I now urge you to read up on what the 'this' keyword does (it should help you see the problem for this particular matter...hopefully). Click the link I sent you above.
     
    lilian58660 and teej107 like this.
  17. Offline

    lilian58660

    Thanks for everything, you're awesome !
     
  18. Offline

    nverdier

Thread Status:
Not open for further replies.

Share This Page