add canEnter checks for Regions
All checks were successful
/ Auto-Build-App (push) Successful in 1m34s
All checks were successful
/ Auto-Build-App (push) Successful in 1m34s
This commit is contained in:
parent
2256d3d9c7
commit
a9319d96ac
4 changed files with 93 additions and 14 deletions
|
@ -12,6 +12,7 @@ public class Area {
|
|||
public boolean canBreak = false;
|
||||
public boolean canInteract = false;
|
||||
public boolean canExplode = false;
|
||||
public boolean canEnter = true;
|
||||
|
||||
public int piority = 0;
|
||||
|
||||
|
@ -32,17 +33,14 @@ public class Area {
|
|||
}
|
||||
|
||||
public boolean get_action_bool(String action){
|
||||
switch (action){
|
||||
case "place":
|
||||
return canPlace;
|
||||
case "break":
|
||||
return canBreak;
|
||||
case "interact":
|
||||
return canInteract;
|
||||
case "explode":
|
||||
return canExplode;
|
||||
}
|
||||
return false;
|
||||
return switch (action) {
|
||||
case "place" -> canPlace;
|
||||
case "break" -> canBreak;
|
||||
case "interact" -> canInteract;
|
||||
case "explode" -> canExplode;
|
||||
case "move" -> canEnter;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,13 +6,11 @@ import com.badlogic.gdx.utils.Array;
|
|||
import com.badlogic.gdx.utils.JsonReader;
|
||||
import com.badlogic.gdx.utils.JsonValue;
|
||||
import com.badlogic.gdx.utils.Sort;
|
||||
import finalforeach.cosmicreach.GameAssetLoader;
|
||||
import finalforeach.cosmicreach.blocks.BlockPosition;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import finalforeach.cosmicreach.world.Zone;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class Region {
|
||||
|
||||
|
@ -37,6 +35,20 @@ public class Region {
|
|||
return can;
|
||||
}
|
||||
|
||||
public static boolean can_enter_position(Vector3 position,String action){
|
||||
boolean can = is_not_reloading;
|
||||
|
||||
if (is_not_reloading)
|
||||
for (Area a : areas){
|
||||
if (a.enabled && a.does_intersect(position)){
|
||||
can=a.get_action_bool(action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return can;
|
||||
}
|
||||
|
||||
public static void reload_regions(){
|
||||
is_not_reloading=false;
|
||||
|
||||
|
@ -77,6 +89,7 @@ public class Region {
|
|||
area.canInteract=region.getBoolean("canInteract",false);
|
||||
|
||||
area.canExplode=region.getBoolean("canExplode",false);
|
||||
area.canEnter=region.getBoolean("canEnter",true);
|
||||
|
||||
|
||||
area.piority=region.getInt("piority",0);
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
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.blocks.BlockPosition;
|
||||
import finalforeach.cosmicreach.blocks.BlockState;
|
||||
import finalforeach.cosmicreach.entities.Entity;
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.networking.common.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.common.NetworkSide;
|
||||
import finalforeach.cosmicreach.networking.netty.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.netty.packets.PlayerPositionPacket;
|
||||
import finalforeach.cosmicreach.networking.netty.packets.blocks.PlaceBlockPacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import finalforeach.cosmicreach.world.Zone;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.api.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 java.util.ConcurrentModificationException;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.*;
|
||||
|
||||
@Mixin(PlayerPositionPacket.class)
|
||||
public class PlayerPositionMixin {
|
||||
@Shadow
|
||||
public String playerUniqueId;
|
||||
@Shadow
|
||||
public String zoneId;
|
||||
@Shadow
|
||||
public Vector3 position;
|
||||
@Shadow
|
||||
public Vector3 viewDir;
|
||||
@Shadow
|
||||
public Vector3 viewDirOff;
|
||||
|
||||
@Inject(method = "handle", at = @At("HEAD"), cancellable = true)
|
||||
private void event_player_move(CallbackInfo ci, @Local NetworkIdentity identity, @Local ChannelHandlerContext ctx){
|
||||
if (identity.getSide() != NetworkSide.CLIENT) {
|
||||
Account account = ServerSingletons.getAccount(identity);
|
||||
if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_enter_position(position,"move")) {
|
||||
ci.cancel();
|
||||
|
||||
Player player = ServerSingletons.getPlayer(identity);
|
||||
Entity e = player.getEntity();
|
||||
e.viewDirection.set(this.viewDir);
|
||||
e.viewPositionOffset.set(this.viewDirOff);
|
||||
|
||||
Vector3 new_pos = player.getPosition().cpy().sub(position);
|
||||
|
||||
PlayerPositionPacket plr_packet = new PlayerPositionPacket(player);
|
||||
plr_packet.position.add(new_pos);
|
||||
plr_packet.playerUniqueId=account.getUniqueId();
|
||||
plr_packet.setupAndSend(ctx);
|
||||
|
||||
MessagePacket msg_packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but you can't enter this area." : "Sorry but you can't do this action right now. [Config Reload In Progress]"));
|
||||
msg_packet.playerUniqueId=account.getUniqueId();
|
||||
msg_packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,8 @@
|
|||
"InteractBlockMixin",
|
||||
"MessagePacketMixin",
|
||||
"ServerSingletonsMixin",
|
||||
"BlockActionExplodeMixin"
|
||||
"BlockActionExplodeMixin",
|
||||
"PlayerPositionMixin"
|
||||
],
|
||||
"client": [],
|
||||
"injectors": {
|
||||
|
|
Loading…
Reference in a new issue