Search in sources :

Example 16 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class RefreshColonyCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
    Colony colony = actionMenu.getColonyForArgument("colony");
    if (null == colony) {
        final EntityPlayer player = actionMenu.getPlayerForArgument("player");
        if (null != player) {
            IColony iColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
            if (null == iColony) {
                if (sender instanceof EntityPlayer) {
                    final Entity senderEntity = sender.getCommandSenderEntity();
                    if (senderEntity != null) {
                        final UUID mayorID = senderEntity.getUniqueID();
                        iColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
                    }
                }
            }
            if (null != iColony) {
                colony = ColonyManager.getColony(iColony.getID());
            }
        }
    }
    if (colony == null) {
        sender.sendMessage(new TextComponentString(NO_COLONY_FOUND_MESSAGE));
        return;
    }
    executeShared(server, sender, colony);
}
Also used : Entity(net.minecraft.entity.Entity) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 17 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class RefreshColonyCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    final int colonyId;
    colonyId = getIthArgument(args, 0, -1);
    IColony tempColony = ColonyManager.getColony(colonyId);
    if (colonyId == -1 && args.length >= 1) {
        final EntityPlayer player = server.getEntityWorld().getPlayerEntityByName(args[0]);
        if (player != null) {
            tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
        }
    }
    if (sender instanceof EntityPlayer) {
        final Entity senderEntity = sender.getCommandSenderEntity();
        if (senderEntity == null) {
            return;
        }
        final UUID mayorID = senderEntity.getUniqueID();
        if (tempColony == null) {
            tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
        }
    }
    if (tempColony == null) {
        if (colonyId == -1 && args.length != 0) {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_PLAYER_FOUND_MESSAGE, args[0])));
        } else {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_ID_FOUND_MESSAGE, colonyId)));
        }
        return;
    }
    final Colony colony = ColonyManager.getColony(tempColony.getID());
    if (colony == null) {
        sender.sendMessage(new TextComponentString(NO_COLONY_FOUND_MESSAGE));
        return;
    }
    executeShared(server, sender, colony);
}
Also used : Entity(net.minecraft.entity.Entity) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 18 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class AbstractCitizensCommands method execute.

@NotNull
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    if (args.length == 0) {
        sender.sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    boolean firstArgumentColonyId = true;
    int colonyId = -1;
    if (args.length >= 2) {
        colonyId = getIthArgument(args, 0, -1);
        if (colonyId == -1) {
            final EntityPlayer player = server.getEntityWorld().getPlayerEntityByName(args[0]);
            if (player != null) {
                final IColony tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
                if (tempColony != null) {
                    colonyId = tempColony.getID();
                }
            }
            firstArgumentColonyId = false;
        }
    }
    final Colony colony;
    if (sender instanceof EntityPlayer && colonyId == -1) {
        final IColony tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
        if (tempColony != null) {
            colonyId = tempColony.getID();
            firstArgumentColonyId = false;
        }
    }
    colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    if (sender instanceof EntityPlayer) {
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, getCommand(), colonyId)) {
            player.sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    final int citizenId = getValidCitizenId(colony, firstArgumentColonyId, args);
    if (citizenId == -1 || colony.getCitizenManager().getCitizen(citizenId) == null) {
        sender.sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    executeSpecializedCode(server, sender, colony, citizenId);
}
Also used : 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) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class ListCitizensCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    int colonyId = getIthArgument(args, 0, getColonyId(sender));
    final Integer page = getIthArgument(args, 1, 1);
    Colony colony = null;
    if (sender instanceof EntityPlayer) {
        if (colonyId == -1) {
            final IColony icolony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
            if (icolony != null) {
                colonyId = icolony.getID();
            }
        }
    }
    colony = ColonyManager.getColony(colonyId);
    executeShared(server, sender, colony, page);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony)

Example 20 with IColony

use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.

the class AddOfficerCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    if (args.length == 0) {
        sender.sendMessage(new TextComponentString(NO_COLONY_OR_PLAYER));
        return;
    }
    final Entity senderEntity = sender.getCommandSenderEntity();
    int colonyId = getIthArgument(args, 0, -1);
    if (colonyId == -1 && senderEntity instanceof EntityPlayer) {
        final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), ((EntityPlayer) sender).getUniqueID());
        if (colony == null) {
            senderEntity.sendMessage(new TextComponentString(COLONY_X_NULL));
            return;
        }
        colonyId = colony.getID();
    }
    final Colony colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.sendMessage(new TextComponentString(String.format(COLONY_X_NULL, colonyId)));
        return;
    }
    String playerName = null;
    if (args.length >= 2) {
        playerName = args[1];
    }
    if (playerName == null || playerName.isEmpty()) {
        playerName = sender.getName();
    }
    executeShared(server, sender, colony, playerName);
}
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)

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