Plugin Running Issues , need help!

Discussion in 'Programming' started by thomas12000, May 29, 2016.

  1. Hello , I'm Thomas
    I'm having trouble running my plugin on the server for some reason i get a lot of things in the server log ...

    Here is my Main.class
    Code (Text):
    package com.twmas.IskandurPluginX;

    import java.util.HashMap;

    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.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener{
       
        static HashMap<String, Integer> points = new HashMap<String, Integer>();
       
        Points pointsclass = new Points();
       
        public void onEnable(){
            Bukkit.getLogger().info("IskandurPluginX is enabled.");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            pointsclass.pointsRead();
           
        }
       
        public void onDisable(){
            Bukkit.getLogger().info("IskandurPluginX is disabled.");
            pointsclass.pointsWrite();
        }
       
        //events
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            if(points.get(player.getName().toLowerCase()) == null){
                points.put(player.getName().toLowerCase(), 0);
            }
            event.setJoinMessage(ChatColor.YELLOW + player.getName() + ChatColor.AQUA + " has joined the beautiful world of Iskandur Craft.");
        }
       
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent event){
            Player player = event.getPlayer();
            event.setQuitMessage(ChatColor.YELLOW + player.getName() + ChatColor.AQUA + " has left the beautiful world of Iskandur Craft.");
        }
       
        //commands
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
           
            if(cmd.getName().equalsIgnoreCase("points")){
               
                Player player = (Player) sender;
                player.sendMessage("You have " + points.get(player.getName().toLowerCase()) + " points.");
               
                if(!(player.hasPermission("iskandurpluginx.points"))){
                   
                }
               
                if(args.length == 0){
                    player.sendMessage(points.get(player.getName().toLowerCase()) + "points.");
                }
               
                if(args.length == 1){
                    if(args[0].equalsIgnoreCase("exchange")){
                        if(args[1].equalsIgnoreCase("1")){
                           
                        }else if(args[1].equalsIgnoreCase("2")){
                           
                        }else if(args[1].equalsIgnoreCase("3")){
                           
                        }else if(args[1].equalsIgnoreCase("4")){
                           
                        }
                    }else if(args[0].equalsIgnoreCase("help")){
                       
                    }
                }
               
                if(args.length > 2){
                   
                }
            }
           
            if(cmd.getName().equalsIgnoreCase("guild")){
               
            }
           
            if(cmd.getName().equalsIgnoreCase("report")){
               
            }
           
            return false;
        }

    }
     
    Here is my Points.java
    Code (Text):
    package com.twmas.IskandurPluginX;

    import java.util.Map.Entry;

    public class Points extends Main{
       
        public void pointsRead(){
            for(String str : getConfig().getKeys(true)){
                int p = getConfig().getInt(str);
                points.put(str, p);
            }
            saveConfig();
        }
       
        public void pointsWrite(){
            for(Entry<String, Integer> pointstostore : points.entrySet()){
                getConfig().set(pointstostore.getKey(), pointstostore.getValue());
            }
            saveConfig();
        }
    }
     
    Here is the log of the server last time i run it with the plugin on
    Code (Text):
    [23:19:06] [Server thread/INFO]: Starting minecraft server version 1.8.8
    [23:19:06] [Server thread/INFO]: Loading properties
    [23:19:06] [Server thread/INFO]: Default game type: SURVIVAL
    [23:19:07] [Server thread/INFO]: This server is running CraftBukkit version git-Spigot-db6de12-18fbb24 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    [23:19:07] [Server thread/INFO]: Debug logging is disabled
    [23:19:07] [Server thread/INFO]: Server Ping Player Sample Count: 12
    [23:19:07] [Server thread/INFO]: Using 4 threads for Netty based IO
    [23:19:07] [Server thread/INFO]: Generating keypair
    [23:19:07] [Server thread/INFO]: Starting Minecraft server on *:25565
    [23:19:07] [Server thread/INFO]: Using default channel type
    [23:19:07] [Server thread/INFO]: Set PluginClassLoader as parallel capable
    [23:19:07] [Server thread/ERROR]: Could not load 'plugins\IskandurPluginX.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) [server.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) [server.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [server.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_92]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[server.jar:git-Spigot-db6de12-18fbb24]
        at com.twmas.IskandurPluginX.Main.<init>(Main.java:16) ~[?:?]
        at com.twmas.IskandurPluginX.Points.<init>(Points.java:5) ~[?:?]
        at com.twmas.IskandurPluginX.Main.<init>(Main.java:20) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_92]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_92]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_92]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_92]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_92]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[server.jar:git-Spigot-db6de12-18fbb24]
        ... 6 more
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[server.jar:git-Spigot-db6de12-18fbb24]
        at com.twmas.IskandurPluginX.Main.<init>(Main.java:16) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_92]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_92]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_92]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_92]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_92]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[server.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[server.jar:git-Spigot-db6de12-18fbb24]
        ... 6 more
    [23:19:07] [Server thread/INFO]: **** Beginning UUID conversion, this may take A LONG time ****
    [23:19:07] [Server thread/INFO]: Preparing level "world"
    [23:19:07] [Server thread/INFO]: -------- World Settings For [world] --------
    [23:19:07] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [23:19:07] [Server thread/INFO]: Experience Merge Radius: 3.0
    [23:19:07] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [23:19:07] [Server thread/INFO]: Clear tick list: false
    [23:19:07] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [23:19:07] [Server thread/INFO]: Item Merge Radius: 2.5
    [23:19:07] [Server thread/INFO]: Item Despawn Rate: 6000
    [23:19:07] [Server thread/INFO]: Max Entity Collisions: 8
    [23:19:07] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [23:19:07] [Server thread/INFO]: View Distance: 10
    [23:19:07] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [23:19:07] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [23:19:07] [Server thread/INFO]: Structure Info Saving: true
    [23:19:07] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [23:19:07] [Server thread/INFO]: Anti X-Ray: true
    [23:19:07] [Server thread/INFO]:     Engine Mode: 1
    [23:19:07] [Server thread/INFO]:     Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [23:19:07] [Server thread/INFO]:     Replace Blocks: [1, 5]
    [23:19:07] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [23:19:07] [Server thread/INFO]: Max TNT Explosions: 100
    [23:19:07] [Server thread/INFO]: Mob Spawn Range: 4
    [23:19:07] [Server thread/INFO]: Random Lighting Updates: false
    [23:19:07] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Cane Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Melon Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: NetherWart Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [23:19:07] [Server thread/INFO]: Sending up to 10 chunks per packet
    [23:19:07] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [23:19:07] [Server thread/INFO]: -------- World Settings For [world_nether] --------
    [23:19:07] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [23:19:07] [Server thread/INFO]: Experience Merge Radius: 3.0
    [23:19:07] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [23:19:07] [Server thread/INFO]: Clear tick list: false
    [23:19:07] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [23:19:07] [Server thread/INFO]: Item Merge Radius: 2.5
    [23:19:07] [Server thread/INFO]: Item Despawn Rate: 6000
    [23:19:07] [Server thread/INFO]: Max Entity Collisions: 8
    [23:19:07] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [23:19:07] [Server thread/INFO]: View Distance: 10
    [23:19:07] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [23:19:07] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [23:19:07] [Server thread/INFO]: Structure Info Saving: true
    [23:19:07] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [23:19:07] [Server thread/INFO]: Anti X-Ray: true
    [23:19:07] [Server thread/INFO]:     Engine Mode: 1
    [23:19:07] [Server thread/INFO]:     Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [23:19:07] [Server thread/INFO]:     Replace Blocks: [1, 5]
    [23:19:07] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [23:19:07] [Server thread/INFO]: Max TNT Explosions: 100
    [23:19:07] [Server thread/INFO]: Mob Spawn Range: 4
    [23:19:07] [Server thread/INFO]: Random Lighting Updates: false
    [23:19:07] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Cane Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Melon Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: NetherWart Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [23:19:07] [Server thread/INFO]: Sending up to 10 chunks per packet
    [23:19:07] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [23:19:07] [Server thread/INFO]: -------- World Settings For [world_the_end] --------
    [23:19:07] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [23:19:07] [Server thread/INFO]: Experience Merge Radius: 3.0
    [23:19:07] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [23:19:07] [Server thread/INFO]: Clear tick list: false
    [23:19:07] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [23:19:07] [Server thread/INFO]: Item Merge Radius: 2.5
    [23:19:07] [Server thread/INFO]: Item Despawn Rate: 6000
    [23:19:07] [Server thread/INFO]: Max Entity Collisions: 8
    [23:19:07] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [23:19:07] [Server thread/INFO]: View Distance: 10
    [23:19:07] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [23:19:07] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [23:19:07] [Server thread/INFO]: Structure Info Saving: true
    [23:19:07] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [23:19:07] [Server thread/INFO]: Anti X-Ray: true
    [23:19:07] [Server thread/INFO]:     Engine Mode: 1
    [23:19:07] [Server thread/INFO]:     Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [23:19:07] [Server thread/INFO]:     Replace Blocks: [1, 5]
    [23:19:07] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [23:19:07] [Server thread/INFO]: Max TNT Explosions: 100
    [23:19:07] [Server thread/INFO]: Mob Spawn Range: 4
    [23:19:07] [Server thread/INFO]: Random Lighting Updates: false
    [23:19:07] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Cane Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Melon Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: NetherWart Growth Modifier: 100%
    [23:19:07] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [23:19:07] [Server thread/INFO]: Sending up to 10 chunks per packet
    [23:19:07] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [23:19:07] [Server thread/INFO]: Preparing start region for level 0 (Seed: -7550620356162349031)
    [23:19:08] [Server thread/INFO]: Preparing start region for level 1 (Seed: -7550620356162349031)
    [23:19:09] [Server thread/INFO]: Preparing start region for level 2 (Seed: -7550620356162349031)
    [23:19:10] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [23:19:10] [Server thread/INFO]: Done (2.599s)! For help, type "help" or "?"
    [23:19:12] [Server thread/INFO]: Plugins (0): [m
    [23:19:13] [Server thread/INFO]: Stopping the server
    [23:19:13] [Server thread/INFO]: Stopping server
    [23:19:13] [Server thread/INFO]: Saving players
    [23:19:13] [Server thread/INFO]: Saving worlds
    [23:19:13] [Server thread/INFO]: Saving chunks for level 'world'/Overworld
    [23:19:13] [Server thread/INFO]: Saving chunks for level 'world_nether'/Nether
    [23:19:14] [Server thread/INFO]: Saving chunks for level 'world_the_end'/The End
     
     
  2. Code (Java):
    public class Points extends Main // My god, why does it extend Main?!
    You need to stop and go learn basic java, it will save you lots of struggling.

    Basically, your Points class is an entire second copy of your plugin, which is both entirely illogical (and vastly wasteful of resources) and not allowed by bukkit.

    Also, you cannot initialize a Points object before onEnable (your current code calls new Points() as soon as your plugin class is loaded), because it uses bukkit methods like getConfig, which are not even usable until the plugin is enabled.
     
  3. Those methods aren't called before onEnable. Why should this be a problem?
     
  4. Yes, they actually are. More reasons why you need to just go take the time to learn basic java, it would really save you frustration and time to fully understand fundamentals.

    Points pointsclass = new Points(); Is called outside of any method; as soon as an instance of a class is created (with new, in this case by the plugin classloader), it also instantiates any global (class-scope) variables in that class.
    onEnable is not called for quite a while after this, and definitely not before (that would be a logical impossibility).

    Best practices: do nothing before onEnable, declare all variables in your main class without an assignment : Points points; and then give them values in onEnable. The only exception is when you need to use onLoad when doing something that involves injecting code into NMS, or modifying server startup.


    TL;DR Points constructor tries to access the plugin config before the plugin config (or the plugin) even exists.

    Edit: I just noticed this is not even the OP.. Oh well, now there are two people that need to learn java,
     
  5. I might not have made myself clear enough. The two methods defined in Points are not called before onEnable is called. You refer to the Points constructor saying it calls the methods defined in said class. It does not. Points does not declare a constructor and as such a default no-arg constructor is created by the compiler. This constructor takes no explicit actions and thus - seeing as the only explicit calls to these methods are in the onEnable method - these methods are not called before onEnable.

    There would be no problems in instantiating Points so long as none of its methods are called before onEnable. Keep in mind I haven't even begun talking about proper design and good practices. This is merely from a functional viewpoint. The code as-is is nowhere near proper.