2013-07-30 23:56:59 +02:00
|
|
|
package StevenDimDoors.mod_pocketDim.commands;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
|
|
|
|
import StevenDimDoors.mod_pocketDim.BlankTeleporter;
|
2013-08-29 08:14:24 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
2013-07-30 23:56:59 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
|
|
|
|
|
|
|
|
public class CommandTeleportPlayer extends DDCommandBase
|
|
|
|
{
|
|
|
|
private static CommandTeleportPlayer instance = null;
|
|
|
|
|
|
|
|
private CommandTeleportPlayer()
|
|
|
|
{
|
|
|
|
super("dd-tp", new String[] {"<Player Name> <Dimension ID> <X Coord> <Y Coord> <Z Coord>"} );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CommandTeleportPlayer instance()
|
|
|
|
{
|
|
|
|
if (instance == null)
|
|
|
|
{
|
|
|
|
instance = new CommandTeleportPlayer();
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO- Change to accept variety of input, like just coords, just dim ID, or two player names.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
List dimensionIDs = Arrays.asList(PocketManager.getStaticDimensionIDs()); //Gets list of all registered dimensions, regardless if loaded or not
|
2013-07-30 23:56:59 +02:00
|
|
|
EntityPlayer targetPlayer = sender;
|
|
|
|
int dimDestinationID = sender.worldObj.provider.dimensionId;
|
|
|
|
|
|
|
|
if(command.length == 5)
|
|
|
|
{
|
|
|
|
for(int i= 1; i <5;i++)
|
|
|
|
{
|
|
|
|
if(!isInteger(command[i]))
|
|
|
|
{
|
|
|
|
return DDCommandResult.INVALID_ARGUMENTS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player
|
|
|
|
{
|
|
|
|
targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return DDCommandResult.INVALID_ARGUMENTS;
|
|
|
|
}
|
|
|
|
dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string
|
|
|
|
|
|
|
|
if(!dimensionIDs.contains(dimDestinationID))
|
|
|
|
{
|
|
|
|
return DDCommandResult.INVALID_DIMENSION_ID;
|
|
|
|
}
|
2013-08-29 08:14:24 +02:00
|
|
|
if(PocketManager.getWorld(dimDestinationID)==null)
|
2013-07-30 23:56:59 +02:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
PocketManager.initDimension(dimDestinationID);
|
2013-07-30 23:56:59 +02:00
|
|
|
}
|
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().transferPlayerToDimension((EntityPlayerMP) targetPlayer, dimDestinationID, new BlankTeleporter(PocketManager.getWorld(dimDestinationID)));
|
2013-07-30 23:56:59 +02:00
|
|
|
targetPlayer.setPositionAndUpdate(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return DDCommandResult.INVALID_ARGUMENTS;
|
|
|
|
}
|
|
|
|
return DDCommandResult.SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInteger( String input )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Integer.parseInt( input );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(Exception e )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|