Search in sources :

Example 76 with Colony

use of com.minecolonies.coremod.colony.Colony 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)

Example 77 with Colony

use of com.minecolonies.coremod.colony.Colony 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 78 with Colony

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

the class ChangeColonyOwnerCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
    final Colony colony = actionMenu.getColonyForArgument("colony");
    final EntityPlayer player = actionMenu.getPlayerForArgument("player");
    executeShared(server, sender, colony, player);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 79 with Colony

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

the class ColonyPermissionEventHandler method on.

/**
 * ExplosionEvent.Detonate handler.
 *
 * @param event ExplosionEvent.Detonate
 */
@SubscribeEvent
public void on(final ExplosionEvent.Detonate event) {
    if (!Configurations.gameplay.enableColonyProtection || !Configurations.gameplay.turnOffExplosionsInColonies) {
        return;
    }
    final World eventWorld = event.getWorld();
    final Predicate<BlockPos> getBlocksInColony = pos -> colony.isCoordInColony(eventWorld, pos);
    final Predicate<Entity> getEntitiesInColony = entity -> colony.isCoordInColony(entity.getEntityWorld(), entity.getPosition());
    // if block is in colony -> remove from list
    final List<BlockPos> blocksToRemove = event.getAffectedBlocks().stream().filter(getBlocksInColony).collect(Collectors.toList());
    // if entity is in colony -> remove from list
    final List<Entity> entitiesToRemove = event.getAffectedEntities().stream().filter(getEntitiesInColony).collect(Collectors.toList());
    event.getAffectedBlocks().removeAll(blocksToRemove);
    event.getAffectedEntities().removeAll(entitiesToRemove);
}
Also used : Permissions(com.minecolonies.coremod.colony.permissions.Permissions) Blocks(net.minecraft.init.Blocks) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ItemScanTool(com.minecolonies.coremod.items.ItemScanTool) ArrowLooseEvent(net.minecraftforge.event.entity.player.ArrowLooseEvent) ItemPotion(net.minecraft.item.ItemPotion) Action(com.minecolonies.api.colony.permissions.Action) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) ItemStack(net.minecraft.item.ItemStack) ItemTossEvent(net.minecraftforge.event.entity.item.ItemTossEvent) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) JobGuard(com.minecolonies.coremod.colony.jobs.JobGuard) Block(net.minecraft.block.Block) FillBucketEvent(net.minecraftforge.event.entity.player.FillBucketEvent) EntityUtils(com.minecolonies.api.util.EntityUtils) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) EntityItemPickupEvent(net.minecraftforge.event.entity.player.EntityItemPickupEvent) ExplosionEvent(net.minecraftforge.event.world.ExplosionEvent) Entity(net.minecraft.entity.Entity) Event(net.minecraftforge.fml.common.eventhandler.Event) LanguageHandler(com.minecolonies.api.util.LanguageHandler) BlockContainer(net.minecraft.block.BlockContainer) BlockEvent(net.minecraftforge.event.world.BlockEvent) Colony(com.minecolonies.coremod.colony.Colony) PermissionEvent(com.minecolonies.coremod.colony.permissions.PermissionEvent) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) ItemFood(net.minecraft.item.ItemFood) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) IBlockState(net.minecraft.block.state.IBlockState) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EntityMob(net.minecraft.entity.monster.EntityMob) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) NotNull(org.jetbrains.annotations.NotNull) Configurations(com.minecolonies.api.configuration.Configurations) FakePlayer(net.minecraftforge.common.util.FakePlayer) AttackEntityEvent(net.minecraftforge.event.entity.player.AttackEntityEvent) Entity(net.minecraft.entity.Entity) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 80 with Colony

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

the class StructureWrapper method handleBlockPlacement.

private void handleBlockPlacement(final BlockPos pos, final IBlockState localState, final boolean complete) {
    for (final IPlacementHandler handlers : PlacementHandlers.handlers) {
        final Object result = handlers.handle(world, pos, localState, null, true, complete);
        if (result instanceof IBlockState) {
            final IBlockState blockState = (IBlockState) result;
            final Colony colony = ColonyManager.getColony(world, pos);
            if (colony != null) {
                final AbstractBuilding building = colony.getBuildingManager().getBuilding(position);
                if (building != null) {
                    building.registerBlockPosition(blockState, pos, world);
                }
            }
            return;
        } else if (!(result instanceof IPlacementHandler.ActionProcessingResult) || result != IGNORE) {
            return;
        }
    }
}
Also used : IPlacementHandler(com.minecolonies.coremod.placementhandlers.IPlacementHandler) IBlockState(net.minecraft.block.state.IBlockState) Colony(com.minecolonies.coremod.colony.Colony) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Aggregations

Colony (com.minecolonies.coremod.colony.Colony)81 TextComponentString (net.minecraft.util.text.TextComponentString)29 IColony (com.minecolonies.api.colony.IColony)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 BlockPos (net.minecraft.util.math.BlockPos)19 Nullable (org.jetbrains.annotations.Nullable)16 CitizenData (com.minecolonies.coremod.colony.CitizenData)13 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)13 NotNull (org.jetbrains.annotations.NotNull)11 ItemStack (net.minecraft.item.ItemStack)9 Entity (net.minecraft.entity.Entity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 World (net.minecraft.world.World)6 List (java.util.List)5 UUID (java.util.UUID)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)4 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)4 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)4 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)4