Search in sources :

Example 6 with IColony

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

the class EventHandler method onWareHousePlaced.

private static boolean onWareHousePlaced(final World world, final EntityPlayer player, final BlockPos pos) {
    if (onBlockHutPlaced(world, player, pos)) {
        final IColony colony = ColonyManager.getIColonyByOwner(world, player);
        if (colony != null && (!Configurations.limitToOneWareHousePerColony || !colony.hasWarehouse())) {
            return true;
        }
        LanguageHandler.sendPlayerMessage(player, "tile.blockHut.warehouse.limit");
    }
    return false;
}
Also used : IColony(com.minecolonies.coremod.colony.IColony)

Example 7 with IColony

use of com.minecolonies.coremod.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;
    //see if sent by a player and grab their name and Get the players Colony ID that sent the command
    if (sender 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);
            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.getCommandSenderEntity().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.teleportBuffer + " seconds to teleport again"));
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with IColony

use of com.minecolonies.coremod.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.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    if (!isPlayerOpped(sender)) {
        return;
    }
    int colonyId = getIthArgument(args, 0, -1);
    if (colonyId == -1) {
        final String playerName = args[0];
        if (playerName == null || playerName.isEmpty()) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_PLAYER));
            return;
        }
        final EntityPlayer player = sender.getEntityWorld().getPlayerEntityByName(playerName);
        final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player.getUniqueID());
        colonyId = colony.getID();
    }
    final Colony colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.sendMessage(new TextComponentString(String.format(COLONY_NULL, colonyId)));
        return;
    }
    String playerName = null;
    if (args.length >= 2) {
        playerName = args[1];
    }
    if (playerName == null || playerName.isEmpty()) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_PLAYER));
        return;
    }
    final EntityPlayer player = sender.getEntityWorld().getPlayerEntityByName(playerName);
    if (player == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_PLAYER));
        return;
    }
    if (ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player) != null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(String.format(HAS_A_COLONY, playerName)));
        return;
    }
    colony.getPermissions().setOwner(player);
    sender.sendMessage(new TextComponentString(String.format(SUCCESS_MESSAGE, playerName, colonyId)));
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 9 with IColony

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

the class DeleteColonyCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    final int colonyId;
    if (args.length == 0) {
        IColony colony = null;
        if (sender instanceof EntityPlayer) {
            colony = ColonyManager.getIColonyByOwner(((EntityPlayer) sender).world, (EntityPlayer) sender);
        }
        if (colony == null) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
            return;
        }
        colonyId = colony.getID();
    } else {
        colonyId = getIthArgument(args, 0, -1);
    }
    final Colony colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_COLONY_FOUND_MESSAGE_ID));
        return;
    }
    if (sender instanceof EntityPlayer) {
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, DELETECOLONY, colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    server.addScheduledTask(() -> ColonyManager.deleteColony(colony.getID()));
}
Also used : IColony(com.minecolonies.coremod.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 10 with IColony

use of com.minecolonies.coremod.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 {
    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 UUID mayorID = sender.getCommandSenderEntity().getUniqueID();
        if (tempColony == null) {
            tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
        }
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, Commands.REFRESH_COLONY, colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    if (tempColony == null) {
        if (colonyId == -1 && args.length != 0) {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE, args[0])));
        } else {
            sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE_ID, colonyId)));
        }
        return;
    }
    final Colony colony = ColonyManager.getColony(tempColony.getID());
    if (colony == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_COLONY_FOUND_MESSAGE_ID));
        return;
    }
    sender.getCommandSenderEntity().sendMessage(new TextComponentString(REFRESH));
    colony.getPermissions().restoreOwnerIfNull();
}
Also used : IColony(com.minecolonies.coremod.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

IColony (com.minecolonies.coremod.colony.IColony)13 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 TextComponentString (net.minecraft.util.text.TextComponentString)9 Colony (com.minecolonies.coremod.colony.Colony)8 NotNull (org.jetbrains.annotations.NotNull)3 UUID (java.util.UUID)2 BlockPos (net.minecraft.util.math.BlockPos)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 ArrayList (java.util.ArrayList)1 BlockSilverfish (net.minecraft.block.BlockSilverfish)1 Minecraft (net.minecraft.client.Minecraft)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 Style (net.minecraft.util.text.Style)1 ClickEvent (net.minecraft.util.text.event.ClickEvent)1 World (net.minecraft.world.World)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1