Fixed various teleportation issues

Added support to any dimension in /space command
Fixed player falling to their death /space command
Fixed flying players loosing flight after teleportation
This commit is contained in:
LemADEC 2015-08-29 15:02:34 +02:00
parent de7f344eed
commit 5aecdc08d2
4 changed files with 123 additions and 37 deletions

View file

@ -172,6 +172,7 @@ public class SpaceEventHandler {
new SpaceTeleporter(DimensionManager.getWorld(WarpDriveConfig.G_SPACE_DIMENSION_ID), 0, x, 250, z));
player.setFire(30);
player.setPositionAndUpdate(entity.posX, 250.0D, entity.posZ);
player.sendPlayerAbilities();
}
} else {// (in space, no air block and not a player)
entity_airBlock.put(entity.getEntityId(), 0);

View file

@ -5,8 +5,8 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.command.ICommandSender;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
@ -943,10 +943,10 @@ public class WarpDrive implements LoadingCallback {
}
}
public static void addChatMessage(final EntityPlayer player, final String message) {
public static void addChatMessage(final ICommandSender sender, final String message) {
String[] lines = message.split("\n");
for (String line : lines) {
player.addChatMessage(new ChatComponentText(line));
sender.addChatMessage(new ChatComponentText(line));
}
}
@Mod.EventHandler

View file

@ -434,8 +434,6 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
private void summonPlayer(EntityPlayerMP player, int x, int y, int z) {
if (consumeEnergy(WarpDriveConfig.SHIP_TELEPORT_ENERGY_PER_ENTITY, false)) {
player.setPositionAndUpdate(x, y, z);
if (player.dimension != worldObj.provider.dimensionId) {
player.mcServer.getConfigurationManager().transferPlayerToDimension(
player,
@ -444,6 +442,10 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
DimensionManager.getWorld(worldObj.provider.dimensionId),
0,
MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ)));
player.setPositionAndUpdate(x, y, z);
player.sendPlayerAbilities();
} else {
player.setPositionAndUpdate(x, y, z);
}
}
}
@ -897,6 +899,7 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
}
((EntityPlayerMP) entity).setPositionAndUpdate(x + 0.5D, newY + 2.0D, z + 0.5D);
((EntityPlayerMP) entity).sendPlayerAbilities();
}
}
}

View file

@ -18,50 +18,132 @@ public class CommandSpace extends CommandBase {
public int getRequiredPermissionLevel() {
return 2;
}
@Override
public String getCommandName() {
return "space";
}
@Override
public void processCommand(ICommandSender icommandsender, String[] astring) {
EntityPlayerMP player = null;
public void processCommand(ICommandSender sender, String[] args) {
MinecraftServer server = MinecraftServer.getServer();
int targetDim = WarpDriveConfig.G_SPACE_DIMENSION_ID;
if (icommandsender != null && icommandsender instanceof EntityPlayerMP) {
player = (EntityPlayerMP) icommandsender;
// set defaults
int targetDimensionId = Integer.MAX_VALUE;
EntityPlayerMP player = null;
if (sender != null && sender instanceof EntityPlayerMP) {
player = (EntityPlayerMP) sender;
}
if (astring.length >= 1) {
if ("hyper".equals(astring[0])) {
targetDim = WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID;
} else if ("overworld".equals(astring[0])) {
targetDim = 0;
} else {
// get an online player by name
List<EntityPlayer> onlinePlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer onlinePlayer : onlinePlayers) {
if (onlinePlayer.getCommandSenderName().equalsIgnoreCase(astring[0]) && onlinePlayer instanceof EntityPlayerMP) {
player = (EntityPlayerMP) onlinePlayer;
}
}
// parse arguments
if (args.length == 0) {
// nop
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
WarpDrive.addChatMessage(sender, getCommandUsage(sender));
return;
}
}
if (player == null) {
WarpDrive.logger.info("/space: undefined player");
EntityPlayerMP playerFound = getOnlinePlayerByName(args[0]);
if (playerFound != null) {
player = playerFound;
} else {
targetDimensionId = getDimensionId(args[0]);
}
} else if (args.length == 2) {
player = getOnlinePlayerByName(args[0]);
targetDimensionId = getDimensionId(args[1]);
} else {
WarpDrive.addChatMessage(sender, "/space: too many arguments " + args.length);
return;
}
WorldServer targetWorld = server.worldServerForDimension(targetDim);
WarpDrive.logger.info("/space: teleporting player " + player.getCommandSenderName() + " to " + targetDim + ":" + targetWorld.getWorldInfo().getWorldName());
SpaceTeleporter teleporter = new SpaceTeleporter(targetWorld, 0, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ));
server.getConfigurationManager().transferPlayerToDimension(player, targetDim, teleporter);
// check player
if (player == null) {
WarpDrive.addChatMessage(sender, "/space: undefined player");
return;
}
// toggle between overworld and space if no dimension was providen
if (targetDimensionId == Integer.MAX_VALUE) {
if (player.worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID) {
targetDimensionId = 0;
} else {
targetDimensionId = WarpDriveConfig.G_SPACE_DIMENSION_ID;
}
}
// get target world
WorldServer targetWorld = server.worldServerForDimension(targetDimensionId);
if (targetWorld == null) {
WarpDrive.addChatMessage(sender, "/space: undefined dimension " + targetDimensionId);
return;
}
// inform player
String message = "Teleporting player " + player.getCommandSenderName() + " to dimension " + targetDimensionId + "..."; // + ":" + targetWorld.getWorldInfo().getWorldName();
WarpDrive.addChatMessage(sender, message);
WarpDrive.logger.info(message);
if (sender != player) {
WarpDrive.addChatMessage(player, sender + " is teleporting you to dimension " + targetDimensionId); // + ":" + targetWorld.getWorldInfo().getWorldName());
}
// find a good spot
int newX = MathHelper.floor_double(player.posX);
int newY = Math.min(255, Math.max(0, MathHelper.floor_double(player.posY)));
int newZ = MathHelper.floor_double(player.posZ);
if ( (targetWorld.isAirBlock(newX, newY - 1, newZ) && !player.capabilities.allowFlying)
|| !targetWorld.isAirBlock(newX, newY, newZ)
|| !targetWorld.isAirBlock(newX, newY + 1, newZ)) {// non solid ground and can't fly, or inside blocks
newY = targetWorld.getTopSolidOrLiquidBlock(newX, newZ) + 1;
if (newY == 0) {
newY = 128;
}
}
SpaceTeleporter teleporter = new SpaceTeleporter(targetWorld, 0, newX, newY, newZ);
server.getConfigurationManager().transferPlayerToDimension(player, targetDimensionId, teleporter);
player.setPositionAndUpdate(newX + 0.5D, newY + 0.05D, newZ + 0.5D);
player.sendPlayerAbilities();
}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return "/space [hyper|overworld|<player>]";
return "/space (<playerName>) ([overworld|nether|end|theend|space|hyper|hyperspace|<dimensionId>])";
}
private EntityPlayerMP getOnlinePlayerByName(final String playerName) {
List<EntityPlayer> onlinePlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer onlinePlayer : onlinePlayers) {
if (onlinePlayer.getCommandSenderName().equalsIgnoreCase(playerName) && onlinePlayer instanceof EntityPlayerMP) {
return (EntityPlayerMP) onlinePlayer;
}
}
return null;
}
private int getDimensionId(String stringDimension) {
if (stringDimension.equalsIgnoreCase("overworld")) {
return 0;
} else if (stringDimension.equalsIgnoreCase("nether")) {
return -1;
} else if (stringDimension.equalsIgnoreCase("end") || stringDimension.equalsIgnoreCase("theend")) {
return 1;
} else if (stringDimension.equalsIgnoreCase("space")) {
return WarpDriveConfig.G_SPACE_DIMENSION_ID;
} else if (stringDimension.equalsIgnoreCase("hyper") || stringDimension.equalsIgnoreCase("hyperspace")) {
return WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID;
}
try {
return Integer.parseInt(stringDimension);
} catch(Exception exception) {
// exception.printStackTrace();
WarpDrive.logger.info("/space: invalid dimension '" + stringDimension + "', expecting integer or overworld/nether/end/theend/space/hyper/hyperspace");
}
return 0;
}
}