add self_claim signs
Some checks failed
/ Auto-Build-App (push) Has been cancelled

This commit is contained in:
pietru 2024-12-29 14:08:47 +01:00
parent 27dd4a0fcb
commit 454647c599
6 changed files with 120 additions and 4 deletions

View file

@ -9,9 +9,9 @@ group=net.pietru
id=cookie_utils id=cookie_utils
# Dependency Versions # Dependency Versions
cosmic_reach_version=0.3.12 cosmic_reach_version=0.3.14
# If unspecified, will use the version above # If unspecified, will use the version above
cosmic_reach_server_version=0.3.12 cosmic_reach_server_version=0.3.14
cosmic_quilt_version=2.3.1 cosmic_quilt_version=2.3.1
#2.2.0 #2.2.0

View file

@ -48,6 +48,10 @@ public class Area {
return space.contains(c); return space.contains(c);
} }
public boolean does_intersect(BoundingBox c){
return space.contains(c);
}
public boolean get_action_bool(String action,String player_id){ public boolean get_action_bool(String action,String player_id){
if (is_plr_valid(player_id)) if (is_plr_valid(player_id))
for (int i = 0; i < player_perms.size; i++) { for (int i = 0; i < player_perms.size; i++) {

View file

@ -114,6 +114,16 @@ public class Region {
return null; return null;
} }
public static int get_owned_areas(String playerId){
int c = 0;
for (int i = 0; i< areas.size; i++){
Area a = areas.get(i);
if (a.enabled && a.is_user_type(playerId,"Owner"))
c++;
}
return c;
}
public static void reload_regions(){ public static void reload_regions(){
is_not_reloading=false; is_not_reloading=false;

View file

@ -95,13 +95,18 @@ public class TextCommands {
packet.setupAndSend(channelHandlerContext); packet.setupAndSend(channelHandlerContext);
}); });
commands.put("my_area",(args, networkIdentity, channelHandlerContext) -> { commands.put("my_area",(args, networkIdentity, channelHandlerContext) -> {
Account account = ServerSingletons.getAccount(networkIdentity);
Player plr = ServerSingletons.getPlayer(networkIdentity); Player plr = ServerSingletons.getPlayer(networkIdentity);
Area area = get_area_at_pos(plr.getPosition(), plr.getZone()); Area area = get_area_at_pos(plr.getPosition(), plr.getZone());
MessagePacket packet = new MessagePacket("[Server] You are in "+(area!=null?area.name : "no area atm...")); MessagePacket packet = new MessagePacket("[Server] You are in "+(area!=null?area.name : "no area atm..."));
packet.setupAndSend(channelHandlerContext); packet.setupAndSend(channelHandlerContext);
}); });
commands.put("my_claims",(args, networkIdentity, channelHandlerContext) -> {
Account account = ServerSingletons.getAccount(networkIdentity);
MessagePacket packet = new MessagePacket("[Server] You have "+Region.get_owned_areas(account.getUniqueId())+" claims...");
packet.setupAndSend(channelHandlerContext);
});
commands.put("setup",(args, networkIdentity, channelHandlerContext) -> { commands.put("setup",(args, networkIdentity, channelHandlerContext) -> {
Account account = ServerSingletons.getAccount(networkIdentity); Account account = ServerSingletons.getAccount(networkIdentity);
boolean cancel = false; boolean cancel = false;

View file

@ -0,0 +1,96 @@
package net.pietru.cookie_utils.mixins;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.BoundingBox;
import com.llamalad7.mixinextras.sugar.Local;
import finalforeach.cosmicreach.blockentities.BlockEntitySign;
import finalforeach.cosmicreach.entities.player.Player;
import finalforeach.cosmicreach.networking.packets.MessagePacket;
import finalforeach.cosmicreach.networking.server.ServerSingletons;
import finalforeach.cosmicreach.world.Zone;
import net.pietru.cookie_utils.api.Area;
import net.pietru.cookie_utils.api.Region;
import net.pietru.cookie_utils.permissions.ObjectPermList;
import net.pietru.cookie_utils.permissions.Permissions;
import net.pietru.cookie_utils.permissions.PlayerAreaPerm;
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;
@Mixin(BlockEntitySign.class)
public class BlockEntitySignMixin {
@Shadow
private String[] texts = new String[]{"", "", "", "", ""};
@Shadow
Zone zone;
@Shadow
int x;
@Shadow
int y;
@Shadow
int z;
@Inject(method = "onInteract", at = @At("HEAD"), cancellable = true)
private void event_onInteract(CallbackInfo ci, @Local Player player, @Local Zone zone){
if (texts[0].equals("[CLAIM]") && texts[2].isEmpty() && !player.isProne) {
String ownerId = player.getAccount().getUniqueId();
int c = Region.get_owned_areas(ownerId);
if (Permissions.has_perm(ownerId,"claims.limit."+(c+1))) {
int size = isInt(texts[1]) ? Math.max(Math.min(Integer.parseInt(texts[1]), 15), 2) : 15;
Vector3 ca = new Vector3(x - size, y - size, z - size);
Vector3 cb = new Vector3(x + size, y + size, z + size);
BoundingBox test = new BoundingBox(ca,cb);
boolean can_claim = true;
for (int i = 0; (i< Region.areas.size && can_claim); i++){
Area a = Region.areas.get(i);
if (a.piority>=0 && a.does_intersect(test)) {
can_claim=false;
}
}
ci.cancel();
if (can_claim) {
Area area = new Area();
area.enabled = true;
ObjectPermList.get_default_perms(area.perms);
area.setCorners(ca, cb);
area.name = "self_claim_sign_" + ownerId.replace(":", "_") + ".json";
area.zoneId = zone.zoneId;
PlayerAreaPerm plr_perm = PlayerAreaPerm.get_owner_perm(ownerId);
area.player_perms.add(plr_perm);
area.save(false);
plr_perm.save(area, false);
Region.areas.add(area);
Region.sort_areas();
if (area.parent.isEmpty())
Region.load_area_player_perms(area);
MessagePacket packet = new MessagePacket("[Server] Successfully claimed area of size "+size+" (size*2+1)");
packet.setupAndSend(ServerSingletons.getConnection(player));
} else {
MessagePacket packet = new MessagePacket("[Server] Area of size "+size+" intersects another protected area...");
packet.setupAndSend(ServerSingletons.getConnection(player));
}
} else {
MessagePacket packet = new MessagePacket("[Server] Sorry, but you can't claim more land...");
packet.setupAndSend(ServerSingletons.getConnection(player));
}
}
}
public static boolean isInt(String str) {
try {
Integer.parseInt(str);
return true;
} catch(NumberFormatException e){
return false;
}
}
}

View file

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