use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class ChangeColonyOwnerCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
if (args.length < 2) {
sender.sendMessage(new TextComponentString(NO_COLONY_OR_PLAYER));
return;
}
int colonyId = getIthArgument(args, 0, -1);
if (colonyId == -1) {
final String playerName = args[0];
final EntityPlayer player = sender.getEntityWorld().getPlayerEntityByName(playerName);
final Entity senderEntity = sender.getCommandSenderEntity();
if (senderEntity == null) {
server.sendMessage(new TextComponentString(NO_COLONY_OR_PLAYER));
return;
} else {
if (playerName == null || playerName.isEmpty() || player == null) {
senderEntity.sendMessage(new TextComponentString(NO_PLAYER));
return;
}
final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player.getUniqueID());
if (colony == null) {
return;
}
colonyId = colony.getID();
}
}
String playerName = null;
if (args.length >= 2) {
playerName = args[1];
}
final Colony colony = ColonyManager.getColony(colonyId);
if (colony == null) {
sender.sendMessage(new TextComponentString(String.format(COLONY_X_NULL, colonyId)));
return;
}
if (playerName == null || playerName.isEmpty()) {
sender.sendMessage(new TextComponentString(NO_PLAYER));
return;
}
final EntityPlayer player = sender.getEntityWorld().getPlayerEntityByName(playerName);
executeShared(server, sender, colony, player);
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class TeleportToColony method colonyTeleport.
/**
* colonyTeleport is used with Home and Colony to teleport people to either
* there home. or to another colony, when you specified a colonyID.
*
* @param server the server instance.
* @param sender the player that is initiating the command.
* @param args this is the colony ID that the player wishes to TP to.
*/
@NotNull
public static void colonyTeleport(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) {
final EntityPlayer playerToTeleport;
final IColony colony;
final int colonyId;
final Entity senderEntity = sender.getCommandSenderEntity();
// see if sent by a player and grab their name and Get the players Colony ID that sent the command
if (senderEntity instanceof EntityPlayer) {
// if no args then this is a home colony TP and we get the players Colony ID
if (args.length == 0) {
playerToTeleport = (EntityPlayer) sender;
colony = ColonyManager.getIColonyByOwner(((EntityPlayer) sender).world, (EntityPlayer) sender);
if (colony == null) {
return;
}
colonyId = colony.getID();
} else {
// if there is args then this will be to a friends colony TP and we use the Colony ID they specify
// will need to see if they friendly to destination colony
playerToTeleport = (EntityPlayer) sender;
colonyId = Integer.valueOf(args[0]);
}
} else {
sender.sendMessage(new TextComponentString(CANT_FIND_PLAYER));
return;
}
if (MinecoloniesCommand.canExecuteCommand((EntityPlayer) sender)) {
teleportPlayer(playerToTeleport, colonyId, sender);
return;
}
sender.getCommandSenderEntity().sendMessage(new TextComponentString("Please wait at least " + Configurations.gameplay.teleportBuffer + " seconds to teleport again"));
}
Aggregations