Search in sources :

Example 21 with IColony

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);
}
Also used : Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 22 with IColony

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"));
}
Also used : Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IColony (com.minecolonies.api.colony.IColony)22 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 TextComponentString (net.minecraft.util.text.TextComponentString)14 Colony (com.minecolonies.coremod.colony.Colony)12 Entity (net.minecraft.entity.Entity)7 UUID (java.util.UUID)5 Player (com.minecolonies.api.colony.permissions.Player)2 ColonyView (com.minecolonies.coremod.colony.ColonyView)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 NotNull (org.jetbrains.annotations.NotNull)2 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 BuildingBasedRequester (com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester)1 TeleportToColony (com.minecolonies.coremod.util.TeleportToColony)1 GameProfile (com.mojang.authlib.GameProfile)1 BlockSilverfish (net.minecraft.block.BlockSilverfish)1