Jump to content

[1.7.10] Server Commands Crash


robyrho

Recommended Posts

Hi,

I'm trying to develop a server-side mod that add some basic command to forge basic server(without cauldron).

I don't know why but the server crash without reason, only this string:

[FML]: Fatal errors were detected during the transition from SERVER_ABOUT_TO_START to SERVER_STARTING. Loading cannot continue

Here are my classes:

 

Main

package net.robyrho.cdacommands;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import net.robyrho.cdacommands.commands.HomeCommand;
import net.robyrho.cdacommands.commands.SetHomeCommand;
import net.robyrho.cdacommands.commands.SetSpawnCommand;
import net.robyrho.cdacommands.commands.SpawnCommand;
import net.robyrho.cdacommands.commands.TPACommand;
import net.robyrho.cdacommands.commands.TPAcceptCommand;
import net.robyrho.cdacommands.handlers.ServerProxy;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.relauncher.FMLInjectionData;

@Mod(modid = "cdacommands", version = "1.7.10-1.0")
public class CdACommands {

          //Proxy are blank classes, I'll not post them
@SidedProxy(serverSide = "net.robyrho.cdacommands.handlers.ServerProxy", clientSide = "net.robyrho.cdacommands.handlers.ClientProxy")
public static ServerProxy proxy;

private static String basePath;
private static File locationsFile;

@EventHandler
public void preInit(FMLPreInitializationEvent e) {
	basePath = ((File)(FMLInjectionData.data()[6])).getAbsolutePath().replace(File.separatorChar, '/').replace("/.", "") + File.separator + "mods" + File.separator + "CdACommands";
	File baseDir = new File(basePath);
	if(!baseDir.exists()) {
		baseDir.mkdirs();
		locationsFile = new File(basePath + File.separator + "Locations.json");
		if(!locationsFile.exists()) {
			try {
				locationsFile.createNewFile();
			} catch(IOException ex) {
				System.err.append(ex.getMessage());
			}
			try {
				FileWriter wr = new FileWriter(locationsFile);
				wr.write("{\n}");
				wr.flush();
				wr.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	} else {
		locationsFile = new File(basePath + File.separator + "Locations.json");
		if(!locationsFile.exists()) {
			try {
				locationsFile.createNewFile();
			} catch(IOException ex) {
				System.err.append(ex.getMessage());
			}
			try {
				FileWriter wr = new FileWriter(locationsFile);
				wr.write("{\n}");
				wr.flush();
				wr.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	}
}

@EventHandler
public void init(FMLInitializationEvent e) {

}

@EventHandler
public void serverInit(FMLServerStartingEvent e) {
	e.registerServerCommand(new SetSpawnCommand());
	e.registerServerCommand(new SpawnCommand());
	e.registerServerCommand(new TPACommand());
	e.registerServerCommand(new TPAcceptCommand());
	e.registerServerCommand(new SetHomeCommand());
	e.registerServerCommand(new HomeCommand());
}

public static File getLocationsFile() {
	return locationsFile;
}
}

 

SetSpawnCommand:

package net.robyrho.cdacommands.commands;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.robyrho.cdacommands.CdACommands;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import scala.actors.threadpool.Arrays;

public class SetSpawnCommand implements ICommand {

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "setspawn";
}

@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
	return "/setspawn";
}

@Override
public List getCommandAliases() {
	return null;
}

@SuppressWarnings("null")
@Override
public void processCommand(ICommandSender sender, String[] args) {
	JSONParser parser = new JSONParser();
	EntityPlayerMP p = (EntityPlayerMP) sender;
	if(!Arrays.asList(MinecraftServer.getServer().getConfigurationManager().func_152606_n()).contains(p.getDisplayName())) {
		IChatComponent argsErr = null;
		argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
		argsErr.appendText("Non hai i permessi per eseguire questo comando");
		p.addChatMessage(argsErr);
		return;
	}

	if(args.length == 0) {
		try {
			Object obj = parser.parse(new FileReader(CdACommands.getLocationsFile()));
			JSONObject jsonObject = (JSONObject) obj;

			jsonObject.put("Spawn", p.posX + ";" + p.posY + ";" + p.posZ + ";" + p.cameraYaw + ";" + p.cameraPitch);
			try {
				FileWriter writer = new FileWriter(CdACommands.getLocationsFile());
				writer.write(jsonObject.toJSONString());
				writer.flush();
				writer.close();
			} catch(IOException ex) {
				ex.printStackTrace();
			}
			IChatComponent mess = null;
			mess = mess.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_GREEN));
			mess.appendText("Punto di spawn impostato corretamente");
			p.addChatMessage(mess);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}

	} else {
		IChatComponent argsErr = null;
		argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
		argsErr.appendText("Usa " + getCommandUsage(sender));
		p.addChatMessage(argsErr);
	}
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
	if(sender instanceof EntityPlayerMP) {
		return true;
	}
	return false;
}

@Override
public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
	return false;
}

}

 

SpawnCommand

package net.robyrho.cdacommands.commands;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.robyrho.cdacommands.CdACommands;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class SpawnCommand implements ICommand {

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "spawn";
}

@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
	return "/spawn";
}

@Override
public List getCommandAliases() {
	return null;
}

@SuppressWarnings("null")
@Override
public void processCommand(ICommandSender sender, String[] args) {
	JSONParser parser = new JSONParser();
	EntityPlayerMP p = (EntityPlayerMP) sender;

	try {
		Object obj = parser.parse(new FileReader(CdACommands.getLocationsFile()));
		JSONObject jsonObject = (JSONObject) obj;

		if(jsonObject.containsKey("Spawn")) {
			String s = (String) jsonObject.get("Spawn");
			String[] sList = s.split(";");
			try {
			p.setPositionAndRotation(Double.parseDouble(sList[0]), Double.parseDouble(sList[1]), Double.parseDouble(sList[2]), Float.parseFloat(sList[3]), Float.parseFloat(sList[4]));
			} catch(NumberFormatException ex) {
				IChatComponent argsErr = null;
				argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
				argsErr.appendText("Qualcosa non ha funzionato nella lettura delle coordinate, contatta un OP!");
				p.addChatMessage(argsErr);
			}
		}
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	} catch (ParseException e) {
		e.printStackTrace();
	}
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
	if(sender instanceof EntityPlayerMP) {
		return true;
	}
	return false;
}

@Override
public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
	return false;
}

}

 

SetHomeCommand

package net.robyrho.cdacommands.commands;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import scala.actors.threadpool.Arrays;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.robyrho.cdacommands.CdACommands;

public class SetHomeCommand implements ICommand {

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "sethome";
}

@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
	return "/sethome";
}

@Override
public List getCommandAliases() {
	return null;
}

@SuppressWarnings("null")
@Override
public void processCommand(ICommandSender sender, String[] args) {
	JSONParser parser = new JSONParser();
	EntityPlayerMP p = (EntityPlayerMP) sender;

	if(args.length == 0) {
		try {
			Object obj = parser.parse(new FileReader(CdACommands.getLocationsFile()));
			JSONObject jsonObject = (JSONObject) obj;

			jsonObject.put(p.getDisplayName(), p.posX + ";" + p.posY + ";" + p.posZ + ";" + p.cameraYaw + ";" + p.cameraPitch);
			try {
				FileWriter writer = new FileWriter(CdACommands.getLocationsFile());
				writer.write(jsonObject.toJSONString());
				writer.flush();
				writer.close();
			} catch(IOException ex) {
				ex.printStackTrace();
			}
			IChatComponent mess = null;
			mess = mess.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_GREEN));
			mess.appendText("Benvenuto a casa!");
			p.addChatMessage(mess);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}

	} else {
		IChatComponent argsErr = null;
		argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
		argsErr.appendText("Usa " + getCommandUsage(sender));
		p.addChatMessage(argsErr);
	}
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
	if(sender instanceof EntityPlayerMP) {
		return true;
	}
	return false;
}

@Override
public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
	return false;
}

}

 

HomeCommand

package net.robyrho.cdacommands.commands;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.robyrho.cdacommands.CdACommands;

public class HomeCommand implements ICommand {

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "home";
}

@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
	return "/home";
}

@Override
public List getCommandAliases() {
	return null;
}

@SuppressWarnings("null")
@Override
public void processCommand(ICommandSender sender, String[] args) {
	JSONParser parser = new JSONParser();
	EntityPlayerMP p = (EntityPlayerMP) sender;

	try {
		Object obj = parser.parse(new FileReader(CdACommands.getLocationsFile()));
		JSONObject jsonObject = (JSONObject) obj;

		if(jsonObject.containsKey(p.getDisplayName())) {
			String s = (String) jsonObject.get(p.getDisplayName());
			String[] sList = s.split(";");
			try {
			p.setPositionAndRotation(Double.parseDouble(sList[0]), Double.parseDouble(sList[1]), Double.parseDouble(sList[2]), Float.parseFloat(sList[3]), Float.parseFloat(sList[4]));
			} catch(NumberFormatException ex) {
				IChatComponent argsErr = null;
				argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
				argsErr.appendText("Qualcosa non ha funzionato nella lettura delle coordinate, contatta un OP!");
				p.addChatMessage(argsErr);
			}
		}
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	} catch (ParseException e) {
		e.printStackTrace();
	}
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
	if(sender instanceof EntityPlayerMP) {
		return true;
	}
	return false;
}

@Override
public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
	return false;
}

}

 

TPACommand

package net.robyrho.cdacommands.commands;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.WorldServer;

public class TPACommand implements ICommand {
public static HashMap<EntityPlayerMP, List<EntityPlayerMP>> requests = new HashMap<EntityPlayerMP, List<EntityPlayerMP>>();

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "tpa";
}

@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
	return "/tpa <player>";
}

@Override
public List getCommandAliases() {
	return null;
}

@SuppressWarnings("null")
@Override
public void processCommand(ICommandSender sender, String[] args) {
	final EntityPlayerMP p = (EntityPlayerMP) sender;
	if(args.length == 1) {
		String[] pList = MinecraftServer.getServer().getAllUsernames();
		if(Arrays.asList(pList).contains(args[0])) {
			WorldServer[] ws= MinecraftServer.getServer().worldServers;
			for(WorldServer w : ws) {
				if(w.playerEntities.contains(w.getPlayerEntityByName(args[0]))) {
					final EntityPlayerMP pt = (EntityPlayerMP) w.getPlayerEntityByName(args[0]);
					List<EntityPlayerMP> l = requests.get(pt);
					l.add(p);
					requests.put(pt, l);
					IChatComponent argsErr = null;
					argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GOLD));
					argsErr.appendText("Hai ricevuto una richiesta di teletrasporto da " + p.getDisplayName() + ". Scrivi /tpaccept entro 15 secondi per accettarla.");
					pt.addChatMessage(argsErr);
					Timer t = new Timer();
					t.schedule(new TimerTask(){
						@Override
						public void run() {
							List<EntityPlayerMP> l = requests.get(pt);
							l.remove(p);
							requests.put(pt, l);
						}
					}, 15000L);
				}
			}
		} else {
			IChatComponent argsErr = null;
			argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
			argsErr.appendText("Il giocatore " + args[0] + " non è online");
			p.addChatMessage(argsErr);
		}
	} else {
		IChatComponent argsErr = null;
		argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
		argsErr.appendText("Usa " + getCommandUsage(sender));
		p.addChatMessage(argsErr);
	}
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
	if(sender instanceof EntityPlayerMP) {
		return true;
	}
	return false;
}

@Override
public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
	return false;
}

}

 

TPAcceptCommand

package net.robyrho.cdacommands.commands;

import java.util.List;

import scala.actors.threadpool.Arrays;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.WorldServer;

public class TPAcceptCommand implements ICommand {

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "tpaccept";
}

@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
	return "/tpaccept";
}

@Override
public List getCommandAliases() {
	return null;
}

@SuppressWarnings("null")
@Override
public void processCommand(ICommandSender sender, String[] args) {
	EntityPlayerMP p = (EntityPlayerMP) sender;
	if(args.length == 0) {
		if(TPACommand.requests.containsKey(p)) {
			List<EntityPlayerMP> pl = TPACommand.requests.get(p);
			for(EntityPlayerMP pf : pl) {
			pf.setPosition(p.posX, p.posY, p.posZ);
			}
			TPACommand.requests.remove(p);
		} else {
			IChatComponent argsErr = null;
			argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
			argsErr.appendText("Non hai nessuna richiesta di teletrasporto!");
			p.addChatMessage(argsErr);
		}
	} else {
		IChatComponent argsErr = null;
		argsErr = argsErr.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED));
		argsErr.appendText("Usa " + getCommandUsage(sender));
		p.addChatMessage(argsErr);
	}
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
	if(sender instanceof EntityPlayerMP) {
		return true;
	}
	return false;
}

@Override
public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
	return false;
}

}

 

Please guys, only a little suggestion for me.

Thank you

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.