add pvp protect for areas, bugfix blockPos in oninteract event?
Some checks failed
/ Auto-Build-App (push) Failing after 3m1s

This commit is contained in:
pietru 2025-01-09 11:31:02 +01:00
parent 5d75207b39
commit 8b377e21cb
6 changed files with 54 additions and 7 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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();

View file

@ -14,7 +14,8 @@
"PlayerPositionMixin",
"NettyServerMixin",
"ServerSingletonsMixin",
"BlockEntitySignMixin"
"BlockEntitySignMixin",
"PlayerEntityMixin"
],
"client": [],
"injectors": {