Search in sources :

Example 1 with IPermissions

use of com.minecolonies.api.colony.permissions.IPermissions in project minecolonies by ldtteam.

the class EntityCitizen method checkIfValidDamageSource.

/**
 * Check if the damage source is valid.
 *
 * @param source the damage source.
 * @param damage the dealt damage.
 * @return true if valid.
 */
private boolean checkIfValidDamageSource(final DamageSource source, final float damage) {
    final Entity sourceEntity = source.getEntity();
    if (sourceEntity instanceof EntityCitizen) {
        if (((EntityCitizen) sourceEntity).citizenColonyHandler.getColonyId() == citizenColonyHandler.getColonyId()) {
            return false;
        }
        final IColony attackerColony = ((EntityCitizen) sourceEntity).citizenColonyHandler.getColony();
        if (attackerColony != null && citizenColonyHandler.getColony() != null) {
            final IPermissions permission = attackerColony.getPermissions();
            citizenColonyHandler.getColony().getPermissions().addPlayer(permission.getOwner(), permission.getOwnerName(), permission.getRank(permission.HOSTILE_RANK_ID));
        }
    }
    if (sourceEntity instanceof PlayerEntity) {
        if (sourceEntity instanceof ServerPlayerEntity) {
            if (citizenColonyHandler.getColony().getRaiderManager().isRaided()) {
                return false;
            }
            if (damage > 1 && !getCitizenColonyHandler().getColony().getPermissions().hasPermission((PlayerEntity) sourceEntity, Action.HURT_CITIZEN)) {
                return false;
            }
            if (getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard) {
                return IGuardBuilding.checkIfGuardShouldTakeDamage(this, (PlayerEntity) sourceEntity);
            }
        } else {
            final IColonyView colonyView = IColonyManager.getInstance().getColonyView(getCitizenColonyHandler().getColonyId(), level.dimension());
            return damage <= 1 || colonyView == null || colonyView.getPermissions().hasPermission((PlayerEntity) sourceEntity, Action.HURT_CITIZEN);
        }
    }
    return true;
}
Also used : SittingEntity(com.minecolonies.coremod.entity.SittingEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IPermissions(com.minecolonies.api.colony.permissions.IPermissions) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 2 with IPermissions

use of com.minecolonies.api.colony.permissions.IPermissions in project minecolonies by Minecolonies.

the class WindowPermissionsPage method trigger.

/**
 * Called when the permission button has been triggered.
 *
 * @param button the triggered button.
 */
private void trigger(@NotNull final Button button) {
    final int index = actionsList.getListElementIndexByPane(button);
    final Action action = actions.get(index);
    final IPermissions permissions = building.getColony().getPermissions();
    final PlayerEntity playerEntity = Minecraft.getInstance().player;
    String key = button.getText() instanceof TranslationTextComponent ? ((TranslationTextComponent) button.getText()).getKey() : button.getTextAsString();
    final boolean enable = !COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_ON.equals(key);
    button.disable();
    if (!permissions.alterPermission(permissions.getRank(playerEntity), actionsRank, action, enable)) {
        return;
    }
    Network.getNetwork().sendToServer(new PermissionsMessage.Permission(building.getColony(), enable, actionsRank, action));
    if (!enable) {
        button.setText(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_OFF));
    } else {
        button.setText(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_ON));
    }
}
Also used : Action(com.minecolonies.api.colony.permissions.Action) PermissionsMessage(com.minecolonies.coremod.network.messages.PermissionsMessage) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) IPermissions(com.minecolonies.api.colony.permissions.IPermissions) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 3 with IPermissions

use of com.minecolonies.api.colony.permissions.IPermissions in project minecolonies by Minecolonies.

the class EntityCitizen method checkIfValidDamageSource.

/**
 * Check if the damage source is valid.
 *
 * @param source the damage source.
 * @param damage the dealt damage.
 * @return true if valid.
 */
private boolean checkIfValidDamageSource(final DamageSource source, final float damage) {
    final Entity sourceEntity = source.getEntity();
    if (sourceEntity instanceof EntityCitizen) {
        if (((EntityCitizen) sourceEntity).citizenColonyHandler.getColonyId() == citizenColonyHandler.getColonyId()) {
            return false;
        }
        final IColony attackerColony = ((EntityCitizen) sourceEntity).citizenColonyHandler.getColony();
        if (attackerColony != null && citizenColonyHandler.getColony() != null) {
            final IPermissions permission = attackerColony.getPermissions();
            citizenColonyHandler.getColony().getPermissions().addPlayer(permission.getOwner(), permission.getOwnerName(), permission.getRank(permission.HOSTILE_RANK_ID));
        }
    }
    if (sourceEntity instanceof PlayerEntity) {
        if (sourceEntity instanceof ServerPlayerEntity) {
            if (citizenColonyHandler.getColony().getRaiderManager().isRaided()) {
                return false;
            }
            if (damage > 1 && !getCitizenColonyHandler().getColony().getPermissions().hasPermission((PlayerEntity) sourceEntity, Action.HURT_CITIZEN)) {
                return false;
            }
            if (getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard) {
                return IGuardBuilding.checkIfGuardShouldTakeDamage(this, (PlayerEntity) sourceEntity);
            }
        } else {
            final IColonyView colonyView = IColonyManager.getInstance().getColonyView(getCitizenColonyHandler().getColonyId(), level.dimension());
            return damage <= 1 || colonyView == null || colonyView.getPermissions().hasPermission((PlayerEntity) sourceEntity, Action.HURT_CITIZEN);
        }
    }
    return true;
}
Also used : SittingEntity(com.minecolonies.coremod.entity.SittingEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IPermissions(com.minecolonies.api.colony.permissions.IPermissions) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 4 with IPermissions

use of com.minecolonies.api.colony.permissions.IPermissions in project minecolonies by ldtteam.

the class WindowPermissionsPage method trigger.

/**
 * Called when the permission button has been triggered.
 *
 * @param button the triggered button.
 */
private void trigger(@NotNull final Button button) {
    final int index = actionsList.getListElementIndexByPane(button);
    final Action action = actions.get(index);
    final IPermissions permissions = building.getColony().getPermissions();
    final PlayerEntity playerEntity = Minecraft.getInstance().player;
    final boolean enable = !LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_ON).equals(button.getTextAsString());
    button.disable();
    if (!permissions.alterPermission(permissions.getRank(playerEntity), actionsRank, action, enable)) {
        return;
    }
    Network.getNetwork().sendToServer(new PermissionsMessage.Permission(building.getColony(), enable, actionsRank, action));
    if (!enable) {
        button.setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_OFF));
    } else {
        button.setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_ON));
    }
}
Also used : Action(com.minecolonies.api.colony.permissions.Action) PermissionsMessage(com.minecolonies.coremod.network.messages.PermissionsMessage) IPermissions(com.minecolonies.api.colony.permissions.IPermissions) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

IPermissions (com.minecolonies.api.colony.permissions.IPermissions)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 Action (com.minecolonies.api.colony.permissions.Action)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 IThreatTableEntity (com.minecolonies.api.entity.combat.threat.IThreatTableEntity)2 SittingEntity (com.minecolonies.coremod.entity.SittingEntity)2 PermissionsMessage (com.minecolonies.coremod.network.messages.PermissionsMessage)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 MonsterEntity (net.minecraft.entity.monster.MonsterEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1