Search in sources :

Example 41 with Colony

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

the class OpenCraftingGUIMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final OpenCraftingGUIMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null && checkPermissions(colony, player)) {
        final BlockPos pos = message.buildingId;
        player.openGui(MineColonies.instance, 0, player.world, pos.getX(), pos.getY(), pos.getZ());
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos)

Example 42 with Colony

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

the class RecallCitizenMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final RecallCitizenMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        // Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        @Nullable final AbstractBuildingWorker building = colony.getBuildingManager().getBuilding(message.buildingId, AbstractBuildingWorker.class);
        if (building != null) {
            for (int i = 0; i < building.getWorkerEntities().size(); i++) {
                Optional<EntityCitizen> optionalEntityCitizen = building.getWorkerEntities().get(i);
                if (!optionalEntityCitizen.isPresent()) {
                    final CitizenData citizenData = building.getWorker().get(i);
                    if (citizenData != null) {
                        Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
                        citizenData.updateCitizenEntityIfNecessary();
                        optionalEntityCitizen = citizenData.getCitizenEntity();
                    } else {
                        Log.getLogger().warn("Citizen is AWOL and citizenData is null!");
                        return;
                    }
                }
                final BlockPos loc = building.getLocation();
                if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), colony.getWorld(), loc)) {
                    LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerHuts.recallFail");
                }
            }
        }
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with Colony

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

the class TownHallRenameMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final TownHallRenameMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        // Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        message.name = (message.name.length() <= MAX_NAME_LENGTH) ? message.name : message.name.substring(0, SUBSTRING_LENGTH);
        colony.setName(message.name);
        MineColonies.getNetwork().sendToAll(message);
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony)

Example 44 with Colony

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

the class UpgradeWarehouseMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final UpgradeWarehouseMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony == null) {
        Log.getLogger().warn("UpgradeWarehouseMessage colony is null");
        return;
    }
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    final AbstractBuilding building = colony.getBuildingManager().getBuilding(message.buildingId);
    if (!(building instanceof BuildingWareHouse)) {
        Log.getLogger().warn("UpgradeWarehouseMessage building is not a Warehouse");
        return;
    }
    ((BuildingWareHouse) building).upgradeContainers(player.world);
    final boolean isCreative = player.capabilities.isCreativeMode;
    if (!isCreative) {
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(player.inventory), itemStack -> itemStack.isItemEqual(new ItemStack(Blocks.EMERALD_BLOCK)));
        player.inventory.decrStackSize(slot, 1);
    }
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) ItemStack(net.minecraft.item.ItemStack) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.BuildingWareHouse)

Example 45 with Colony

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

the class BuildToolPlaceMessage method handleHut.

/**
 * Handles the placement of huts.
 *
 * @param world         World the hut is being placed into.
 * @param player        Who placed the hut.
 * @param sn            The name of the structure.
 * @param rotation      The number of times the structure should be rotated.
 * @param buildPos      The location the hut is being placed.
 * @param mirror        Whether or not the strcture is mirrored.
 */
private static void handleHut(@NotNull final World world, @NotNull final EntityPlayer player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    final String hut = sn.getSection();
    final Block block = Block.getBlockFromName(Constants.MOD_ID + ":blockHut" + hut);
    final Colony tempColony = ColonyManager.getClosestColony(world, buildPos);
    if (tempColony != null && (!tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && !(block instanceof BlockHutTownHall && !ColonyManager.isTooCloseToColony(world, buildPos)))) {
        return;
    }
    if (block != null && player.inventory.hasItemStack(new ItemStack(block))) {
        if (EventHandler.onBlockHutPlaced(world, player, block, buildPos)) {
            world.destroyBlock(buildPos, true);
            world.setBlockState(buildPos, block.getDefaultState().withRotation(BlockUtils.getRotation(rotation)));
            ((AbstractBlockHut) block).onBlockPlacedByBuildTool(world, buildPos, world.getBlockState(buildPos), player, null, mirror, sn.getStyle());
            player.inventory.clearMatchingItems(Item.getItemFromBlock(block), -1, 1, null);
            setupBuilding(world, player, sn, rotation, buildPos, mirror);
        }
    } else {
        LanguageHandler.sendPlayerMessage(player, BuildToolPlaceMessage.NO_HUT_IN_INVENTORY);
    }
}
Also used : Block(net.minecraft.block.Block) Colony(com.minecolonies.coremod.colony.Colony) TextComponentString(net.minecraft.util.text.TextComponentString) BlockHutTownHall(com.minecolonies.coremod.blocks.BlockHutTownHall) ItemStack(net.minecraft.item.ItemStack) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut)

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