From db75fd56267e13540ce699473782c8cd94a5e88c Mon Sep 17 00:00:00 2001 From: pietru Date: Sat, 10 May 2025 21:45:45 +0200 Subject: [PATCH] Protect from fire, improve protections --- gradle.properties | 4 +- .../mixins/BlockEntitySignMixin.java | 1 + .../cookie_utils/mixins/EntityMixin.java | 45 +++++++++++++++++++ .../mixins/PlayerEntityMixin.java | 40 ++++++----------- .../permissions/ObjectPermList.java | 16 +++++++ 5 files changed, 77 insertions(+), 29 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6df193b..8e8a96d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,9 +10,9 @@ id=cookie_utils # Dependency Versions cosmic_reach_rev=alpha -cosmic_reach_version=0.4.8 +cosmic_reach_version=0.4.9 # If unspecified, will use the version above -cosmic_reach_server_version=0.4.8 +cosmic_reach_server_version=0.4.9 cosmic_quilt_version=2.3.1 #2.2.0 diff --git a/src/main/java/net/pietru/cookie_utils/mixins/BlockEntitySignMixin.java b/src/main/java/net/pietru/cookie_utils/mixins/BlockEntitySignMixin.java index 8354a7b..24d8fb8 100644 --- a/src/main/java/net/pietru/cookie_utils/mixins/BlockEntitySignMixin.java +++ b/src/main/java/net/pietru/cookie_utils/mixins/BlockEntitySignMixin.java @@ -67,6 +67,7 @@ public class BlockEntitySignMixin { Area area = new Area(); area.enabled = true; ObjectPermList.get_default_perms(area.perms); + ObjectPermList.get_safe_perm_overrides(area.perms); area.setCorners(ca, cb); area.name = "claim_sign/self_claim_sign_"+c+"_" + ownerId.replace(":", "_") + ".json"; area.zoneId = zone.zoneId; diff --git a/src/main/java/net/pietru/cookie_utils/mixins/EntityMixin.java b/src/main/java/net/pietru/cookie_utils/mixins/EntityMixin.java index 554cb46..962e3f7 100644 --- a/src/main/java/net/pietru/cookie_utils/mixins/EntityMixin.java +++ b/src/main/java/net/pietru/cookie_utils/mixins/EntityMixin.java @@ -1,10 +1,27 @@ package net.pietru.cookie_utils.mixins; import com.badlogic.gdx.math.Vector3; +import com.llamalad7.mixinextras.sugar.Local; +import finalforeach.cosmicreach.accounts.Account; import finalforeach.cosmicreach.entities.Entity; +import finalforeach.cosmicreach.entities.EntityFlameProjectile; +import finalforeach.cosmicreach.entities.EntityLaserProjectile; +import finalforeach.cosmicreach.entities.IDamageSource; +import finalforeach.cosmicreach.entities.components.PlayerFallDamage; +import finalforeach.cosmicreach.entities.player.Player; +import finalforeach.cosmicreach.entities.player.PlayerEntity; +import finalforeach.cosmicreach.networking.packets.MessagePacket; +import finalforeach.cosmicreach.networking.server.ServerSingletons; import finalforeach.cosmicreach.world.Zone; +import net.pietru.cookie_utils.permissions.Permissions; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static net.pietru.cookie_utils.api.Region.can_enter_position; +import static net.pietru.cookie_utils.api.Region.is_not_reloading; @Mixin(Entity.class) public class EntityMixin { @@ -12,4 +29,32 @@ public class EntityMixin { public Zone zone; @Shadow public Vector3 position; + + @Inject(method = "hit", at = @At("HEAD"), cancellable = true) + private void event_player_hit(CallbackInfo ci, @Local(argsOnly = true) IDamageSource damageSource, @Local(argsOnly = true) float amount){ + if (damageSource instanceof Entity) { + if (damageSource instanceof PlayerEntity) { + Account account = ((PlayerEntity) damageSource).getPlayer().getAccount(); + + if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_enter_position(((Entity) damageSource).getPosition(), "pve", account.getUniqueId())) { + ci.cancel(); + + MessagePacket packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but you can't things here." : "Sorry but you can't do this action right now. [Config Reload In Progress]")); + packet.setupAndSend(ServerSingletons.getConnection(((PlayerEntity) damageSource).getPlayer())); + } + } else if (damageSource instanceof EntityLaserProjectile) { + if (!can_enter_position(((Entity)damageSource).getPosition(), "laser_damage", this.zone)) { + ci.cancel(); + } + } else if (damageSource instanceof EntityFlameProjectile) { + if (!can_enter_position(((Entity)damageSource).getPosition(), "fire_damage", this.zone)) { + ci.cancel(); + } + } else { + if (!can_enter_position(((Entity)damageSource).getPosition(), "eve", this.zone)) { + ci.cancel(); + } + } + } + } } diff --git a/src/main/java/net/pietru/cookie_utils/mixins/PlayerEntityMixin.java b/src/main/java/net/pietru/cookie_utils/mixins/PlayerEntityMixin.java index efd5af4..06cf0f1 100644 --- a/src/main/java/net/pietru/cookie_utils/mixins/PlayerEntityMixin.java +++ b/src/main/java/net/pietru/cookie_utils/mixins/PlayerEntityMixin.java @@ -3,6 +3,7 @@ package net.pietru.cookie_utils.mixins; import com.llamalad7.mixinextras.sugar.Local; import finalforeach.cosmicreach.accounts.Account; import finalforeach.cosmicreach.entities.Entity; +import finalforeach.cosmicreach.entities.EntityFlameProjectile; import finalforeach.cosmicreach.entities.EntityLaserProjectile; import finalforeach.cosmicreach.entities.IDamageSource; import finalforeach.cosmicreach.entities.components.PlayerFallDamage; @@ -20,42 +21,27 @@ import static net.pietru.cookie_utils.api.Region.*; @Mixin(PlayerEntity.class) public class PlayerEntityMixin extends EntityMixin{ - @Inject(method = "onAttackInteraction", at = @At("HEAD"), cancellable = true) - private void event_player_attack(CallbackInfo ci, @Local(argsOnly = true) Entity sourceEntity){ - if (sourceEntity instanceof PlayerEntity){ - Account account = ((PlayerEntity) sourceEntity).getPlayer().getAccount(); - - if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_enter_position(sourceEntity.getPosition(),"pvp",account.getUniqueId())) { - ci.cancel(); - - MessagePacket packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but you can't attack people here." : "Sorry but you can't do this action right now. [Config Reload In Progress]")); - packet.setupAndSend(ServerSingletons.getConnection(((PlayerEntity) sourceEntity).getPlayer())); - } - } else if (sourceEntity instanceof EntityLaserProjectile) { - if (!can_enter_position(sourceEntity.getPosition(),"laser_damage",this.zone)){ - ci.cancel(); - } - } else { - if (!can_enter_position(sourceEntity.getPosition(),"pve",this.zone)){ - ci.cancel(); - } - } - } - @Inject(method = "hit", at = @At("HEAD"), cancellable = true) private void event_player_hit(CallbackInfo ci, @Local(argsOnly = true) IDamageSource damageSource, @Local(argsOnly = true) float amount){ if (damageSource instanceof Entity) { if (damageSource instanceof PlayerEntity) { Account account = ((PlayerEntity) damageSource).getPlayer().getAccount(); + Entity ob = ((Entity)(Object)this); - if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_enter_position(((Entity)damageSource).getPosition(), "pvp", account.getUniqueId())) { - ci.cancel(); + if (ob instanceof PlayerEntity) { + if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_enter_position(((Entity) damageSource).getPosition(), "pvp", account.getUniqueId())) { + ci.cancel(); - MessagePacket packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but you can't attack people here." : "Sorry but you can't do this action right now. [Config Reload In Progress]")); - packet.setupAndSend(ServerSingletons.getConnection(((PlayerEntity) damageSource).getPlayer())); + MessagePacket packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but you can't attack people here." : "Sorry but you can't do this action right now. [Config Reload In Progress]")); + packet.setupAndSend(ServerSingletons.getConnection(((PlayerEntity) damageSource).getPlayer())); + } } } else if (damageSource instanceof EntityLaserProjectile) { - if (!can_enter_position(((Entity)damageSource).getPosition(), "laser_damage", this.zone)) { + if (!can_enter_position(((Entity)damageSource).getPosition(), "player_laser_damage", this.zone)) { + ci.cancel(); + } + } else if (damageSource instanceof EntityFlameProjectile) { + if (!can_enter_position(((Entity)damageSource).getPosition(), "player_fire_damage", this.zone)) { ci.cancel(); } } else { diff --git a/src/main/java/net/pietru/cookie_utils/permissions/ObjectPermList.java b/src/main/java/net/pietru/cookie_utils/permissions/ObjectPermList.java index 70e198e..afe81dd 100644 --- a/src/main/java/net/pietru/cookie_utils/permissions/ObjectPermList.java +++ b/src/main/java/net/pietru/cookie_utils/permissions/ObjectPermList.java @@ -7,6 +7,7 @@ import java.util.Map; public class ObjectPermList { public static final Map default_bool_perms = new HashMap<>(); + public static final Map safety_overrides_bool_perms = new HashMap<>(); static { default_bool_perms.put("place", false); default_bool_perms.put("break", false); @@ -20,8 +21,17 @@ public class ObjectPermList { default_bool_perms.put("pvp", false); default_bool_perms.put("pve", true); + default_bool_perms.put("eve", true); + default_bool_perms.put("player_laser_damage", true); default_bool_perms.put("laser_damage", true); + default_bool_perms.put("player_fire_damage", true); + default_bool_perms.put("fire_damage", true); default_bool_perms.put("fall_damage",true); + + safety_overrides_bool_perms.put("pve", false); + safety_overrides_bool_perms.put("player_laser_damage", false); + safety_overrides_bool_perms.put("player_fire_damage", false); + safety_overrides_bool_perms.put("fall_damage",false); } @@ -59,4 +69,10 @@ public class ObjectPermList { val.set_bool_perm(key,default_bool_perms.get(key)); } } + + public static void get_safe_perm_overrides(ObjectPermList val){ + for (String key : safety_overrides_bool_perms.keySet()){ + val.set_bool_perm(key,default_bool_perms.get(key)); + } + } }