use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class BlockHutField method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
//Only work on server side.
if (worldIn.isRemote) {
return;
}
if (placer instanceof EntityPlayer) {
@Nullable final Colony colony = ColonyManager.getColony(worldIn, pos);
if (colony != null) {
@NotNull final InventoryField inventoryField = new InventoryField();
final ScarecrowTileEntity scareCrow = (ScarecrowTileEntity) worldIn.getTileEntity(pos);
final EntityPlayer player = (EntityPlayer) placer;
if (scareCrow != null) {
scareCrow.setInventoryField(inventoryField);
colony.addNewField(scareCrow, player.inventory, pos, worldIn);
}
}
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ListColoniesCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
int page = getIthArgument(args, 0, 1);
final int abandonedSince = getIthArgument(args, 1, 0);
final List<Colony> colonies;
if (abandonedSince > 0) {
colonies = ColonyManager.getColoniesAbandonedSince(abandonedSince);
} else {
colonies = ColonyManager.getColonies();
}
final int colonyCount = colonies.size();
// check to see if we have to add one page to show the half page
final int halfPage = (colonyCount % COLONIES_ON_PAGE == 0) ? 0 : 1;
final int pageCount = ((colonyCount) / COLONIES_ON_PAGE) + halfPage;
if (page < 1 || page > pageCount) {
page = 1;
}
final int pageStartIndex = COLONIES_ON_PAGE * (page - 1);
final int pageStopIndex = Math.min(COLONIES_ON_PAGE * page, colonyCount);
final int prevPage = Math.max(0, page - 1);
final int nextPage = Math.min(page + 1, (colonyCount / COLONIES_ON_PAGE) + halfPage);
final List<Colony> coloniesPage;
if (pageStartIndex < 0 || pageStartIndex >= colonyCount) {
coloniesPage = new ArrayList<>();
} else {
coloniesPage = colonies.subList(pageStartIndex, pageStopIndex);
}
final ITextComponent headerLine = new TextComponentString(PAGE_TOP_LEFT + page + PAGE_TOP_MIDDLE + pageCount + PAGE_TOP_RIGHT);
sender.sendMessage(headerLine);
for (final Colony colony : coloniesPage) {
sender.sendMessage(new TextComponentString(String.format(ID_AND_NAME_TEXT, colony.getID(), colony.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_COLONY_INFO, colony.getID())))));
final BlockPos center = colony.getCenter();
final ITextComponent teleport = new TextComponentString(COORDINATES_TEXT + String.format(COORDINATES_XYZ, center.getX(), center.getY(), center.getZ())).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, TELEPORT_COMMAND + colony.getID())));
sender.sendMessage(teleport);
}
final ITextComponent prevButton = new TextComponentString(PREV_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + prevPage)));
final ITextComponent nextButton = new TextComponentString(NEXT_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + nextPage)));
final ITextComponent beginLine = new TextComponentString(PAGE_LINE);
final ITextComponent endLine = new TextComponentString(PAGE_LINE);
sender.sendMessage(beginLine.appendSibling(prevButton).appendSibling(new TextComponentString(PAGE_LINE_DIVIDER)).appendSibling(nextButton).appendSibling(endLine));
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ColonyPackageManager method sendPermissionsPackets.
@Override
public void sendPermissionsPackets(@NotNull final Set<EntityPlayerMP> oldSubscribers, final boolean hasNewSubscribers) {
final Permissions permissions = colony.getPermissions();
if (permissions.isDirty() || hasNewSubscribers || colony.getWorld().rand.nextInt(CHANCE_TO_UPDATE) <= 1) {
subscribers.stream().filter(player -> permissions.isDirty() || !oldSubscribers.contains(player)).forEach(player -> {
final Rank rank = permissions.getRank(player);
MineColonies.getNetwork().sendTo(new PermissionsMessage.View(colony, rank), player);
});
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class BuildingWareHouse method getTileEntity.
/**
* Returns the tile entity that belongs to the colony building.
*
* @return {@link TileEntityColonyBuilding} object of the building.
*/
@Override
public TileEntityWareHouse getTileEntity() {
final Colony colony = getColony();
if ((tileEntity == null || tileEntity.isInvalid()) && colony != null && colony.getWorld() != null && getLocation() != null && colony.getWorld().getBlockState(getLocation()) != null && colony.getWorld().getBlockState(this.getLocation()).getBlock() instanceof BlockHutWareHouse) {
final TileEntity te = getColony().getWorld().getTileEntity(this.getLocation());
if (te instanceof TileEntityWareHouse) {
tileEntity = (TileEntityWareHouse) te;
if (tileEntity.getBuilding() == null) {
tileEntity.setColony(colony);
tileEntity.setBuilding(this);
}
}
}
return tileEntity;
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ItemScepterGuard method handleItemUsage.
/**
* Handles the usage of the item.
*
* @param worldIn the world it is used in.
* @param pos the position.
* @param compound the compound.
* @param playerIn the player using it.
* @return if it has been successful.
*/
@NotNull
private static EnumActionResult handleItemUsage(final World worldIn, final BlockPos pos, final NBTTagCompound compound, final EntityPlayer playerIn) {
final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
if (colony == null) {
return EnumActionResult.FAIL;
}
final BlockPos guardTower = BlockPosUtil.readFromNBT(compound, "pos");
final AbstractBuilding hut = colony.getBuildingManager().getBuilding(guardTower);
if (!(hut instanceof AbstractBuildingGuards)) {
return EnumActionResult.FAIL;
}
final AbstractBuildingGuards tower = (AbstractBuildingGuards) hut;
if (BlockPosUtil.getDistance2D(pos, guardTower) > tower.getPatrolDistance()) {
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuardTooFar");
return EnumActionResult.FAIL;
}
final Task task = Task.values()[compound.getInteger("task")];
final CitizenData citizen = tower.getMainWorker();
String name = "";
if (citizen != null) {
name = " " + citizen.getName();
}
if (task.equals(Task.GUARD)) {
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuard", pos, name);
tower.setGuardTarget(pos);
playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem);
} else {
if (!compound.hasKey(TAG_LAST_POS)) {
tower.resetPatrolTargets();
}
tower.addPatrolTargets(pos);
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickPatrol", pos, name);
}
BlockPosUtil.writeToNBT(compound, TAG_LAST_POS, pos);
return EnumActionResult.SUCCESS;
}
Aggregations