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