add my_rank cmd
All checks were successful
/ Auto-Build-App (push) Successful in 2m11s

This commit is contained in:
pietru 2024-11-09 16:03:42 +01:00
parent aa975490e0
commit 0f15395ceb
3 changed files with 31 additions and 21 deletions

View file

@ -12,6 +12,7 @@ import finalforeach.cosmicreach.savelib.utils.TriConsumer;
import finalforeach.cosmicreach.world.Zone;
import finalforeach.cosmicreach.worldgen.ZoneGenerator;
import io.netty.channel.ChannelHandlerContext;
import net.pietru.cookie_utils.permissions.GroupPerms;
import net.pietru.cookie_utils.permissions.Permissions;
import net.pietru.cookie_utils.setups.Setup;
@ -48,46 +49,49 @@ public class TextCommands {
commands.put("help",(args, networkIdentity, channelHandlerContext) -> {
Account account = ServerSingletons.getAccount(networkIdentity);
MessagePacket packet;
packet = new MessagePacket("You have access to following commands:");
packet.playerUniqueId=account.getUniqueId();
packet = new MessagePacket("[Server] You have access to following commands:");
packet.setupAndSend(channelHandlerContext);
for (String cmd : commands.keySet()){
if (!has_perm(account.getUniqueId(),cmd))
continue;
packet = new MessagePacket(" - "+cmd);
packet.playerUniqueId=account.getUniqueId();
packet.setupAndSend(channelHandlerContext);
}
});
commands.put("my_rank",(args, networkIdentity, channelHandlerContext) -> {
Account account = ServerSingletons.getAccount(networkIdentity);
MessagePacket packet;
GroupPerms groupPerms = Permissions.get_group(account.getUniqueId());
packet = new MessagePacket("[Server] Your rank is "+groupPerms.group_DisplayName);
packet.setupAndSend(channelHandlerContext);
packet = new MessagePacket(groupPerms.group_Desc);
packet.setupAndSend(channelHandlerContext);
});
commands.put("gpos",(args, networkIdentity, channelHandlerContext) -> {
Player player = ServerSingletons.getPlayer(networkIdentity);
Account account = ServerSingletons.getAccount(networkIdentity);
Vector3 pos = player.getPosition();
MessagePacket packet = new MessagePacket("You are at "+(int)pos.x+" "+(int)pos.y+" "+(int)pos.z);
packet.playerUniqueId=account.getUniqueId();
MessagePacket packet = new MessagePacket("[Server] You are at "+(int)pos.x+" "+(int)pos.y+" "+(int)pos.z);
packet.setupAndSend(channelHandlerContext);
});
commands.put("my_zone",(args, networkIdentity, channelHandlerContext) -> {
Player player = ServerSingletons.getPlayer(networkIdentity);
Account account = ServerSingletons.getAccount(networkIdentity);
MessagePacket packet = new MessagePacket("You are in "+player.zoneId);
packet.playerUniqueId=account.getUniqueId();
MessagePacket packet = new MessagePacket("[Server] You are in "+player.zoneId);
packet.setupAndSend(channelHandlerContext);
});
commands.put("my_id",(args, networkIdentity, channelHandlerContext) -> {
Account account = ServerSingletons.getAccount(networkIdentity);
MessagePacket packet = new MessagePacket("Your id is "+account.getUniqueId());
packet.playerUniqueId=account.getUniqueId();
MessagePacket packet = new MessagePacket("[Server] Your id is "+account.getUniqueId());
packet.setupAndSend(channelHandlerContext);
});
commands.put("my_name",(args, networkIdentity, channelHandlerContext) -> {
Account account = ServerSingletons.getAccount(networkIdentity);
MessagePacket packet = new MessagePacket("Your name is "+account.getUsername());
packet.playerUniqueId=account.getUniqueId();
MessagePacket packet = new MessagePacket("[Server] Your name is "+account.getUsername());
packet.setupAndSend(channelHandlerContext);
});
commands.put("my_area",(args, networkIdentity, channelHandlerContext) -> {
@ -95,8 +99,7 @@ public class TextCommands {
Player plr = ServerSingletons.getPlayer(networkIdentity);
Area area = get_area_at_pos(plr.getPosition(), plr.getZone());
MessagePacket packet = new MessagePacket("You are in "+(area!=null?area.name : "no area atm..."));
packet.playerUniqueId=account.getUniqueId();
MessagePacket packet = new MessagePacket("[Server] You are in "+(area!=null?area.name : "no area atm..."));
packet.setupAndSend(channelHandlerContext);
});
commands.put("setup",(args, networkIdentity, channelHandlerContext) -> {
@ -113,12 +116,10 @@ public class TextCommands {
}
MessagePacket packet = new MessagePacket(started ? "[Server] Starting setup.." : "[Server] Failed to start setup... (There might be one running)");
packet.playerUniqueId=account.getUniqueId();
packet.setupAndSend(channelHandlerContext);
if (started){
packet = new MessagePacket(Setup.setups.get(account.getUniqueId()).get_step_hint());
packet.playerUniqueId=account.getUniqueId();
packet.setupAndSend(channelHandlerContext);
}
});
@ -189,7 +190,6 @@ public class TextCommands {
}
packet.playerUniqueId=account.getUniqueId();
packet.setupAndSend(channelHandlerContext);
});
@ -245,10 +245,10 @@ public class TextCommands {
}
if (player!=null && zone!=null){
txt="[server] Sended "+player.getAccount().getDisplayName()+" to zone "+zoneId;
txt="[Server] Sended "+player.getAccount().getDisplayName()+" to zone "+zoneId;
Zone old = player.getZone();
if (old.zoneId.equals(zoneId)) {
txt = "[server] Player " + player.getAccount().getDisplayName() + " is already in zone " + zoneId;
txt = "[Server] Player " + player.getAccount().getDisplayName() + " is already in zone " + zoneId;
}else {
zone.addPlayer(player);
player.setZone(zoneId);
@ -297,7 +297,6 @@ public class TextCommands {
if (packet==null)
return;
packet.playerUniqueId=account.getUniqueId();
packet.setupAndSend(channelHandlerContext);
});
@ -315,7 +314,6 @@ public class TextCommands {
if (packet==null)
return;
Account account = ServerSingletons.getAccount(networkIdentity);
packet.playerUniqueId=account.getUniqueId();
packet.setupAndSend(channelHandlerContext);
});
@ -323,7 +321,6 @@ public class TextCommands {
MessagePacket packet = new MessagePacket("Reloaded groups...");
reload_perm_groups();
Account account = ServerSingletons.getAccount(networkIdentity);
packet.playerUniqueId=account.getUniqueId();
packet.setupAndSend(channelHandlerContext);
});
}

View file

@ -4,6 +4,8 @@ import java.util.ArrayList;
public class GroupPerms {
public String group_id = "";
public String group_DisplayName = "";
public String group_Desc = "";
public ArrayList<String> perms = new ArrayList<>();
public boolean has_perm(String perm){
@ -13,8 +15,11 @@ public class GroupPerms {
public static GroupPerms get_default_perms(){
GroupPerms val = new GroupPerms();
val.group_id="default";
val.group_DisplayName="Default Group";
val.group_Desc="The default user rank...";
val.perms.add("help");
val.perms.add("gpos");
val.perms.add("my_rank");
val.perms.add("my_zone");
val.perms.add("my_id");
val.perms.add("my_name");

View file

@ -115,6 +115,14 @@ public class Permissions {
return has_user_special_perm(playerId) || group.has_perm(perm) || group.has_perm("*");
}
public static GroupPerms get_group(String playerId){
GroupPerms group = default_group;
if (player_group.containsKey(playerId))
if (groupPermsMap.containsKey(player_group.get(playerId)))
group=groupPermsMap.get(player_group.get(playerId));
return group;
}
public static boolean set_group(String playerId,String group){
if (!groupPermsMap.containsKey(group) || !is_plr_valid(playerId))
return false;