Search in sources :

Example 46 with Colony

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

the class ChangeFreeToInteractBlockMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final ChangeFreeToInteractBlockMessage 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.EDIT_PERMISSIONS)) {
            LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.item.permissionscepter.permission.deny");
            return;
        }
        if (message.type == MessageType.ADD_BLOCK) {
            switch(message.mode) {
                case LOCATION:
                    colony.addFreePosition(message.pos);
                    LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.item.permissionscepter.addposition.success", message.pos.getX(), message.pos.getY(), message.pos.getZ());
                    break;
                case BLOCK:
                    colony.addFreeBlock(message.block);
                    LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.item.permissionscepter.addblock.success", message.block.getRegistryName());
                    break;
                default:
            }
        } else {
            switch(message.mode) {
                case LOCATION:
                    colony.removeFreePosition(message.pos);
                    LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.item.permissionscepter.removelocation.success", message.pos.getX(), message.pos.getY(), message.pos.getZ());
                    break;
                case BLOCK:
                    colony.removeFreeBlock(message.block);
                    LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.item.permissionscepter.removeblock.success", message.block.getRegistryName());
                    break;
                default:
            }
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony)

Example 47 with Colony

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

the class GeneralEntityWalkToProxy method getWayPoints.

@Override
public Set<BlockPos> getWayPoints() {
    final EntityLiving living = getEntity();
    final Colony colony = ColonyManager.getClosestColony(living.getEntityWorld(), living.getPosition());
    if (colony == null || !colony.isCoordInColony(living.getEntityWorld(), living.getPosition())) {
        return Collections.emptySet();
    }
    return colony.getWayPoints().keySet();
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) Colony(com.minecolonies.coremod.colony.Colony)

Example 48 with Colony

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

the class AddRemoveRecipeMessage method messageOnServerThread.

/**
 * Executes the message on the server thread.
 * Only if the player has the permission, toggle message.
 *
 * @param message the original message.
 * @param player  the player associated.
 */
@Override
public void messageOnServerThread(final AddRemoveRecipeMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony == null || !colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    final AbstractBuilding buildingWorker = colony.getBuildingManager().getBuilding(message.building);
    if (buildingWorker instanceof AbstractBuildingWorker) {
        final IToken token = ColonyManager.getRecipeManager().checkOrAddRecipe(message.storage);
        if (message.remove) {
            ((AbstractBuildingWorker) buildingWorker).removeRecipe(token);
        } else {
            ((AbstractBuildingWorker) buildingWorker).addRecipe(token);
        }
        buildingWorker.markDirty();
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) Colony(com.minecolonies.coremod.colony.Colony) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 49 with Colony

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

the class AssignUnassignMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final AssignUnassignMessage 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;
        }
        final AbstractBuilding building = colony.getBuildingManager().getBuilding(message.buildingId);
        if (!(building instanceof BuildingHome)) {
            return;
        }
        final CitizenData citizen = colony.getCitizenManager().getCitizen(message.citizenID);
        if (message.assign && !((BuildingHome) building).isFull() && citizen.getHomeBuilding() == null) {
            ((BuildingHome) building).addResident(citizen);
        } else if (((BuildingHome) building).hasResident(citizen)) {
            building.removeCitizen(citizen);
        }
    }
}
Also used : BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 50 with Colony

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

the class GuardTaskMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final GuardTaskMessage 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 AbstractBuildingGuards building = colony.getBuildingManager().getBuilding(message.buildingId, AbstractBuildingGuards.class);
        if (building != null) {
            if (message.job != -1) {
                building.setJob(AbstractBuildingGuards.GuardJob.values()[message.job]);
            }
            building.setAssignManually(message.assignmentMode);
            building.setPatrolManually(message.patrollingMode);
            building.setRetrieveOnLowHealth(message.retrieval);
            building.setTask(AbstractBuildingGuards.Task.values()[message.task]);
            if (building.getTask().equals(AbstractBuildingGuards.Task.FOLLOW)) {
                building.setPlayerToFollow(player);
            }
        }
    }
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) Colony(com.minecolonies.coremod.colony.Colony) Nullable(org.jetbrains.annotations.Nullable)

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