Area MultiZone support
All checks were successful
/ Auto-Build-App (push) Successful in 1m29s

This commit is contained in:
pietru 2024-11-04 21:20:51 +01:00
parent 9f032739db
commit 23cc2c8582
5 changed files with 14 additions and 10 deletions

View file

@ -21,6 +21,7 @@ public class Area {
BoundingBox space = new BoundingBox(); BoundingBox space = new BoundingBox();
public String name = "none"; public String name = "none";
public String zoneId = "";
public String parent = ""; public String parent = "";
public boolean enabled = true; public boolean enabled = true;
public boolean protect = false; public boolean protect = false;

View file

@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.*; import com.badlogic.gdx.utils.*;
import finalforeach.cosmicreach.blocks.BlockPosition; import finalforeach.cosmicreach.blocks.BlockPosition;
import finalforeach.cosmicreach.io.SaveLocation; import finalforeach.cosmicreach.io.SaveLocation;
import finalforeach.cosmicreach.networking.server.ServerSingletons;
import finalforeach.cosmicreach.world.Zone; import finalforeach.cosmicreach.world.Zone;
import net.pietru.cookie_utils.permissions.ObjectPermList; import net.pietru.cookie_utils.permissions.ObjectPermList;
import net.pietru.cookie_utils.permissions.PlayerAreaPerm; import net.pietru.cookie_utils.permissions.PlayerAreaPerm;
@ -29,7 +30,7 @@ public class Region {
if (is_not_reloading) if (is_not_reloading)
for (Area a : areas){ for (Area a : areas){
if (a.enabled && a.does_intersect(g_position)){ if (a.enabled && (z.zoneId.isEmpty() || z.zoneId.equals(a.zoneId)) && a.does_intersect(g_position)){
can=a.get_action_bool(action,player_id); can=a.get_action_bool(action,player_id);
break; break;
} }
@ -46,7 +47,7 @@ public class Region {
if (is_not_reloading) if (is_not_reloading)
for (int i = 0; i< areas.size; i++){ for (int i = 0; i< areas.size; i++){
Area a = areas.get(i); Area a = areas.get(i);
if (a.enabled && a.does_intersect(g_position)){ if (a.enabled && (z.zoneId.isEmpty() || z.zoneId.equals(a.zoneId)) && a.does_intersect(g_position)){
can=a.get_action_bool(action); can=a.get_action_bool(action);
break; break;
} }
@ -57,11 +58,12 @@ public class Region {
public static boolean can_enter_position(Vector3 position,String action,String player_id){ public static boolean can_enter_position(Vector3 position,String action,String player_id){
boolean can = is_not_reloading; boolean can = is_not_reloading;
Zone z = ServerSingletons.getAccountByUniqueId(player_id).getPlayer().getZone();
if (is_not_reloading) if (is_not_reloading)
for (int i = 0; i< areas.size; i++){ for (int i = 0; i< areas.size; i++){
Area a = areas.get(i); Area a = areas.get(i);
if (a.enabled && a.does_intersect(position)){ if (a.enabled && (z.zoneId.isEmpty() || z.zoneId.equals(a.zoneId)) && a.does_intersect(position)){
can=a.get_action_bool(action,player_id); can=a.get_action_bool(action,player_id);
break; break;
} }
@ -70,13 +72,13 @@ public class Region {
return can; return can;
} }
public static boolean can_enter_position(Vector3 position,String action){ public static boolean can_enter_position(Vector3 position,String action, Zone z){
boolean can = is_not_reloading; boolean can = is_not_reloading;
if (is_not_reloading) if (is_not_reloading)
for (int i = 0; i< areas.size; i++){ for (int i = 0; i< areas.size; i++){
Area a = areas.get(i); Area a = areas.get(i);
if (a.enabled && a.does_intersect(position)){ if (a.enabled && (z.zoneId.isEmpty() || z.zoneId.equals(a.zoneId)) && a.does_intersect(position)){
can=a.get_action_bool(action); can=a.get_action_bool(action);
break; break;
} }
@ -100,11 +102,11 @@ public class Region {
return can; return can;
} }
public static Area get_area_at_pos(Vector3 position){ public static Area get_area_at_pos(Vector3 position, Zone z){
if (is_not_reloading) if (is_not_reloading)
for (int i = 0; i< areas.size; i++){ for (int i = 0; i< areas.size; i++){
Area a = areas.get(i); Area a = areas.get(i);
if (a.enabled && a.does_intersect(position)){ if (a.enabled && (z.zoneId.isEmpty() || z.zoneId.equals(a.zoneId)) && a.does_intersect(position)){
return a; return a;
} }
} }
@ -149,6 +151,7 @@ public class Region {
area.enabled=region.getBoolean("enabled",true); area.enabled=region.getBoolean("enabled",true);
area.protect=region.getBoolean("protect",false); area.protect=region.getBoolean("protect",false);
area.zoneId = region.getString("zoneId","");
area.parent = region.getString("parent",""); area.parent = region.getString("parent","");
if (area.parent.isEmpty()) { if (area.parent.isEmpty()) {
ObjectPermList perms = area.perms; ObjectPermList perms = area.perms;

View file

@ -88,7 +88,7 @@ public class TextCommands {
commands.put("my_area",(args, networkIdentity, channelHandlerContext) -> { commands.put("my_area",(args, networkIdentity, channelHandlerContext) -> {
Account account = ServerSingletons.getAccount(networkIdentity); Account account = ServerSingletons.getAccount(networkIdentity);
Player plr = ServerSingletons.getPlayer(networkIdentity); Player plr = ServerSingletons.getPlayer(networkIdentity);
Area area = get_area_at_pos(plr.getPosition()); Area area = get_area_at_pos(plr.getPosition(), plr.getZone());
MessagePacket packet = new MessagePacket("You are in "+(area!=null?area.name : "no area atm...")); MessagePacket packet = new MessagePacket("You are in "+(area!=null?area.name : "no area atm..."));
packet.playerUniqueId=account.getUniqueId(); packet.playerUniqueId=account.getUniqueId();

View file

@ -22,7 +22,7 @@ public class MobSpawnerMixin {
@Inject(method = "spawnMob", at = @At("HEAD"), cancellable = true) @Inject(method = "spawnMob", at = @At("HEAD"), cancellable = true)
private void event_spawnMob(CallbackInfo ci, @Local Zone zone){ private void event_spawnMob(CallbackInfo ci, @Local Zone zone){
if (!can_enter_position(tmpSpawnPackLoc,"spawn_mob")) { if (!can_enter_position(tmpSpawnPackLoc,"spawn_mob", zone)) {
++numberOfMobs; ++numberOfMobs;
ci.cancel(); ci.cancel();
} }

View file

@ -34,7 +34,7 @@ public class areaPermSetup extends Setup {
@Override @Override
public boolean can_start_setup(String playerId) { public boolean can_start_setup(String playerId) {
Player player = GameSingletons.getPlayerFromUniqueId(playerId); Player player = GameSingletons.getPlayerFromUniqueId(playerId);
area=get_area_at_pos(player.getPosition()); area=get_area_at_pos(player.getPosition(), player.getZone());
return area!=null&&Region.is_area_user_type(player.getPosition(),playerId,"Owner"); return area!=null&&Region.is_area_user_type(player.getPosition(),playerId,"Owner");
} }