[Fixed, Solved] Plugin help, Will not load.

Discussion in 'Plugin Development' started by Wesnc, Jun 29, 2011.

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

    Wesnc

    Plugin Errors here, not sure what the problem is, Image of the error is attached.

    KiddieCheck.java
    Code:
    package com.wesnc.kiddieCheck;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class KiddieCheck extends JavaPlugin
    {
    	static String mainDir = "plugins/KiddieCheck";
    	static File kiddieConfig = new File(mainDir+File.separator+"KiddieCheck.properties");
    	static Properties prop = new Properties();
    	Logger logger = Logger.getLogger("Minecraft");
    	KDPlayerListener playerListener = new KDPlayerListener(this);
    	CommandExec commandExecutor = new CommandExec(this);
    	int minAge;
    	boolean kickUnderage;
    	@Override
    	public void onDisable()
    	{
    		logger.log(Level.INFO, "[KiddieCheck] Unloaded");
    	}
    
    	@Override
    	public void onEnable()
    	{
    		new File(mainDir).mkdir();
    		if(!kiddieConfig.exists())
    		{
    			try
    			{
    				kiddieConfig.createNewFile();
    				FileOutputStream out = new FileOutputStream(kiddieConfig);
    				prop.put("MinAge", "15");
    				prop.put("KickUnderaged", true);
    				prop.store(out, "edit accordingly");
    				out.flush();
    				out.close();
    			}
    			catch(IOException ex){}
    		}
    		else
    		{
    			load();
    		}
    		getCommand("age").setExecutor(commandExecutor);
    		registerEvents();
    		logger.log(Level.INFO, "[KiddieCheck] loaded");
    	}
    
    	private void registerEvents()
    	{
    		PluginManager pm = getServer().getPluginManager();
    		pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Normal, this);
    	}
    
    	private void load()
    	{
    		try
    		{
    			FileInputStream in = new FileInputStream(kiddieConfig);
    			prop.load(in);
    			minAge = Integer.parseInt(prop.getProperty("MinAge"));
    			kickUnderage = Boolean.parseBoolean(prop.getProperty("KickUnderaged"));
    		}
    		catch(IOException ex) { }
    	}
    
    }
    
    CommandExec.java
    Code:
    package com.wesnc.kiddieCheck;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class CommandExec implements CommandExecutor
    {
    	public KiddieCheck plugin;
    
    	public CommandExec(KiddieCheck instance)
    	{
    		plugin = instance;
    	}
    
    	@Override
    	public boolean onCommand(CommandSender sender, Command cmd, String label,
    			String[] args)
    	{
    		if(args.length < 2)
    			return false;
    		int argAge = Integer.parseInt(args[0]);
    		boolean kickUnderage = this.plugin.kickUnderage;
    		if(argAge < this.plugin.minAge)
    		{
    			sender.sendMessage("You are underage for this server");
    			if(kickUnderage == true)
    			{
    				Player player = (Player) sender;
    				player.kickPlayer("Underage");
    				this.plugin.getServer().broadcastMessage(player.getDisplayName() +" was kicked for being underage");
    				return true;
    			}
    		}
    		return false;
    	}
    
    }
    
    Dont comment on how mean or cruel this plugin is, not here for that just needing some help.

    MIGHT have found the problem, its not writing anything in the properties file for some reason. Any help on this?
     

    Attached Files:

    Last edited by a moderator: May 18, 2016
  2. Offline

    badbh222

    If the file already exists, it won't write any of the data to it, are you starting the server with no file, I know I'm just pointing out the obvious, but it can happen... :p
     
  3. Offline

    Wesnc

    Found the issue and fixed it, thanks. Deleteing the old file which had nothing in it fixed it.
    And this line:
    Code:
    prop.put("KickUnderaged", true);

    Changing the true to "true" fixed it up
     
  4. Offline

    badbh222

    Heh, it happens to all of us. :D

    Glad to hear you fixed it, interesting plugin idea. :)
     
  5. Offline

    nickguletskii

    This plugin will be useless anyway, because everyone will use fake data.
     
Thread Status:
Not open for further replies.

Share This Page