diff --git a/src/main/java/net/pietru/cookie_utils/api/Region.java b/src/main/java/net/pietru/cookie_utils/api/Region.java index dc7af9f..5727d2c 100644 --- a/src/main/java/net/pietru/cookie_utils/api/Region.java +++ b/src/main/java/net/pietru/cookie_utils/api/Region.java @@ -173,6 +173,8 @@ public class Region { perms.set_bool_perm("explode", region.getBoolean("explode", false)); perms.set_bool_perm("enter", region.getBoolean("enter", true)); perms.set_bool_perm("spawn_mob", region.getBoolean("spawn_mob", true)); + + perms.set_bool_perm("pvp", region.getBoolean("pvp", false)); } diff --git a/src/main/java/net/pietru/cookie_utils/mixins/InteractBlockMixin.java b/src/main/java/net/pietru/cookie_utils/mixins/InteractBlockMixin.java index 1b1fb2b..4d8bf54 100644 --- a/src/main/java/net/pietru/cookie_utils/mixins/InteractBlockMixin.java +++ b/src/main/java/net/pietru/cookie_utils/mixins/InteractBlockMixin.java @@ -36,13 +36,15 @@ public class InteractBlockMixin { private void event_block_interact(CallbackInfo ci, @Local NetworkIdentity identity, @Local ChannelHandlerContext ctx){ if (identity.getSide() != NetworkSide.CLIENT) { Account account = ServerSingletons.getAccount(identity); - BlockPosition temp = blockPos.copy(); - temp.convertToLocal(identity.getZone()); - if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_edit_block(temp,"interact",account.getUniqueId())) { - ci.cancel(); + if (blockPos!=null) { + BlockPosition temp = blockPos.copy(); + temp.convertToLocal(identity.getZone()); + if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_edit_block(temp, "interact", account.getUniqueId())) { + ci.cancel(); - MessagePacket packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but this area is under protection." : "Sorry but you can't do this action right now. [Config Reload In Progress]")); - packet.setupAndSend(ctx); + MessagePacket packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but this area is under protection." : "Sorry but you can't do this action right now. [Config Reload In Progress]")); + packet.setupAndSend(ctx); + } } } } diff --git a/src/main/java/net/pietru/cookie_utils/mixins/PlayerEntityMixin.java b/src/main/java/net/pietru/cookie_utils/mixins/PlayerEntityMixin.java new file mode 100644 index 0000000..fbafeda --- /dev/null +++ b/src/main/java/net/pietru/cookie_utils/mixins/PlayerEntityMixin.java @@ -0,0 +1,33 @@ +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.player.PlayerEntity; +import finalforeach.cosmicreach.networking.packets.MessagePacket; +import finalforeach.cosmicreach.networking.server.ServerSingletons; +import net.pietru.cookie_utils.permissions.Permissions; +import org.spongepowered.asm.mixin.Mixin; +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.*; + +@Mixin(PlayerEntity.class) +public class PlayerEntityMixin { + + @Inject(method = "onAttackInteraction", at = @At("HEAD"), cancellable = true) + private void event_player_attack(CallbackInfo ci, @Local Entity sourceEntity){ + if (sourceEntity instanceof PlayerEntity){ + Account account = ((PlayerEntity) sourceEntity).player.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).player)); + } + } + } +} 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 f97944a..2f0941f 100644 --- a/src/main/java/net/pietru/cookie_utils/permissions/ObjectPermList.java +++ b/src/main/java/net/pietru/cookie_utils/permissions/ObjectPermList.java @@ -1,6 +1,7 @@ package net.pietru.cookie_utils.permissions; import com.badlogic.gdx.utils.JsonValue; +import finalforeach.cosmicreach.settings.ServerSettings; import java.util.HashMap; import java.util.Map; @@ -37,6 +38,8 @@ public class ObjectPermList { val.addChild("explode", new JsonValue(false)); val.addChild("enter", new JsonValue(true)); val.addChild("spawn_mob", new JsonValue(false)); + + val.addChild("pvp", new JsonValue(false)); } public static void get_default_perms(ObjectPermList val){ @@ -47,5 +50,7 @@ public class ObjectPermList { val.set_bool_perm("explode", false); val.set_bool_perm("enter", true); val.set_bool_perm("spawn_mob", false); + + val.set_bool_perm("pvp", false); } } diff --git a/src/main/java/net/pietru/cookie_utils/setups/areaPermSetup.java b/src/main/java/net/pietru/cookie_utils/setups/areaPermSetup.java index 6aa908c..4132b3d 100644 --- a/src/main/java/net/pietru/cookie_utils/setups/areaPermSetup.java +++ b/src/main/java/net/pietru/cookie_utils/setups/areaPermSetup.java @@ -73,6 +73,7 @@ public class areaPermSetup extends Setup { plr_perm.perms.set_bool_perm("break", target); plr_perm.perms.set_bool_perm("interact", target); plr_perm.perms.set_bool_perm("enter", target); + plr_perm.perms.set_bool_perm("pvp", target); break; case "edit","e": plr_perm.perms.set_bool_perm("place", target); @@ -84,6 +85,9 @@ public class areaPermSetup extends Setup { case "enter","m": plr_perm.perms.set_bool_perm("enter", target); break; + case "pvp","p": + plr_perm.perms.set_bool_perm("pvp", target); + break; } run_setup_finish(); diff --git a/src/main/resources/cookie_utils.mixins.json b/src/main/resources/cookie_utils.mixins.json index c3d2ffc..c5fbd01 100644 --- a/src/main/resources/cookie_utils.mixins.json +++ b/src/main/resources/cookie_utils.mixins.json @@ -14,7 +14,8 @@ "PlayerPositionMixin", "NettyServerMixin", "ServerSingletonsMixin", - "BlockEntitySignMixin" + "BlockEntitySignMixin", + "PlayerEntityMixin" ], "client": [], "injectors": {