use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class MultiBlockChangeMessage 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 MultiBlockChangeMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(player.getServerWorld(), player.getPosition());
final TileEntity entity = player.getServerWorld().getTileEntity(message.pos);
if (entity instanceof TileEntityMultiBlock && (colony == null || colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS))) {
((TileEntityMultiBlock) entity).setDirection(message.direction);
((TileEntityMultiBlock) entity).setOutput(message.output);
((TileEntityMultiBlock) entity).setRange(message.range);
((TileEntityMultiBlock) entity).setSpeed(message.speed);
final IBlockState state = player.getServerWorld().getBlockState(message.pos);
player.getServerWorld().notifyBlockUpdate(message.pos, state, state, 0x3);
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class RecallTownhallMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final RecallTownhallMessage 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 BuildingTownHall building = colony.getBuildingManager().getTownHall();
if (building != null) {
final BlockPos location = building.getLocation();
final World world = colony.getWorld();
for (final CitizenData citizenData : colony.getCitizenManager().getCitizens()) {
Optional<EntityCitizen> optionalEntityCitizen = citizenData.getCitizenEntity();
if (!optionalEntityCitizen.isPresent()) {
Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
citizenData.updateCitizenEntityIfNecessary();
optionalEntityCitizen = citizenData.getCitizenEntity();
}
if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), world, location)) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerHuts.recallFail");
}
}
}
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class TransferItemsRequestMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final TransferItemsRequestMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(message.colonyId);
if (colony == null) {
Log.getLogger().warn("TransferItemsRequestMessage colony is null");
return;
}
final AbstractBuilding building = colony.getBuildingManager().getBuilding(message.buildingId);
if (building == null) {
Log.getLogger().warn("TransferItemsRequestMessage building is null");
return;
}
if (message.quantity <= 0) {
Log.getLogger().warn("TransferItemsRequestMessage quantity below 0");
return;
}
final boolean isCreative = player.capabilities.isCreativeMode;
final Item item = message.itemStack.getItem();
final int amountToTake;
if (isCreative) {
amountToTake = message.quantity;
} else {
amountToTake = Math.min(message.quantity, InventoryUtils.getItemCountInItemHandler(new InvWrapper(player.inventory), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, message.itemStack, true, true)));
}
final ItemStack itemStackToTake = new ItemStack(item, amountToTake, message.itemStack.getItemDamage());
itemStackToTake.setTagCompound(message.itemStack.getTagCompound());
ItemStack remainingItemStack = InventoryUtils.addItemStackToProviderWithResult(building.getTileEntity(), itemStackToTake);
if (!ItemStackUtils.isEmpty(remainingItemStack)) {
// If we still have some to drop, let's try the additional chests now
final World world = colony.getWorld();
for (final BlockPos pos : building.getAdditionalCountainers()) {
final TileEntity entity = world.getTileEntity(pos);
remainingItemStack = InventoryUtils.addItemStackToProviderWithResult(entity, remainingItemStack);
if (ItemStackUtils.isEmpty(remainingItemStack)) {
break;
}
}
}
if (ItemStackUtils.isEmpty(remainingItemStack) || ItemStackUtils.getSize(remainingItemStack) != ItemStackUtils.getSize(itemStackToTake)) {
// Only doing this at the moment as the additional chest do not detect new content
building.getTileEntity().markDirty();
}
if (!isCreative) {
int amountToRemoveFromPlayer = amountToTake - ItemStackUtils.getSize(remainingItemStack);
while (amountToRemoveFromPlayer > 0) {
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(player.inventory), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, message.itemStack, true, true));
final ItemStack itemsTaken = player.inventory.decrStackSize(slot, amountToRemoveFromPlayer);
amountToRemoveFromPlayer -= ItemStackUtils.getSize(itemsTaken);
}
}
if (attemptResolve) {
building.overruleNextOpenRequestWithStack(itemStack);
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class TransferItemsToCitizenRequestMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final TransferItemsToCitizenRequestMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(message.colonyId);
if (colony == null) {
Log.getLogger().warn("TransferItemsRequestMessage colony is null");
return;
}
final CitizenData citizenData = colony.getCitizenManager().getCitizen(message.citizenId);
if (citizenData == null) {
Log.getLogger().warn("TransferItemsRequestMessage citizenData is null");
return;
}
final Optional<EntityCitizen> optionalEntityCitizen = citizenData.getCitizenEntity();
if (!optionalEntityCitizen.isPresent()) {
Log.getLogger().warn("TransferItemsRequestMessage entity citizen is null");
return;
}
final boolean isCreative = player.capabilities.isCreativeMode;
if (message.quantity <= 0 && !isCreative) {
Log.getLogger().warn("TransferItemsRequestMessage quantity below 0");
return;
}
final Item item = message.itemStack.getItem();
final int amountToTake;
if (isCreative) {
amountToTake = message.quantity;
} else {
amountToTake = Math.min(message.quantity, InventoryUtils.getItemCountInItemHandler(new InvWrapper(player.inventory), item, message.itemStack.getItemDamage()));
}
final ItemStack itemStackToTake = message.itemStack.copy();
ItemStackUtils.setSize(itemStackToTake, message.quantity);
final EntityCitizen citizen = optionalEntityCitizen.get();
final ItemStack remainingItemStack = InventoryUtils.addItemStackToItemHandlerWithResult(new InvWrapper(citizen.getInventoryCitizen()), itemStackToTake);
if (!isCreative) {
int amountToRemoveFromPlayer = amountToTake - ItemStackUtils.getSize(remainingItemStack);
while (amountToRemoveFromPlayer > 0) {
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(player.inventory), item, message.itemStack.getItemDamage());
final ItemStack itemsTaken = player.inventory.decrStackSize(slot, amountToRemoveFromPlayer);
amountToRemoveFromPlayer -= ItemStackUtils.getSize(itemsTaken);
}
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class MarkBuildingDirtyMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final MarkBuildingDirtyMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(message.colonyId);
if (colony == null) {
Log.getLogger().warn("MarkBuildingDirtyMessage colony is null");
return;
}
final AbstractBuilding building = colony.getBuildingManager().getBuilding(message.buildingId);
if (building == null || building.getTileEntity() == null) {
Log.getLogger().warn("MarkBuildingDirtyMessage building or tileEntity is null");
return;
}
building.getTileEntity().markDirty();
}
Aggregations