Solved Event Ecxeption - Ban Plugin

Discussion in 'Plugin Help/Development/Requests' started by ScorixEar, May 24, 2015.

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

    ScorixEar

    Hello guys and girls :D
    I'm going to code a Bansystem back to the roods (without the Bukkit ban api) and now, I think I'm finished. But, there is a problem. I use two files (because of the uuid) and both should be filled with informations if one player join, but both are empty. There is also a big error in the cmd (EventException and NullPointerException - realy hard...) an I'm seeking it now a long time and I want to ask you, if you can help me with this.
    Main class:
    Code:
    package minecrafthaifl.ban.main;
    
    import java.io.File;
    
    import minecrafthaifl.ban.command.CommandHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Bansystem extends JavaPlugin
    {
    	private static Bansystem plugin;
    	private static FileConfiguration d;
    	private static FileConfiguration c;
    	private static File g;
    	private static File f;
    	
    	
    	public void onEnable()
    	{
    		plugin=this;
    		f=YamlHandler.createFile("Bans.yml");
    		c=YamlHandler.createYamlFile(f);
    		g=YamlHandler.createFile("Player.yml");
    		d=YamlHandler.createYamlFile(g);
    		Bukkit.getServer().getPluginManager().registerEvents(new CommandHandler(),this);
    		Bukkit.getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
    		
    	}
    	
    	public static Bansystem getInstance()
    	{
    		return plugin;
    	}
    	public static File getRawBanFile()
    	{
    		return f;
    	}
    	public static FileConfiguration getBanFile()
    	{
    		return c;
    	}
    	public static File getRawPlayerFile()
    	{
    		return g;
    	}
    	public static FileConfiguration getPlayerFile()
    	{
    		return d;
    	}
    }
    
    PlayerJoinListener:
    Code:
    package minecrafthaifl.ban.main;
    
    import java.util.Calendar;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class PlayerJoinListener implements Listener
    {
    
    	public void onPlayerJoin(PlayerJoinEvent e)
    	{
    		FileConfiguration f = Bansystem.getBanFile();
    		FileConfiguration g = Bansystem.getPlayerFile();
    		if(!Bansystem.getPlayerFile().contains(e.getPlayer().getName()))
    		{
    			Bansystem.getPlayerFile().set(e.getPlayer().getName()+".UUID", e.getPlayer().getUniqueId());
    			YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    		}
    		else if((Bansystem.getPlayerFile().get(e.getPlayer().getName()+".UUID")!=e.getPlayer().getUniqueId()))
    		{
    			Bansystem.getBanFile().set(e.getPlayer().getName()+".UUID", e.getPlayer().getUniqueId());
    			YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    		}
    		
    		if(!Bansystem.getBanFile().getBoolean(e.getPlayer()+".Ban"))
    		{
    			Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Ban", false);
    			Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Grund", "---");
    			Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Dauer", "---");
    			Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Entbannungsdatum", 0);
    			if(Bansystem.getBanFile().contains(e.getPlayer().getUniqueId()+".LastMen"))
    			{
    				Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".LastMen", "---");
    			}
    			if(!Bansystem.getBanFile().contains(e.getPlayer().getUniqueId()+".Kicks"))
    			{
    					Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Kicks", 0);
    			}
    			
    			if(Bansystem.getBanFile().contains(e.getPlayer().getUniqueId()+".LastKickGrund"))
    			{
    				Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".LastKickGrund", "---");
    			}
    			Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".KickOff", false);
    			YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    			YamlHandler.saveYamlFile(g, Bansystem.getRawPlayerFile());
    		}
    		else
    		{
    			Calendar c = Calendar.getInstance();
    			
    			if(Bansystem.getBanFile().get(e.getPlayer().getUniqueId()+".Dauer")!="permanent")
    			{
    				Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Dauer", (Bansystem.getBanFile().getInt(e.getPlayer().getUniqueId()+".Entbannungsdatum")-c.getTimeInMillis()));
    				YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    				if(Bansystem.getBanFile().getLong(e.getPlayer().getUniqueId()+".Dauer")<=0)
    				{
    					Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Ban", false);
    					YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    				}
    				else
    					e.getPlayer().kickPlayer("§4Du wurdest gebannt!\n§cGrund: "+Bansystem.getBanFile().getString(e.getPlayer().getUniqueId()+".Grund")+"\n§aDauer: §b"+Bansystem.getBanFile().getString(e.getPlayer().getUniqueId()+".Dauer")+"\n\n§9Du kannst dich auf www.venoria.de für eine Entbannung bewerben.");
    			}
    			else
    				e.getPlayer().kickPlayer("§4Du wurdest gebannt!\n§cGrund: "+Bansystem.getBanFile().getString(e.getPlayer().getUniqueId()+".Grund")+"\n§aDauer: §b"+Bansystem.getBanFile().getString(e.getPlayer().getUniqueId()+".Dauer")+"\n\n§9Du kannst dich auf www.venoria.de für eine Entbannung bewerben.");
    			
    		}
    		
    	}
    }
    
    YamlHandler (This class has no Error and works perfectly):
    Code:
    package minecrafthaifl.ban.main;
    
    import java.io.File;
    import java.io.IOException;
    
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    
    public class YamlHandler
    {
    	public static File createFile(String filename)
    	{
    		File f= new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + filename);
    		if(!f.exists())
    		{
    			try {
    				f.createNewFile();
    			} catch (IOException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    		return f;
    	}
    	public static FileConfiguration createYamlFile(File f)
    	{
    		FileConfiguration fc= YamlConfiguration.loadConfiguration(f);
    		
    		return fc;
    	}
    	
    	public static void saveYamlFile(FileConfiguration c,File f)
    	{
    		try {
    			c.save(f);
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    	}
    	
    }
    
    
    Command (also has no error):
    Code:
    package minecrafthaifl.ban.command;
    
    import org.bukkit.entity.Player;
    
    public abstract class Command
    {
    	private int minarg;
    	private int maxarg;
    	
    	public Command(int minargs,int maxargs)
    	{
    		this.minarg=minargs;
    		this.maxarg=maxargs;
    	}
    	
    	
    	public int getMinArgs()
    	{
    		return minarg;
    	}
    	public int getMaxArgs()
    	{
    		return maxarg;
    	}
    		
    	public abstract String getPermission();
    	
    	//Parameter Übergabe
    	public abstract void onCommandUse(Player p,String args[]);
    	
    	public abstract String getCommand();
    	
    }
    
    CommandHandler (also no ...):
    Code:
    package minecrafthaifl.ban.command;
    
    import java.util.ArrayList;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    
    public class CommandHandler implements Listener{
    	
    	private ArrayList<Command> commandlist = new ArrayList<Command>(); 
    	
    	public CommandHandler()
    	{
    		registerCommand(new CommandBan());
    		registerCommand(new CommandKick());
    		registerCommand(new CommandUnban());
    		registerCommand(new CommandKickoff());
    	}
    	
    	private void registerCommand(Command c)
    	{
    		commandlist.add(c);
    	}
    	
    	@EventHandler
    	void onCommand(PlayerCommandPreprocessEvent e)
    	{
    		Player p = e.getPlayer();
    		String s = e.getMessage();
    		String[] args = s.split(" ");
    		
    		String command = args[0];
    		String[] argm = new String[args.length -1];
    		for(int i=1; i<args.length;i++)
    		{
    			argm[i-1]=args[i];
    		}
    		
    		if(command.startsWith("/"))
    		{
    			Command com = null;
    			
    			for(Command comm : this.commandlist)
    			{
    				if(comm.getCommand().equalsIgnoreCase(command))
    				{
    					com=comm;
    				}
    			}
    			
    			if(com!=null)
    			{
    				if(com.getPermission()==null||e.getPlayer().hasPermission(com.getPermission()))
    				{
    					int arglength=argm.length;
    					if(arglength <com.getMinArgs())
    					{
    						e.getPlayer().sendMessage("§4Du hast zu wenig Argumente eingegeben. Bitte überprüfe deine Eingabe!");
    					}
    					else if(arglength >com.getMaxArgs())
    					{
    						e.getPlayer().sendMessage("§4Du hast zu viele Argumente eingegeben. Bitte überprüfe deine Eingabe!");
    					}
    					else
    					{
    						com.onCommandUse(p, argm);
    					}
    				}
    				else {
    					e.getPlayer().sendMessage("§4Du hast keine Permission!");
    				}
    			}
    		}
    		else
    			e.getPlayer().sendMessage("§4Dieser Befehl ist nicht registriert!");
    	}	
    }
    
    CommandBan:
    Code:
    package minecrafthaifl.ban.command;
    
    import java.util.Calendar;
    
    import minecrafthaifl.ban.main.Bansystem;
    import minecrafthaifl.ban.main.YamlHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    
    
    public class CommandBan extends Command{
    
    	public CommandBan() {
    		super(0, 3);
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	public String getPermission() {
    		// TODO Auto-generated method stub
    		return "ban.*";
    	}
    
    	@Override
    	public void onCommandUse(Player p, String[] args) {
    		// TODO Auto-generated method stub
    		String e;
    		Calendar c = Calendar.getInstance();
    		FileConfiguration f = Bansystem.getBanFile();
    		
    		if(args.length==0)
    		{
    			p.sendMessage("§c Zu wenig Argumente! Denke daran: /ban <Name> [Grund] [Dauer in Tagen]");
    		}
    		else if(Bukkit.getPlayer(args[0])==null)
    		{
    			if(Bansystem.getPlayerFile().contains(args[0])){
    				e=Bansystem.getPlayerFile().getString(args[0]+".UUID");
    				if(args.length==1)
    				{
    						Bansystem.getBanFile().set(e+".Ban", true);
    						Bansystem.getBanFile().set(e+".Grund", "Der Bannhammer hat gesprochen!");
    						Bansystem.getBanFile().set(e+".Dauer", "permanent");
    						Bansystem.getBanFile().set(e+".LastPlayer", p.getName());
    						YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    						Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(e+".Grund")+"§c für §6"+Bansystem.getBanFile().get(e+".Dauer")+"§c gebannt!");
    						
    					
    				}
    				else if(args.length==2)
    				{
    					Bansystem.getBanFile().set(e+".Ban", true);
    					Bansystem.getBanFile().set(e+".Grund", args[1]);
    					Bansystem.getBanFile().set(e+".Dauer", "permanent");
    					Bansystem.getBanFile().set(e+".LastPlayer", p.getName());
    					YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    					Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(e+".Grund")+"§c für §6"+Bansystem.getBanFile().get(e+".Dauer")+"§c gebannt!");
    				}
    				else if(args.length==3)
    				{
    					Bansystem.getBanFile().set(e+".Ban", true);
    					Bansystem.getBanFile().set(e+".Grund", args[1]);
    					Bansystem.getBanFile().set(e+".Dauer", (c.getTimeInMillis())+Long.parseLong(args[2])*24*60*60*1000);
    					Bansystem.getBanFile().set(e+".LastPlayer", p.getName());
    					YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    					Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(e+".Grund")+"§c für §6"+Bansystem.getBanFile().get(e+".Dauer")+"§c gebannt!");
    					
    				}
    			}
    			else
    			{
    				p.sendMessage("Dieser Spieler war noch nie online!");
    			}
    					
    		}
    		else if(args.length==1)
    		{
    			
    			
    				Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Ban", true);
    				Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund", "Der Bannhammer hat gesprochen!");
    				Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer", "permanent");
    				Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".LastPlayer", p.getName());
    				YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    				Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gebannt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund")+"\n§aDauer: §b"+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer")+"\n\n§9Du kannst dich auf www.venoria.de für eine Entbannung bewerben.");
    				Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund")+"§c für §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer")+"§c gebannt!");
    			
    		}
    		else if(args.length==2)
    		{
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Ban", true);
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund", args[1]);
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer", "permanent");
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".LastPlayer", p.getName());
    			YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    			Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gebannt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund")+"\n§aDauer: §b"+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer")+"\n\n§9Du kannst dich auf www.venoria.de für eine Entbannung bewerben.");
    			Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund")+"§c für §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer")+"§c gebannt!");
    		}
    		else if(args.length==3)
    		{
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Ban", true);
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund", args[1]);
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer", (c.getTimeInMillis())+Long.parseLong(args[2])*24*60*60*1000);
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".LastPlayer", p.getName());
    			YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    			Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gebannt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund")+"\n§aDauer: §b"+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer")+"\n\n§9Du kannst dich auf www.venoria.de für eine Entbannung bewerben.");
    			Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId()+".Grund")+"§c für §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId()+".Dauer")+"§c gebannt!");
    		}
    		
    	}
    
    	@Override
    	public String getCommand() {
    		// TODO Auto-generated method stub
    		return "/ban";
    	}
    
    }
    
    CommandKick:
    Code:
    package minecrafthaifl.ban.command;
    
    import minecrafthaifl.ban.main.Bansystem;
    import minecrafthaifl.ban.main.YamlHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    public class CommandKick extends Command
    {
    
    	public CommandKick() {
    		super(0, 2);
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	public String getPermission() {
    		// TODO Auto-generated method stub
    		return "kick.*";
    	}
    
    	@Override
    	public void onCommandUse(Player p, String[] args) {
    		// TODO Auto-generated method stub
    		FileConfiguration f = Bansystem.getBanFile();
    		if(args.length==0)
    		{
    			p.sendMessage("§c Zu wenig Argumente! Denke daran: /kick <Name> [Grund]");
    		}
    		else if(Bukkit.getPlayer(args[0])==null)
    		{
    			p.sendMessage("§cDieser Spieler ist nicht online!");
    		}
    		else if(args.length==1)
    		{
    			if(!Bansystem.getBanFile().getBoolean(Bukkit.getPlayer(args[0]).getUniqueId()+".KickOff"))
    			{
    				Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".LastKickGrund", "Du wurdest gekickt!");
    				Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Kicks", Bansystem.getBanFile().getInt(Bukkit.getPlayer(args[0]).getUniqueId()+".Kicks")+1);
    				YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    				Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gekickt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId()+".LastKickGrund"));
    				Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId()+".LastKickGrund")+"§c gekickt!");
    			}
    			else
    				p.sendMessage("§cDieser Spieler hat KickOff an!");
    		}
    		else if (args.length==2)
    		{
    			if(!Bansystem.getBanFile().getBoolean(Bukkit.getPlayer(args[0]).getUniqueId()+".KickOff"))
    			{
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".LastKickGrund", args[1]);
    			Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Kicks", Bansystem.getBanFile().getInt(Bukkit.getPlayer(args[0]).getUniqueId()+".Kicks")+1);
    			YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    			Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gekickt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId()+".LastKickGrund"));
    			Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId()+".LastKickGrund")+"§c gekickt!");
    		}
    		else
    			p.sendMessage("§cDieser Spieler hat KickOff an!");
    		}
    	}
    
    	@Override
    	public String getCommand() {
    		// TODO Auto-generated method stub
    		return "/kick";
    	}
    
    }
    
    CommandKickoff:
    Code:
    package minecrafthaifl.ban.command;
    
    import minecrafthaifl.ban.main.Bansystem;
    import minecrafthaifl.ban.main.YamlHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    public class CommandKickoff extends Command
    {
    
    	public CommandKickoff() {
    		super(0, 1);
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	public String getPermission() {
    		// TODO Auto-generated method stub
    		return "kickoff.*";
    	}
    
    	@Override
    	public void onCommandUse(Player p, String[] args) {
    		// TODO Auto-generated method stub
    		FileConfiguration f =  Bansystem.getBanFile();
    		if(args.length==0)
    		{
    			if(Bansystem.getBanFile().getBoolean(p.getPlayer().getUniqueId()+".KickOff"))
    			{
    				Bansystem.getBanFile().set(p.getPlayer().getUniqueId()+".KickOff", false);
    				YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    				p.sendMessage("§cKickOff ausgestellt.");
    			}
    			else
    			{
    				Bansystem.getBanFile().set(p.getPlayer().getUniqueId()+".KickOff", true);
    				YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    				p.sendMessage("§cKickOff angestellt.");
    			}
    		}
    		else 
    		{
    			if(Bukkit.getPlayer(args[0])==null)
    			{
    				p.sendMessage("§cDieser Spieler ist nicht online!");
    			}
    			else
    			{
    				
    				if(Bansystem.getBanFile().getBoolean(Bukkit.getPlayer(args[0]).getUniqueId()+".KickOff"))
    				{
    					Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".KickOff", false);
    					YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    					p.sendMessage("§cKickOff von "+args[0]+" ausgestellt.");
    				}
    				else
    				{
    					Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".KickOff", true);
    					YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    					p.sendMessage("§cKickOff von "+args[0]+" angestellt.");
    				}
    			}
    		}
    	}
    
    	@Override
    	public String getCommand() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    }
    
    CommandUnban:
    Code:
    package minecrafthaifl.ban.command;
    
    import minecrafthaifl.ban.main.Bansystem;
    import minecrafthaifl.ban.main.YamlHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    public class CommandUnban extends Command{
    
    	public CommandUnban() {
    		super(0,1);
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	public String getPermission() {
    		// TODO Auto-generated method stub
    		return "unban.*";
    	}
    
    	@Override
    	public void onCommandUse(Player p, String[] args) {
    		// TODO Auto-generated method stub
    		String e;
    		FileConfiguration f = Bansystem.getBanFile();
    		if(args.length==0)
    		{
    			p.sendMessage("§c Zu wenig Argumente! Denke daran: /unban <Name>");
    		}
    		else if(Bukkit.getPlayer(args[0])==null)
    		{
    			if(Bansystem.getPlayerFile().contains(args[0])){
    				e=Bansystem.getPlayerFile().getString(args[0]+".UUID");
    				if(Bansystem.getBanFile().getBoolean(e+".Ban"))
    				{
    					if(args.length==1)
    					{
    						Bansystem.getBanFile().set(e+".Ban", false);
    						YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    						p.sendMessage("§6"+args[0]+" wurde entbannt.");
    					}
    				}
    				else
    				{
    					p.sendMessage("§cDieser Spieler ist nicht gebannt!");
    				}
    			}
    			else
    			{
    				p.sendMessage("§cDieser Spieler war noch nie online!");
    			}
    		}
    			
    		else if(args.length==1)
    		{
    			if(Bansystem.getBanFile().getBoolean(Bukkit.getPlayer(args[0]).getUniqueId()+".Ban"))
    			{
    				Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId()+".Ban", false);
    				YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    				p.sendMessage("§6"+args[0]+" wurde entbannt.");
    			}
    			
    			else
    			{
    			p.sendMessage("§cDieser Spieler ist nicht gebannt!");
    			}
    		}
    	}
    
    	@Override
    	public String getCommand() {
    		// TODO Auto-generated method stub
    		return "/unban";
    	}
    
    }
    

    I hope, you can help.
    Thank you :)

    And the Error Code:
    Code:
    [00:59:29] [Server thread/INFO]: CONSOLE: [0;31;1mPlease note that this command is not supported and may cause issues when using some plugins.[m
    [00:59:29] [Server thread/INFO]: CONSOLE: [0;31;1mIf you encounter any issues please use the /stop command to restart your server.[m
    [00:59:29] [Server thread/INFO]: Debug logging is disabled
    [00:59:29] [Server thread/INFO]: Server Ping Player Sample Count: 12
    [00:59:29] [Server thread/INFO]: Using 4 threads for Netty based IO
    [00:59:29] [Server thread/INFO]: -------- World Settings For [world] --------
    [00:59:29] [Server thread/INFO]: Item Despawn Rate: 6000
    [00:59:29] [Server thread/INFO]: Item Merge Radius: 2.5
    [00:59:29] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [00:59:29] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [00:59:29] [Server thread/INFO]: View Distance: 10
    [00:59:29] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [00:59:29] [Server thread/INFO]: Mob Spawn Range: 4
    [00:59:29] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [00:59:29] [Server thread/INFO]: Anti X-Ray: true
    [00:59:29] [Server thread/INFO]:     Engine Mode: 1
    [00:59:29] [Server thread/INFO]:     Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [00:59:29] [Server thread/INFO]:     Replace Blocks: [1, 5]
    [00:59:29] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Cane Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Melon Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [00:59:29] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [00:59:29] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [00:59:29] [Server thread/INFO]: Random Lighting Updates: false
    [00:59:29] [Server thread/INFO]: Structure Info Saving: true
    [00:59:29] [Server thread/INFO]: Sending up to 5 chunks per packet
    [00:59:29] [Server thread/INFO]: Max TNT Explosions: 100
    [00:59:29] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [00:59:29] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [00:59:29] [Server thread/INFO]: Clear tick list: false
    [00:59:29] [Server thread/INFO]: Experience Merge Radius: 3.0
    [00:59:29] [Server thread/INFO]: Max Entity Collisions: 8
    [00:59:29] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [00:59:29] [Server thread/INFO]: -------- World Settings For [world_nether] --------
    [00:59:29] [Server thread/INFO]: Item Despawn Rate: 6000
    [00:59:29] [Server thread/INFO]: Item Merge Radius: 2.5
    [00:59:29] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [00:59:29] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [00:59:29] [Server thread/INFO]: View Distance: 10
    [00:59:29] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [00:59:29] [Server thread/INFO]: Mob Spawn Range: 4
    [00:59:29] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [00:59:29] [Server thread/INFO]: Anti X-Ray: true
    [00:59:29] [Server thread/INFO]:     Engine Mode: 1
    [00:59:29] [Server thread/INFO]:     Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [00:59:29] [Server thread/INFO]:     Replace Blocks: [1, 5]
    [00:59:29] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Cane Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Melon Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [00:59:29] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [00:59:29] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [00:59:29] [Server thread/INFO]: Random Lighting Updates: false
    [00:59:29] [Server thread/INFO]: Structure Info Saving: true
    [00:59:29] [Server thread/INFO]: Sending up to 5 chunks per packet
    [00:59:29] [Server thread/INFO]: Max TNT Explosions: 100
    [00:59:29] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [00:59:29] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [00:59:29] [Server thread/INFO]: Clear tick list: false
    [00:59:29] [Server thread/INFO]: Experience Merge Radius: 3.0
    [00:59:29] [Server thread/INFO]: Max Entity Collisions: 8
    [00:59:29] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [00:59:29] [Server thread/INFO]: -------- World Settings For [world_the_end] --------
    [00:59:29] [Server thread/INFO]: Item Despawn Rate: 6000
    [00:59:29] [Server thread/INFO]: Item Merge Radius: 2.5
    [00:59:29] [Server thread/INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [00:59:29] [Server thread/INFO]: Arrow Despawn Rate: 1200
    [00:59:29] [Server thread/INFO]: View Distance: 10
    [00:59:29] [Server thread/INFO]: Zombie Aggressive Towards Villager: true
    [00:59:29] [Server thread/INFO]: Mob Spawn Range: 4
    [00:59:29] [Server thread/INFO]: Nerfing mobs spawned from spawners: false
    [00:59:29] [Server thread/INFO]: Anti X-Ray: true
    [00:59:29] [Server thread/INFO]:     Engine Mode: 1
    [00:59:29] [Server thread/INFO]:     Hidden Blocks: [14, 15, 16, 21, 48, 49, 54, 56, 73, 74, 82, 129, 130]
    [00:59:29] [Server thread/INFO]:     Replace Blocks: [1, 5]
    [00:59:29] [Server thread/INFO]: Cactus Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Cane Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Melon Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Mushroom Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Pumpkin Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Sapling Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Wheat Growth Modifier: 100%
    [00:59:29] [Server thread/INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [00:59:29] [Server thread/INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [00:59:29] [Server thread/INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [00:59:29] [Server thread/INFO]: Random Lighting Updates: false
    [00:59:29] [Server thread/INFO]: Structure Info Saving: true
    [00:59:29] [Server thread/INFO]: Sending up to 5 chunks per packet
    [00:59:29] [Server thread/INFO]: Max TNT Explosions: 100
    [00:59:29] [Server thread/INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [00:59:29] [Server thread/INFO]: Chunks to Grow per Tick: 650
    [00:59:29] [Server thread/INFO]: Clear tick list: false
    [00:59:29] [Server thread/INFO]: Experience Merge Radius: 3.0
    [00:59:29] [Server thread/INFO]: Max Entity Collisions: 8
    [00:59:29] [Server thread/INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [00:59:29] [Server thread/INFO]: [Bansystem] Disabling Bansystem v1.0
    [00:59:29] [Server thread/INFO]: [Bansystem] Loading Bansystem v1.0
    [00:59:29] [Server thread/INFO]: [Bansystem] Enabling Bansystem v1.0
    [00:59:29] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [00:59:29] [Server thread/INFO]: CONSOLE: [0;32;1mReload complete.[m
    [00:59:37] [Server thread/INFO]: minecrafthaifl issued server command: /help
    [00:59:37] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to Bansystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
        at minecrafthaifl.ban.command.CommandHandler.onCommand(CommandHandler.java:47) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 16 more
    [00:59:40] [Server thread/INFO]: minecrafthaifl lost connection: Disconnected
    [00:59:40] [Server thread/INFO]: minecrafthaifl left the game.
    [00:59:43] [Netty Server IO #2/INFO]: UUID of player minecrafthaifl is f8f42751-0047-3543-9ef3-15ea88591bbf
    [00:59:43] [Server thread/INFO]: minecrafthaifl[/127.0.0.1:51337] logged in with entity id 1267 at ([world]-15.796677324268192, 99.61005942101882, 59.517962755519065)
    [00:59:46] [Server thread/INFO]: minecrafthaifl issued server command: /help
    [00:59:46] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to Bansystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
        at minecrafthaifl.ban.command.CommandHandler.onCommand(CommandHandler.java:47) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 16 more
    [00:59:50] [Server thread/INFO]: minecrafthaifl issued server command: /ban
    [00:59:50] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to Bansystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
        at minecrafthaifl.ban.command.CommandHandler.onCommand(CommandHandler.java:47) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 16 more
    [00:59:54] [Server thread/INFO]: minecrafthaifl issued server command: /ban minecrafthaifl
    [00:59:54] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to Bansystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
        at minecrafthaifl.ban.command.CommandHandler.onCommand(CommandHandler.java:47) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 16 more
    [01:00:50] [Server thread/INFO]: minecrafthaifl lost connection: Disconnected
    [01:00:50] [Server thread/INFO]: minecrafthaifl left the game.
    
     
    Last edited by a moderator: May 24, 2015
  2. Offline

    sciolizer

    @ScorixEar

    NullPointerExceptions are actually almost never hard to solve. And you actually only have one problem, not two. Notice the words "Caused by" preceding NullPointerException - the EventException is a direct cause of the NullPointerException, so you actually only need to deal with the NullPointerException.

    The very next line after the NullPointerException says

    Code:
    at minecrafthaifl.ban.command.CommandHandler.onCommand(CommandHandler.java:47) ~[?:?]
    Your line 47 is

    Code:
    if(comm.getCommand().equalsIgnoreCase(command))
    There's exactly two different ways this line could directly throw a NullPointerException. Either comm is null, or else comm is not null, but comm.getCommand() is null.

    The first thing I'd do is figure out which of the two possibilities it is. You can do that by splitting your line apart

    Code:
    String command = comm.getCommand();
    if (command.equalsIgnoreCase(command))
    
    and then running your program again. Under the new code, the stack trace will either say 47 or 48. The next thing to do from there would be to try to figure out why it's null. For instance, if the new stack trace says 47 (implying that comm is null), you could try adding the following line at the top of your CommandHandler.registerCommand:

    Code:
    if (c == null) throw new RuntimeException("the problem is here!");
    
    Alternatively, you could set a breakpoint on the current line of CommandHandler.registerCommand, although that's going to require some setup if you haven't done it before. It's very worth it though; you'll solve problems much faster.

    Also, everything I've just told you can be found in the sticky in the old forum.
     
  3. Offline

    ScorixEar

    Yeah, I know, how to read the error code ;) but the CommandHandler Class is not wrong -> the errir is at the registercommand and so in one of these commands (like CommandBan) and thats why im seeking, because i don't find the errit in these commands :D
    But thank you for you help^^

    I tested the PlayerJoinListener and just write this code:
    Code:
    package minecrafthaifl.ban.main;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class PlayerJoinListener implements Listener
    {
    
    	public void onPlayerJoin(PlayerJoinEvent e)
    	{
    		FileConfiguration f = Bansystem.getBanFile();
    		FileConfiguration g = Bansystem.getPlayerFile();
    		Bansystem.getPlayerFile().set(e.getPlayer().getName()+".UUID", e.getPlayer().getUniqueId());
    		YamlHandler.saveYamlFile(Bansystem.getPlayerFile(), Bansystem.getRawPlayerFile());
    
    		Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Ban", false);
    		Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Grund", "---");
    		Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Dauer", "---");
    		Bansystem.getBanFile().set(e.getPlayer().getUniqueId()+".Entbannungsdatum", 0);
    		YamlHandler.saveYamlFile(Bansystem.getBanFile(), Bansystem.getRawBanFile());
    		f.set(e.getPlayer().getUniqueId()+"", e.getPlayer().getName());
    		YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
    		
    		
    	}
    }
    
    but nothing happens... The bans.yml and the players.yml are both empty, after I joined the server...
     
    Last edited: May 25, 2015
  4. Offline

    sciolizer

    @ScorixEar

    Sorry, I misunderstand what you meant by that line, which is why I went into explaining about stack traces. Should have guessed you already knew that based on the size of your project, but oh well.

    `PlayerJoinListener.onPlayerJoin` needs an `@EventHandler` annotation.

    Also, in `YamlHandler`, you might want to call `f.mkdirs();` before calling `f.createNewFile();`.
     
  5. Offline

    ScorixEar

    Oh my god, I'm so stupid, of course :D thank you ^^
    What do the f.mkdirs(); ?
     
  6. Offline

    I Al Istannen

    Last edited: May 25, 2015
  7. Offline

    nverdier

    Incorrect. If you have a File object, you can do
    #mkdirs(): Creates a folder (directory) and any parent folders that are non-existent
    #mkdir(): Creates a folder (directory)
    #createNewFile(): Create a file

    So you're somewhat correct, but it with your example, it would create a folder called 'file' instead of an actual file.
     
    I Al Istannen likes this.
  8. Offline

    I Al Istannen

    @nverdier Yes, it was basically what i ment. But very poor expressed. Thanks for correction!
     
    nverdier likes this.
  9. Offline

    ScorixEar

    Ooh ok, thats good. But the Bans and players.yml must in the folder, named Bansystem, can I change the name of the created folder?
     
  10. Offline

    sciolizer

  11. Offline

    ScorixEar

    I made this now
    YamlHandler:
    Code:
    package minecrafthaifl.ban.main;
    
    import java.io.File;
    import java.io.IOException;
    
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    
    public class YamlHandler
    {
        public static File createFile(String filename)
        {
            File f= new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + filename);
            if(!f.exists())
            {
                f.mkdirs();
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return f;
        }
        public static FileConfiguration createYamlFile(File f)
        {
            FileConfiguration fc= YamlConfiguration.loadConfiguration(f);
           
            return fc;
        }
       
        public static void saveYamlFile(FileConfiguration c,File f)
        {
            try {
                c.save(f);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
        }
       
    }
    
    And Use the old PlayerJoinListener + EventHandler
    But there are ow this Error-messages:
    Code:
    [14:12:05] [Server thread/ERROR]: Cannot load C:\Users\Paul\Desktop\Skript Server\f\plugins\Bansystem\Player.yml
    org.bukkit.configuration.InvalidConfigurationException: could not determine a constructor for the tag tag:yaml.org,2002:java.util.UUID
    in 'string', line 2, column 9:
          UUID: !!java.util.UUID {}
                ^
    
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:57) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:226) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:169) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:180) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at minecrafthaifl.ban.main.YamlHandler.createYamlFile(YamlHandler.java:29) [Bansystem.jar:?]
        at minecrafthaifl.ban.main.Bansystem.onEnable(Bansystem.java:26) [Bansystem.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.loadPlugin(CraftServer.java:356) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.enablePlugins(CraftServer.java:316) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.reload(CraftServer.java:746) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.Bukkit.reload(Bukkit.java:534) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServer.java:646) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchServerCommand(CraftServer.java:632) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.aN(DedicatedServer.java:405) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:369) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: org.yaml.snakeyaml.constructor.ConstructorException: could not determine a constructor for the tag tag:yaml.org,2002:java.util.UUID
    in 'string', line 2, column 9:
          UUID: !!java.util.UUID {}
                ^
    
        at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructUndefined.construct(SafeConstructor.java:501) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:373) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:147) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:354) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:485) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:373) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:147) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:354) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:485) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:141) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:127) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:481) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:400) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 21 more
    [14:12:05] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [14:12:05] [Server thread/INFO]: CONSOLE: [0;32;1mReload complete.[m
     
  12. Offline

    I Al Istannen

    @ScorixEar You set the value of the "UUID" path (PlayerJoinListener snippet line 15) to a UUID. To be able to read that, the class must implement ConfigurationSerializable. You can read that here:
    https://hub.spigotmc.org/javadocs/b.../serialization/ConfigurationSerializable.html

    Since UUID doesn't implement that, and doesn't offer the deserialisation methods, bukkit doesn't know what to do with the UUID.
    Try saving it as a String by using UUID#toString(). That should be possible to save and read. For reading just use "UUID.fromString(String string)".

    I hope that was correct, never had that error before :)

    And you may tag sb. because otherwise they don't get an Alert.
     
  13. Offline

    ScorixEar

    Haha :D Thank you @I Al Istannen
    Do you know what there is now xD
    The plugin created two folder, named bans.yml and player.yml. The problem is also the .mkdirs @sciolizer
    The position is not correct now :D
     
  14. Offline

    I Al Istannen

    @ScorixEar So you have two File objects? One for the dir, the other for the actual file. Then, if "!dir.exists()", call "dir.mkdirs()" and see what happens. Then you should be able to create the actual file :) If something doesn't work, i can give a more "in depth" explanation, but I think you can do it!
     
  15. Offline

    ScorixEar

    Thats the problem in the YamlHandler i test if !f.exists() and if not they do f.mkdirs()
    YamlHandler:
    Code:
    package minecrafthaifl.ban.main;
    import java.io.File;
    import java.io.IOException;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    public class YamlHandler
    {
        public static File createFile(String filename)
        {
            File f= new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + filename);
            if(!f.exists())
            {
                f.mkdirs();
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return f;
        }
        public static FileConfiguration createYamlFile(File f)
        {
            FileConfiguration fc= YamlConfiguration.loadConfiguration(f);
          
            return fc;
        }
      
        public static void saveYamlFile(FileConfiguration c,File f)
        {
            try {
                c.save(f);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
          
        }
      
    }
     
  16. Offline

    I Al Istannen

    @ScorixEar
    So this creates a Directory dir. If dir doesn't exists, the directory and all parent directories will be created.

    Then we create another File, which will be our actual file. We check if the file exists and if it doesn't, we create the file.
    Code:
    File dir = new File(Path.to.your.directory);
    if(!dir.exists()) {
      dir.mkdirs();
    }
    
    File actualFile = new File(Path.to.your.file);    
    if(!output.exists()) {
      output.createNewFile();
    }
    
     
  17. Offline

    ScorixEar

    Doesn't worked, I tried this:
    Code:
    File dir = new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + filename);
           
                dir.mkdirs();
           
            File f= new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + filename);
            if(!f.exists())
            {
               
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
    an implemented the four commands with the commandhandler
    Code:
    package minecrafthaifl.ban.command;
    
    import java.util.ArrayList;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    
    public class CommandHandler implements Listener{
       
        private ArrayList<Command> commandlist = new ArrayList<Command>();
       
        public CommandHandler()
        {
            registerCommand(new CommandBan());
            registerCommand(new CommandKick());
            registerCommand(new CommandUnban());
            registerCommand(new CommandKickoff());
        }
       
        private void registerCommand(Command c)
        {
            commandlist.add(c);
        }
       
        @EventHandler
        void onCommand(PlayerCommandPreprocessEvent e)
        {
            Player p = e.getPlayer();
            String s = e.getMessage();
            String[] args = s.split(" ");
           
            String command = args[0];
            String[] argm = new String[args.length -1];
            for(int i=1; i<args.length;i++)
            {
                argm[i-1]=args[i];
            }
           
            if(command.startsWith("/"))
            {
                Command com = null;
               
                for(Command comm : this.commandlist)
                {
                    if(comm.getCommand().equalsIgnoreCase(command))
                    {
                        com=comm;
                    }
                }
               
                if(com!=null)
                {
                    if(com.getPermission()==null||e.getPlayer().hasPermission(com.getPermission()))
                    {
                        int arglength=argm.length;
                        if(arglength <com.getMinArgs())
                        {
                            e.getPlayer().sendMessage("§4Du hast zu wenig Argumente eingegeben. Bitte überprüfe deine Eingabe!");
                        }
                        else if(arglength >com.getMaxArgs())
                        {
                            e.getPlayer().sendMessage("§4Du hast zu viele Argumente eingegeben. Bitte überprüfe deine Eingabe!");
                        }
                        else
                        {
                            com.onCommandUse(p, argm);
                        }
                    }
                    else {
                        e.getPlayer().sendMessage("§4Du hast keine Permission!");
                    }
                }
            }
            else
                e.getPlayer().sendMessage("§4Dieser Befehl ist nicht registriert!");
        }   
    }
    everything works (bansystem folder is now there and the two files bans.yml and players.yml)
    but if I try a command like /help oder /kickoff, doesn't matter wich, there are these errors:
    Code:
    [15:22:37] [Server thread/INFO]: minecrafthaifl issued server command: /ban
    [15:22:37] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to Bansystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
        at minecrafthaifl.ban.command.CommandHandler.onCommand(CommandHandler.java:47) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 16 more
    [15:22:58] 
    also NullPointer (And Yes I know what this means xD)
    and thats the main problem from top I think...
    the commands are not working and I don't find the mistake
    @sciolizer @I Al Istannen
     
  18. Offline

    I Al Istannen

    @ScorixEar You have the same part for the Directory and the File. Try appending the filename just to the file and not to the dir. And why do you use PlayerCommandPreprocessEvent to register a Command? Why not doing it the normal way? :p (http://wiki.bukkit.org/HUGE_Plugin_Tutorial#Commands

    EDIT: And around line 47, getCommand returns a command and not a String. This can't be equals. (But maybe I missed sth.)
     
  19. Offline

    ScorixEar

    As I wrote at the top, in the classes CommandHandler and Command are no mistakes. I use this way, because I don't must register my commands in the plugin.yml and every Command is one class - thats very clear to correct and unerstand I think
     
  20. Offline

    I Al Istannen

    @ScorixEar I'm sorry, it is quite a long conversation. Have you changed your Files? Because you create a Directory first and then try to create a file with the same name. That can't work.
     
  21. Offline

    ScorixEar

    Ok, back to the beginning :D
    My YamlHandler now:
    Code:
    package minecrafthaifl.ban.main;
    
    import java.io.File;
    import java.io.IOException;
    
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    
    public class YamlHandler
    {
        public static File createFile(String filename)
        {
            File dir = new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + filename);
           
                dir.mkdirs();
           
            File f= new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + filename);
            if(!f.exists())
            {
               
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return f;
        }
        public static FileConfiguration createYamlFile(File f)
        {
            FileConfiguration fc= YamlConfiguration.loadConfiguration(f);
           
            return fc;
        }
       
        public static void saveYamlFile(FileConfiguration c,File f)
        {
            try {
                c.save(f);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
        }
       
    }
    
    my CommandHandler:
    Code:
    package minecrafthaifl.ban.command;
    
    import java.util.ArrayList;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    
    public class CommandHandler implements Listener{
       
        private ArrayList<Command> commandlist = new ArrayList<Command>();
       
        public CommandHandler()
        {
            registerCommand(new CommandBan());
            registerCommand(new CommandKick());
            registerCommand(new CommandUnban());
            registerCommand(new CommandKickoff());
        }
       
        private void registerCommand(Command c)
        {
            commandlist.add(c);
        }
       
        @EventHandler
        void onCommand(PlayerCommandPreprocessEvent e)
        {
            Player p = e.getPlayer();
            String s = e.getMessage();
            String[] args = s.split(" ");
           
            String command = args[0];
            String[] argm = new String[args.length -1];
            for(int i=1; i<args.length;i++)
            {
                argm[i-1]=args[i];
            }
           
            if(command.startsWith("/"))
            {
                Command com = null;
               
                for(Command comm : this.commandlist)
                {
                    if(comm.getCommand().equalsIgnoreCase(command))
                    {
                        com=comm;
                    }
                }
               
                if(com!=null)
                {
                    if(com.getPermission()==null||e.getPlayer().hasPermission(com.getPermission()))
                    {
                        int arglength=argm.length;
                        if(arglength <com.getMinArgs())
                        {
                            e.getPlayer().sendMessage("§4Du hast zu wenig Argumente eingegeben. Bitte überprüfe deine Eingabe!");
                        }
                        else if(arglength >com.getMaxArgs())
                        {
                            e.getPlayer().sendMessage("§4Du hast zu viele Argumente eingegeben. Bitte überprüfe deine Eingabe!");
                        }
                        else
                        {
                            com.onCommandUse(p, argm);
                        }
                    }
                    else {
                        e.getPlayer().sendMessage("§4Du hast keine Permission!");
                    }
                }
            }
            else
                e.getPlayer().sendMessage("§4Dieser Befehl ist nicht registriert!");
        }   
    }
    
    My Command Class:
    Code:
    package minecrafthaifl.ban.command;
    
    import org.bukkit.entity.Player;
    
    public abstract class Command
    {
        private int minarg;
        private int maxarg;
       
        public Command(int minargs,int maxargs)
        {
            this.minarg=minargs;
            this.maxarg=maxargs;
        }
       
       
        public int getMinArgs()
        {
            return minarg;
        }
        public int getMaxArgs()
        {
            return maxarg;
        }
           
        public abstract String getPermission();
       
        //Parameter Übergabe
        public abstract void onCommandUse(Player p,String args[]);
       
        public abstract String getCommand();
       
    }
    My main Class:
    Code:
    package minecrafthaifl.ban.main;
    
    import java.io.File;
    
    import minecrafthaifl.ban.command.CommandHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Bansystem extends JavaPlugin
    {
        private static Bansystem plugin;
        private static FileConfiguration d;
        private static FileConfiguration c;
        private static File g;
        private static File f;
       
       
        public void onEnable()
        {
            plugin=this;
            f=YamlHandler.createFile("Bans.yml");
            c=YamlHandler.createYamlFile(f);
            g=YamlHandler.createFile("Player.yml");
            d=YamlHandler.createYamlFile(g);
            Bukkit.getServer().getPluginManager().registerEvents(new CommandHandler(),this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
           
        }
       
        public static Bansystem getInstance()
        {
            return plugin;
        }
        public static File getRawBanFile()
        {
            return f;
        }
        public static FileConfiguration getBanFile()
        {
            return c;
        }
        public static File getRawPlayerFile()
        {
            return g;
        }
        public static FileConfiguration getPlayerFile()
        {
            return d;
        }
    }
    
    My PlayerJoinListener:
    Code:
    package minecrafthaifl.ban.main;
    
    import java.io.File;
    
    import minecrafthaifl.ban.command.CommandHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Bansystem extends JavaPlugin
    {
        private static Bansystem plugin;
        private static FileConfiguration d;
        private static FileConfiguration c;
        private static File g;
        private static File f;
       
       
        public void onEnable()
        {
            plugin=this;
            f=YamlHandler.createFile("Bans.yml");
            c=YamlHandler.createYamlFile(f);
            g=YamlHandler.createFile("Player.yml");
            d=YamlHandler.createYamlFile(g);
            Bukkit.getServer().getPluginManager().registerEvents(new CommandHandler(),this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
           
        }
       
        public static Bansystem getInstance()
        {
            return plugin;
        }
        public static File getRawBanFile()
        {
            return f;
        }
        public static FileConfiguration getBanFile()
        {
            return c;
        }
        public static File getRawPlayerFile()
        {
            return g;
        }
        public static FileConfiguration getPlayerFile()
        {
            return d;
        }
    }
    
    My Commands:
    Ban:
    Code:
    package minecrafthaifl.ban.command;
    
    import java.util.Calendar;
    
    import minecrafthaifl.ban.main.Bansystem;
    import minecrafthaifl.ban.main.YamlHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    
    
    public class CommandBan extends Command{
    
        public CommandBan() {
            super(0, 3);
            // TODO Auto-generated constructor stub
        }
    
        @Override
        public String getPermission() {
            // TODO Auto-generated method stub
            return "ban.*";
        }
    
        @Override
        public void onCommandUse(Player p, String[] args) {
            // TODO Auto-generated method stub
            String e;
            Calendar c = Calendar.getInstance();
            FileConfiguration f = Bansystem.getBanFile();
           
            if(args.length==0)
            {
                p.sendMessage("§c Zu wenig Argumente! Denke daran: /ban <Name> [Grund] [Dauer in Tagen]");
            }
            else if(Bukkit.getPlayer(args[0])==null)
            {
                if(Bansystem.getPlayerFile().contains(args[0])){
                    e=Bansystem.getPlayerFile().getString(args[0]+".UUID");
                    if(args.length==1)
                    {
                            Bansystem.getBanFile().set(e+".Ban", true);
                            Bansystem.getBanFile().set(e+".Grund", "Der Bannhammer hat gesprochen!");
                            Bansystem.getBanFile().set(e+".Dauer", "permanent");
                            Bansystem.getBanFile().set(e+".LastPlayer", p.getName());
                            YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                            Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(e+".Grund")+"§c für §6"+Bansystem.getBanFile().get(e+".Dauer")+"§c gebannt!");
                           
                       
                    }
                    else if(args.length==2)
                    {
                        Bansystem.getBanFile().set(e+".Ban", true);
                        Bansystem.getBanFile().set(e+".Grund", args[1]);
                        Bansystem.getBanFile().set(e+".Dauer", "permanent");
                        Bansystem.getBanFile().set(e+".LastPlayer", p.getName());
                        YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                        Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(e+".Grund")+"§c für §6"+Bansystem.getBanFile().get(e+".Dauer")+"§c gebannt!");
                    }
                    else if(args.length==3)
                    {
                        Bansystem.getBanFile().set(e+".Ban", true);
                        Bansystem.getBanFile().set(e+".Grund", args[1]);
                        Bansystem.getBanFile().set(e+".Dauer", (c.getTimeInMillis())+Long.parseLong(args[2])*24*60*60*1000);
                        Bansystem.getBanFile().set(e+".LastPlayer", p.getName());
                        YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                        Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(e+".Grund")+"§c für §6"+Bansystem.getBanFile().get(e+".Dauer")+"§c gebannt!");
                       
                    }
                }
                else
                {
                    p.sendMessage("Dieser Spieler war noch nie online!");
                }
                       
            }
            else if(args.length==1)
            {
               
               
                    Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Ban", true);
                    Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund", "Der Bannhammer hat gesprochen!");
                    Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer", "permanent");
                    Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastPlayer", p.getName());
                    YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                    Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gebannt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund")+"\n§aDauer: §b"+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer")+"\n\n§9Du kannst dich auf www.venoria.de für eine Entbannung bewerben.");
                    Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund")+"§c für §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer")+"§c gebannt!");
               
            }
            else if(args.length==2)
            {
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Ban", true);
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund", args[1]);
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer", "permanent");
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastPlayer", p.getName());
                YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gebannt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund")+"\n§aDauer: §b"+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer")+"\n\n§9Du kannst dich auf www.venoria.de für eine Entbannung bewerben.");
                Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund")+"§c für §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer")+"§c gebannt!");
            }
            else if(args.length==3)
            {
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Ban", true);
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund", args[1]);
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer", (c.getTimeInMillis())+Long.parseLong(args[2])*24*60*60*1000);
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastPlayer", p.getName());
                YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gebannt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund")+"\n§aDauer: §b"+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer")+"\n\n§9Du kannst dich auf www.venoria.de für eine Entbannung bewerben.");
                Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Grund")+"§c für §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Dauer")+"§c gebannt!");
            }
           
        }
    
        @Override
        public String getCommand() {
            // TODO Auto-generated method stub
            return "/ban";
        }
    
    }
    
    Unban:
    Code:
    package minecrafthaifl.ban.command;
    
    import minecrafthaifl.ban.main.Bansystem;
    import minecrafthaifl.ban.main.YamlHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    public class CommandUnban extends Command{
    
        public CommandUnban() {
            super(0,1);
            // TODO Auto-generated constructor stub
        }
    
        @Override
        public String getPermission() {
            // TODO Auto-generated method stub
            return "unban.*";
        }
    
        @Override
        public void onCommandUse(Player p, String[] args) {
            // TODO Auto-generated method stub
            String e;
            FileConfiguration f = Bansystem.getBanFile();
            if(args.length==0)
            {
                p.sendMessage("§c Zu wenig Argumente! Denke daran: /unban <Name>");
            }
            else if(Bukkit.getPlayer(args[0])==null)
            {
                if(Bansystem.getPlayerFile().contains(args[0])){
                    e=Bansystem.getPlayerFile().getString(args[0]+".UUID");
                    if(Bansystem.getBanFile().getBoolean(e+".Ban"))
                    {
                        if(args.length==1)
                        {
                            Bansystem.getBanFile().set(e+".Ban", false);
                            YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                            p.sendMessage("§6"+args[0]+" wurde entbannt.");
                        }
                    }
                    else
                    {
                        p.sendMessage("§cDieser Spieler ist nicht gebannt!");
                    }
                }
                else
                {
                    p.sendMessage("§cDieser Spieler war noch nie online!");
                }
            }
               
            else if(args.length==1)
            {
                if(Bansystem.getBanFile().getBoolean(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Ban"))
                {
                    Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Ban", false);
                    YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                    p.sendMessage("§6"+args[0]+" wurde entbannt.");
                }
               
                else
                {
                p.sendMessage("§cDieser Spieler ist nicht gebannt!");
                }
            }
        }
    
        @Override
        public String getCommand() {
            // TODO Auto-generated method stub
            return "/unban";
        }
    
    }
    
    Kick:
    Code:
    package minecrafthaifl.ban.command;
    
    import minecrafthaifl.ban.main.Bansystem;
    import minecrafthaifl.ban.main.YamlHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    public class CommandKick extends Command
    {
    
        public CommandKick() {
            super(0, 2);
            // TODO Auto-generated constructor stub
        }
    
        @Override
        public String getPermission() {
            // TODO Auto-generated method stub
            return "kick.*";
        }
    
        @Override
        public void onCommandUse(Player p, String[] args) {
            // TODO Auto-generated method stub
            FileConfiguration f = Bansystem.getBanFile();
            if(args.length==0)
            {
                p.sendMessage("§c Zu wenig Argumente! Denke daran: /kick <Name> [Grund]");
            }
            else if(Bukkit.getPlayer(args[0])==null)
            {
                p.sendMessage("§cDieser Spieler ist nicht online!");
            }
            else if(args.length==1)
            {
                if(!Bansystem.getBanFile().getBoolean(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".KickOff"))
                {
                    Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastKickGrund", "Du wurdest gekickt!");
                    Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Kicks", Bansystem.getBanFile().getInt(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Kicks")+1);
                    YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                    Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gekickt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastKickGrund"));
                    Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastKickGrund")+"§c gekickt!");
                }
                else
                    p.sendMessage("§cDieser Spieler hat KickOff an!");
            }
            else if (args.length==2)
            {
                if(!Bansystem.getBanFile().getBoolean(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".KickOff"))
                {
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastKickGrund", args[1]);
                Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Kicks", Bansystem.getBanFile().getInt(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".Kicks")+1);
                YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                Bukkit.getPlayer(args[0]).kickPlayer("§4Du wurdest gekickt!\n§cGrund: "+Bansystem.getBanFile().getString(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastKickGrund"));
                Bukkit.broadcastMessage("§6"+args[0]+"§c wurde wegen §6"+Bansystem.getBanFile().get(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".LastKickGrund")+"§c gekickt!");
            }
            else
                p.sendMessage("§cDieser Spieler hat KickOff an!");
            }
        }
    
        @Override
        public String getCommand() {
            // TODO Auto-generated method stub
            return "/kick";
        }
    
    }
    
    KickOff:
    Code:
    package minecrafthaifl.ban.command;
    
    import minecrafthaifl.ban.main.Bansystem;
    import minecrafthaifl.ban.main.YamlHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    
    public class CommandKickoff extends Command
    {
    
        public CommandKickoff() {
            super(0, 1);
            // TODO Auto-generated constructor stub
        }
    
        @Override
        public String getPermission() {
            // TODO Auto-generated method stub
            return "kickoff.*";
        }
    
        @Override
        public void onCommandUse(Player p, String[] args) {
            // TODO Auto-generated method stub
            FileConfiguration f =  Bansystem.getBanFile();
            if(args.length==0)
            {
                if(Bansystem.getBanFile().getBoolean(p.getPlayer().getUniqueId()+".KickOff"))
                {
                    Bansystem.getBanFile().set(p.getPlayer().getUniqueId()+".KickOff", false);
                    YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                    p.sendMessage("§cKickOff ausgestellt.");
                }
                else
                {
                    Bansystem.getBanFile().set(p.getPlayer().getUniqueId()+".KickOff", true);
                    YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                    p.sendMessage("§cKickOff angestellt.");
                }
            }
            else 
            {
                if(Bukkit.getPlayer(args[0])==null)
                {
                    p.sendMessage("§cDieser Spieler ist nicht online!");
                }
                else
                {
                   
                    if(Bansystem.getBanFile().getBoolean(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".KickOff"))
                    {
                        Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".KickOff", false);
                        YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                        p.sendMessage("§cKickOff von "+args[0]+" ausgestellt.");
                    }
                    else
                    {
                        Bansystem.getBanFile().set(Bukkit.getPlayer(args[0]).getUniqueId().toString()+".KickOff", true);
                        YamlHandler.saveYamlFile(f, Bansystem.getRawBanFile());
                        p.sendMessage("§cKickOff von "+args[0]+" angestellt.");
                    }
                }
            }
        }
    
        @Override
        public String getCommand() {
            // TODO Auto-generated method stub
            return null;
        }
    
    }
    
    
    And the Error Messages:
    Code:
    [LIST=1]
    [*][15:22:37] [Server thread/INFO]: minecrafthaifl issued server command: /ban
    [*][15:22:37] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to Bansystem v1.0
    [*]org.bukkit.event.EventException
    [*]    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
    [*]    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
    [*]    at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    [*]Caused by: java.lang.NullPointerException
    [*]    at minecrafthaifl.ban.command.CommandHandler.onCommand(CommandHandler.java:47) ~[?:?]
    [*]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
    [*]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
    [*]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
    [*]    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
    [*]    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
    [*]    ... 16 more
    [*][15:22:58]
    [/LIST]
    
    I know, that I can also use f.mkdirs(); instead of dr.mkdirs();
    @I Al Istannen

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Jun 1, 2015
  22. Offline

    I Al Istannen

    @ScorixEar
    I found it. In your "KickOff" "getCommand()" returns null. Because that is the last entry in the arraylist, it gets checked in the commandHandler for loop, leading to a NPE.

    And in your "Kick" command, FIRST broadcast the message. You kick the player first and then try to get the player (now offline) for getting his kick message leading to another NPE.

    And you didn't understand me with the files. That is how it should look like:
    Code:
    File dir = new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + "files");
       
    dir.mkdirs();
       
    File f= new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + "files" + File.separator + filename);
    
    Notice the little difference in the arguments. I appended "files" to the dir. Now there will be a Directory called files. And then I create a file INSIDE this folder by appending an File.Seperator and then the name of the file. Do you understand now? :)
     
  23. Offline

    ScorixEar

    so I should use this?:
    Code:
    File f= new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + "files" + File.separator + filename);
    f.mkdirs();
    if(!f.exists())
            {
              
                try {
                    f.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
    
    @I Al Istannen
     
  24. Offline

    I Al Istannen

    @ScorixEar No. Let's have a look at my above code again.
    Code:
    // this creates a File that should be our Folder later. To do so, we give it the DataFolder as path. 
    //Then we add a Seperator and the name the Folder should have, to get the whole path.
    File dir = new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + "files");
    
    //since that will be our folder, we need to create it and all parent folder, if they don't exist
    dir.mkdirs();
       
    // now we need the actual file. Like "player.yml" or "bans.yml". 
    // They should be INSIDE the folder "files" as that is what we specified above. 
    // To let them lay in there, we need to do exactly what we done above.
    //We get the path of the folder "files" and simply add another Seperator (to be inside) and the name of the file.
    File f= new File(Bansystem.getInstance().getDataFolder().getAbsolutePath() + File.separator + "files" + File.separator + filename);
    
    // then we create the file
    f.createNewFile();
    
    But why does your's not work? Simple. You have one file object. A File object can either be a folder or a file. You make it a Folder by calling "mkdirs()". Then you try to make it a file. That can't work. You will need two file objects. One for the folder and another, inside this folder, for the file ("bans.yml" or similar).
     
  25. Offline

    ScorixEar

    Ah, Now I undestand it. Sorry ^^
    I thought a file is only a file, not a folder :D
    It works :3 only one question. The kick, ban and unban command are also mojang commands. Can I disable these Commands if this plugin is disabled?
    @I Al Istannen
     
  26. Offline

    ScorixEar

  27. Offline

    I Al Istannen

    @ScorixEar
    Sorry, I was in Amsterdam. Holidays :)
    If the plugin is disabled, you can't intercept the commands sended by players. But is this what you want?
     
  28. Offline

    Lolmewn

    Please please please make the code more OOP. Making everything static works, but is very bad practice. Instead, you should pass along the instances of the classes you're using when creating a new class.

    Anyway, I also noticed you forgot an @EventHandler.
    Also note: If you want to create a file, it's safe to first to file.getParentFile().mkdirs() - this way you're sure the directory you're making the file in exists.
     
    I Al Istannen likes this.
  29. Offline

    ScorixEar

    @Lolmewn Where I forgott it?
    @I Al Istannen No, if i use the /ban command, the the target player's config from my plugin change (that is good ^^) and the name stands now on the banned-players.json (I don't want this)

    I changed it ;)
     
  30. Offline

    I Al Istannen

    @ScorixEar You must cancel the PlayerCommandPreprocessEvent after you detected your command. This way no other plugin (and the server) will recieve the command (except their EventPriority is higher, I think).
     
Thread Status:
Not open for further replies.

Share This Page