Skip to content

Commit

Permalink
Make area.allow_attack accept overrides for specific entity
Browse files Browse the repository at this point in the history
  • Loading branch information
3TUSK committed Aug 6, 2022
1 parent 938d5aa commit 91ad15e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/org/teacon/areacontrol/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraftforge.server.permission.PermissionAPI;
Expand All @@ -29,6 +30,9 @@ public abstract class EntityMixin {
@Shadow
public abstract Level getLevel();

@Shadow
public abstract EntityType<?> getType();

/*
* This is probably one of the most universal ways to prevent edge cases such as
* preventing an arrow from unauthorized player to shoot down vanilla item frame.
Expand Down Expand Up @@ -57,7 +61,15 @@ private void damageSrcCheck(DamageSource src, CallbackInfoReturnable<Boolean> ci
permissionToCheck = AreaControlPermissions.BYPASS_PVP;
deniedFeedback = new TranslatableComponent("area_control.notice.pvp_disabled", ObjectArrays.EMPTY_ARRAY);
} else {
propToCheck = "area.allow_attack";
propToCheck = AreaProperties.ALLOW_PVE;
var entityTypeRegName = this.getType().getRegistryName();
var entitySpecificProp = AreaProperties.ALLOW_PVE + "." + entityTypeRegName;
var modSpecificProp = AreaProperties.ALLOW_PVE + "." + entityTypeRegName.getNamespace();
if (AreaProperties.keyPresent(area, entitySpecificProp)) {
propToCheck = entitySpecificProp;
} else if (AreaProperties.keyPresent(area, modSpecificProp)) {
propToCheck = modSpecificProp;
}
permissionToCheck = AreaControlPermissions.BYPASS_ATTACK;
deniedFeedback = new TranslatableComponent("area_control.notice.pve_disabled", ObjectArrays.EMPTY_ARRAY);
}
Expand Down

0 comments on commit 91ad15e

Please sign in to comment.