use of com.minecolonies.coremod.colony.Colony 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.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
boolean firstArgumentColonyId = true;
int colonyId = -1;
if (args.length >= 2) {
colonyId = getIthArgument(args, 0, -1);
if (colonyId == -1) {
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.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
if (sender instanceof EntityPlayer) {
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, getCommand(), colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
final int citizenId = getValidCitizenId(colony, firstArgumentColonyId, args);
if (citizenId == -1 || colony.getCitizen(citizenId) == null) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
return;
}
executeSpecializedCode(server, sender, colony, citizenId);
}
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 workOrderName The name of the work order.
* @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 Structures.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 && BlockPosUtil.getDistance2D(tempColony.getCenter(), buildPos) >= Configurations.workingRangeTownHall * 2 + Configurations.townHallPadding))) {
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);
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class BuildToolPlaceMessage method setupBuilding.
/**
* setup the building once it has been placed.
*
* @param world World the hut is being placed into.
* @param player Who placed the hut.
* @param sn The name of the structure.
* @param workOrderName The name of the work order.
* @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 setupBuilding(@NotNull final World world, @NotNull final EntityPlayer player, final Structures.StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
@Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, buildPos);
if (building == null) {
Log.getLogger().error("BuildTool: building is null!");
} else {
if (building.getTileEntity() != null) {
final Colony colony = ColonyManager.getColony(world, buildPos);
if (colony == null) {
Log.getLogger().info("No colony for " + player.getName());
} else {
building.getTileEntity().setColony(colony);
}
}
building.setStyle(sn.getStyle());
building.setRotation(rotation);
if (mirror) {
building.setMirror();
}
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class HireFireMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final HireFireMessage 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;
}
if (message.hire) {
final CitizenData citizen = colony.getCitizen(message.citizenID);
((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(citizen);
} else {
((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(null);
}
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class DeliveryRequestResolver method attemptResolve.
@Nullable
@Override
public List<IToken<?>> attemptResolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
if (manager.getColony().getWorld().isRemote) {
return null;
}
final Colony colony = (Colony) manager.getColony();
// We can do an instant get here, since we are already filtering on anything that has no entity.
final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> request.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).min(Comparator.comparing((CitizenData c) -> ((JobDeliveryman) c.getJob()).getTaskQueue().size()).thenComparing(Comparator.comparing(c -> {
BlockPos targetPos = request.getRequest().getTarget().getInDimensionLocation();
// We can do an instant get here, since we are already filtering on anything that has no entity.
BlockPos entityLocation = c.getCitizenEntity().get().getLocation().getInDimensionLocation();
return BlockPosUtil.getDistanceSquared(targetPos, entityLocation);
}))).orElse(null);
if (freeDeliveryMan == null) {
return null;
}
final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
job.addRequest(request.getToken());
return Lists.newArrayList();
}
Aggregations