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());
}
}
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");
}
}
}
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations