use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class RSResetCommand 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_ARGUMENTS));
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_NULL));
return;
}
colonyId = colony.getID();
}
final Colony colony = ColonyManager.getColony(colonyId);
if (colony == null) {
sender.sendMessage(new TextComponentString(String.format(COLONY_NULL, colonyId)));
return;
}
executeShared(server, sender, colony);
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class CheckForAutoDeletesCommand method executeShared.
private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final boolean confirmDelete) throws CommandException {
if (sender instanceof EntityPlayer && !isPlayerOpped(sender)) {
sender.sendMessage(new TextComponentString("Must be OP to use command"));
return;
} else if (sender instanceof TileEntity) {
return;
}
final List<Colony> colonies = ColonyManager.getColonies();
final List<Colony> coloniesToDelete = new ArrayList<>();
for (int index = 0; colonies.size() - 1 >= index; index++) {
final Colony colony = colonies.get(index);
if (colony.canBeAutoDeleted() && Configurations.gameplay.autoDeleteColoniesInHours != 0 && colony.getLastContactInHours() >= Configurations.gameplay.autoDeleteColoniesInHours) {
coloniesToDelete.add(colony);
}
}
if (confirmDelete) {
sender.sendMessage(new TextComponentString("Successful"));
for (final Colony col : coloniesToDelete) {
server.addScheduledTask(() -> ColonyManager.deleteColony(col.getID(), Configurations.gameplay.autoDestroyColonyBlocks));
}
} else {
final ITextComponent deleteButton = new TextComponentString("[DELETE]").setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, COMMAND_CHECK_FOR_AUTODELETES)));
sender.sendMessage(new TextComponentString("There are: " + coloniesToDelete.size() + " of a total of " + colonies.size() + " to delete."));
sender.sendMessage(new TextComponentString("Click [DELETE] to confirm"));
sender.sendMessage(deleteButton);
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class RandomTeleportCommand method teleportPlayer.
/**
* Method used to teleport the player.
*
* @param sender the sender to have access to the world.
* @param playerToTeleport the player which shall be teleported.
*/
private static void teleportPlayer(final ICommandSender sender, final EntityPlayer playerToTeleport) {
// Now the position will be calculated, we will try up to 4 times to find a save position.
int attCounter = 0;
while (attCounter <= ATTEMPTS) {
attCounter++;
/* this math is to get negative numbers */
final int x = getRandCoordinate();
final int z = getRandCoordinate();
if (sender.getEntityWorld().getWorldBorder().getSize() < (sender.getEntityWorld().getSpawnPoint().getDistance(x, sender.getEntityWorld().getSpawnPoint().getY(), z))) {
continue;
}
final BlockPos tpPos = new BlockPos(x, STARTING_Y, z);
final Colony colony = ColonyManager.getClosestColony(sender.getEntityWorld(), tpPos);
/* Check for a close by colony*/
if (BlockPosUtil.getDistance2D(colony.getCenter(), tpPos) < Configurations.gameplay.workingRangeTownHall * 2 + Configurations.gameplay.townHallPadding) {
continue;
}
/*Search for a ground position*/
final BlockPos groundPosition = BlockPosUtil.findLand(tpPos, sender.getEntityWorld());
/*If no position found*/
if (groundPosition == null) {
continue;
}
final boolean foundPosition = BlockPosUtil.isPositionSafe(sender, groundPosition);
if (foundPosition) {
if (MinecoloniesCommand.canExecuteCommand((EntityPlayer) sender)) {
playerToTeleport.sendMessage(new TextComponentString("Buckle up buttercup, this ain't no joy ride!!!"));
playerToTeleport.setHealth(playerToTeleport.getMaxHealth());
playerToTeleport.setPositionAndUpdate(groundPosition.getX(), groundPosition.getY() + SAFETY_DROP, groundPosition.getZ());
playerToTeleport.setHealth(playerToTeleport.getMaxHealth());
} else {
sender.getCommandSenderEntity().sendMessage(new TextComponentString("Please wait at least " + Configurations.gameplay.teleportBuffer + " seconds to teleport again"));
}
return;
}
}
playerToTeleport.getCommandSenderEntity().sendMessage(new TextComponentString("Couldn't find a safe spot. Try again in a moment."));
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class EntityAISleep method shouldContinueExecuting.
/**
* Continue executing if he should sleep.
* Call the wake up method as soon as this isn't the case anymore.
* Might search a bed while he is trying to sleep.
*
* @return true while he should sleep.
*/
@Override
public boolean shouldContinueExecuting() {
if (citizen.getDesiredActivity() == EntityCitizen.DesiredActivity.SLEEP) {
wokeUp = false;
final Colony colony = citizen.getColony();
if (colony == null || colony.getBuildingManager().getBuilding(citizen.getHomePosition()) == null) {
return true;
}
if (usedBed == null) {
final AbstractBuilding hut = colony.getBuildingManager().getBuilding(citizen.getHomePosition());
if (hut instanceof BuildingHome) {
for (final BlockPos pos : ((BuildingHome) hut).getBedList()) {
final World world = citizen.world;
IBlockState state = world.getBlockState(pos);
state = state.getBlock().getActualState(state, world, pos);
if (state.getBlock() instanceof BlockBed && !state.getValue(BlockBed.OCCUPIED) && state.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.HEAD)) {
usedBed = pos;
citizen.world.setBlockState(pos, state.withProperty(BlockBed.OCCUPIED, true), 0x03);
final BlockPos feetPos = pos.offset(state.getValue(BlockBed.FACING).getOpposite());
final IBlockState feetState = citizen.world.getBlockState(feetPos);
citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
return true;
}
}
}
usedBed = citizen.getHomePosition();
} else {
if (citizen.isWorkerAtSiteWithMove(usedBed, 1)) {
citizen.trySleep(usedBed);
return true;
}
}
return true;
}
citizen.onWakeUp();
if (usedBed != null) {
final IBlockState state = citizen.world.getBlockState(usedBed);
if (state.getBlock() instanceof BlockBed) {
final IBlockState headState = citizen.world.getBlockState(usedBed);
citizen.world.setBlockState(usedBed, headState.withProperty(BlockBed.OCCUPIED, false), 0x03);
final BlockPos feetPos = usedBed.offset(headState.getValue(BlockBed.FACING).getOpposite());
final IBlockState feetState = citizen.world.getBlockState(feetPos);
citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
}
usedBed = null;
}
wokeUp = true;
return false;
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class DeliveryRequestResolver method onRequestCancelled.
@Nullable
@Override
public IRequest<?> onRequestCancelled(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
if (!manager.getColony().getWorld().isRemote) {
final Colony colony = (Colony) manager.getColony();
final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(c -> c.getJob() instanceof JobDeliveryman && ((JobDeliveryman) c.getJob()).getTaskQueue().contains(request.getToken())).findFirst().orElse(null);
if (freeDeliveryMan == null) {
MineColonies.getLogger().error("Parent cancellation failed! Unknown request: " + request.getToken());
} else {
final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
job.onTaskDeletion(request.getToken());
}
}
return null;
}
Aggregations