add one region reload, example perm file for areas, fixes
All checks were successful
/ Auto-Build-App (push) Successful in 1m37s
All checks were successful
/ Auto-Build-App (push) Successful in 1m37s
This commit is contained in:
parent
8f9957921b
commit
87894d545e
5 changed files with 76 additions and 37 deletions
|
@ -32,12 +32,13 @@ public class Area {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean get_action_bool(String action,String player_id){
|
public boolean get_action_bool(String action,String player_id){
|
||||||
for (int i = 0; i < player_perms.size; i++) {
|
if (!player_id.contains("offline"))
|
||||||
PlayerAreaPerm p = player_perms.get(i);
|
for (int i = 0; i < player_perms.size; i++) {
|
||||||
if (p.enabled && !p.player_id.isEmpty() && p.player_id.equals(player_id)){
|
PlayerAreaPerm p = player_perms.get(i);
|
||||||
return player_perms.get(i).get_action_bool(action);
|
if (p.enabled && !p.player_id.isEmpty() && p.player_id.equals(player_id)){
|
||||||
|
return player_perms.get(i).get_action_bool(action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return perms.get_bool_perm(action,false);
|
return perms.get_bool_perm(action,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,13 @@ public class ObjectPermList {
|
||||||
return bool_perms.getOrDefault(key,def_val);
|
return bool_perms.getOrDefault(key,def_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Json get_default_perms(){
|
public static JsonValue get_default_perms(JsonValue val){
|
||||||
Json val = new Json();
|
val.addChild("canPlace", new JsonValue(false));
|
||||||
val.writeValue("canPlace", false);
|
val.addChild("canBreak", new JsonValue(false));
|
||||||
val.writeValue("canBreak", false);
|
val.addChild("canInteract", new JsonValue(false));
|
||||||
val.writeValue("canInteract", false);
|
|
||||||
|
|
||||||
val.writeValue("canExplode", false);
|
val.addChild("canExplode", new JsonValue(false));
|
||||||
val.writeValue("canEnter", true);
|
val.addChild("canEnter", new JsonValue(true));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.pietru.cookie_utils.api;
|
package net.pietru.cookie_utils.api;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.Json;
|
import com.badlogic.gdx.utils.Json;
|
||||||
|
import com.badlogic.gdx.utils.JsonValue;
|
||||||
|
|
||||||
public class PlayerAreaPerm {
|
public class PlayerAreaPerm {
|
||||||
public String player_id = "";
|
public String player_id = "";
|
||||||
|
@ -11,10 +12,11 @@ public class PlayerAreaPerm {
|
||||||
return perms.get_bool_perm(action,false);
|
return perms.get_bool_perm(action,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Json get_default_perms(){
|
public static JsonValue get_default_perms(){
|
||||||
Json val = ObjectPermList.get_default_perms();
|
JsonValue val = new JsonValue(JsonValue.ValueType.object);
|
||||||
val.writeValue("player_id", "");
|
val.addChild("player_id", new JsonValue(""));
|
||||||
val.writeValue("enabled", true);
|
val.addChild("enabled", new JsonValue(true));
|
||||||
|
ObjectPermList.get_default_perms(val);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class Region {
|
||||||
perms.set_bool_perm("interact", region.getBoolean("canInteract", false));
|
perms.set_bool_perm("interact", region.getBoolean("canInteract", false));
|
||||||
|
|
||||||
perms.set_bool_perm("explode", region.getBoolean("canExplode", false));
|
perms.set_bool_perm("explode", region.getBoolean("canExplode", false));
|
||||||
perms.set_bool_perm("move", region.getBoolean("canEnter", false));
|
perms.set_bool_perm("move", region.getBoolean("canEnter", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +121,9 @@ public class Region {
|
||||||
|
|
||||||
areas.add(area);
|
areas.add(area);
|
||||||
|
|
||||||
|
if (area.parent.isEmpty())
|
||||||
|
load_area_player_perms(area);
|
||||||
|
|
||||||
System.out.println("[REGIONS] Loaded region file \"%s\"".replace("%s", area.name));
|
System.out.println("[REGIONS] Loaded region file \"%s\"".replace("%s", area.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,6 +135,7 @@ public class Region {
|
||||||
Area parent_area = areas.get(j);
|
Area parent_area = areas.get(j);
|
||||||
if (parent_area.name.equals(area.parent)) {
|
if (parent_area.name.equals(area.parent)) {
|
||||||
area.perms = parent_area.perms;
|
area.perms = parent_area.perms;
|
||||||
|
area.player_perms = parent_area.player_perms;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,53 +150,70 @@ public class Region {
|
||||||
System.out.println("[REGIONS] Loaded %s areas.".replace("%s",String.valueOf(areas.size)));
|
System.out.println("[REGIONS] Loaded %s areas.".replace("%s",String.valueOf(areas.size)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload_regions(Area area){
|
public static void reload_area_player_perms(String area_name){
|
||||||
|
for (int i = 0; i < areas.size; i++) {
|
||||||
|
Area area = areas.get(i);
|
||||||
|
if (area.name.equals(area_name)) {
|
||||||
|
load_area_player_perms(area);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void load_area_player_perms(Area area){
|
||||||
area.player_perms.clear();
|
area.player_perms.clear();
|
||||||
|
|
||||||
File perms_folder = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"region_perms", area.name));
|
File perms_folder = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"region_perms", area.name));
|
||||||
if (!perms_folder.exists()) {
|
if (!perms_folder.exists()) {
|
||||||
perms_folder.mkdirs();
|
perms_folder.mkdirs();
|
||||||
try {
|
|
||||||
Json def = PlayerAreaPerm.get_default_perms();
|
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(get_path_string(perms_folder.getPath(),"example.json")));
|
|
||||||
writer.write(def.prettyPrint(JsonWriter.OutputType.json));
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
File[] perms = perms_folder.listFiles(((dir, name) -> name.endsWith(".json")));
|
File[] perms = perms_folder.listFiles(((dir, name) -> name.endsWith(".json")));
|
||||||
if (perms!=null) {
|
if (perms!=null) {
|
||||||
System.out.println("[AREA] Trying to load %s perms.".replace("%s",String.valueOf(perms.length)));
|
System.out.println("[AREA] Trying to load %s perms.".replace("%s",String.valueOf(perms.length)));
|
||||||
for (File f : perms) {
|
for (File f : perms) {
|
||||||
JsonValue region;
|
JsonValue perm_json;
|
||||||
try {
|
try {
|
||||||
region=jsonReader.parse(Gdx.files.absolute(f.getPath()));
|
perm_json=jsonReader.parse(Gdx.files.absolute(f.getPath()));
|
||||||
} catch (Exception ignored){
|
} catch (Exception ignored){
|
||||||
System.out.println("[AREA] Perms file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
System.out.println("[AREA] Perms file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
PlayerAreaPerm perm = new PlayerAreaPerm();
|
PlayerAreaPerm perm = new PlayerAreaPerm();
|
||||||
|
|
||||||
perm.player_id=region.getString("player_id", "");
|
perm.player_id=perm_json.getString("player_id", "");
|
||||||
if (perm.player_id.isEmpty())
|
if (perm.player_id.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
perm.enabled=region.getBoolean("enabled", false);
|
perm.enabled=perm_json.getBoolean("enabled", false);
|
||||||
|
|
||||||
|
|
||||||
ObjectPermList player_perms = perm.perms;
|
ObjectPermList player_perms = perm.perms;
|
||||||
|
|
||||||
player_perms.set_bool_perm("place", region.getBoolean("canPlace", false));
|
player_perms.set_bool_perm("place", perm_json.getBoolean("canPlace", false));
|
||||||
player_perms.set_bool_perm("break", region.getBoolean("canBreak", false));
|
player_perms.set_bool_perm("break", perm_json.getBoolean("canBreak", false));
|
||||||
player_perms.set_bool_perm("interact", region.getBoolean("canInteract", false));
|
player_perms.set_bool_perm("interact", perm_json.getBoolean("canInteract", false));
|
||||||
|
|
||||||
player_perms.set_bool_perm("explode", region.getBoolean("canExplode", false));
|
player_perms.set_bool_perm("explode", perm_json.getBoolean("canExplode", false));
|
||||||
player_perms.set_bool_perm("move", region.getBoolean("canEnter", false));
|
player_perms.set_bool_perm("move", perm_json.getBoolean("canEnter", false));
|
||||||
|
|
||||||
|
|
||||||
area.player_perms.add(perm);
|
area.player_perms.add(perm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
Json json = new Json();
|
||||||
|
json.setOutputType(JsonWriter.OutputType.json);
|
||||||
|
JsonValue def = PlayerAreaPerm.get_default_perms();
|
||||||
|
String txt = def.toString();
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(get_path_string(perms_folder.getPath(),"example.json")));
|
||||||
|
writer.write(json.prettyPrint(txt));
|
||||||
|
writer.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("[REGIONS] Loaded %s permissions.".replace("%s",String.valueOf(areas.size)));
|
System.out.println("[REGIONS] Loaded %s permissions.".replace("%s",String.valueOf(areas.size)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static net.pietru.cookie_utils.api.Region.reload_area_player_perms;
|
||||||
import static net.pietru.cookie_utils.api.Region.reload_regions;
|
import static net.pietru.cookie_utils.api.Region.reload_regions;
|
||||||
|
|
||||||
public class TextCommands {
|
public class TextCommands {
|
||||||
|
@ -40,15 +41,30 @@ public class TextCommands {
|
||||||
Player player = ServerSingletons.getPlayer(networkIdentity);
|
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
|
|
||||||
Vector3 pos = player.getPosition();
|
|
||||||
MessagePacket packet = new MessagePacket("You are in "+player.zoneId);
|
MessagePacket packet = new MessagePacket("You are in "+player.zoneId);
|
||||||
packet.playerUniqueId=account.getUniqueId();
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
packet.setupAndSend(channelHandlerContext);
|
packet.setupAndSend(channelHandlerContext);
|
||||||
});
|
});
|
||||||
commands.put("reload_regions",(args, networkIdentity, channelHandlerContext) -> {
|
commands.put("my_id",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
reload_regions();
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
|
|
||||||
|
MessagePacket packet = new MessagePacket("Your id is "+account.getUniqueId());
|
||||||
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
|
packet.setupAndSend(channelHandlerContext);
|
||||||
|
});
|
||||||
|
commands.put("reload_regions",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
|
MessagePacket packet = null;
|
||||||
|
if (args.length==1) {
|
||||||
|
reload_regions();
|
||||||
|
packet = new MessagePacket("Reloaded regions...");
|
||||||
|
}
|
||||||
|
if (args.length==2) {
|
||||||
|
reload_area_player_perms(args[1]);
|
||||||
|
packet = new MessagePacket("Reloaded %s area...".replace("%s", args[1]));
|
||||||
|
}
|
||||||
|
if (packet==null)
|
||||||
|
return;
|
||||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
MessagePacket packet = new MessagePacket("Reloaded regions...");
|
|
||||||
packet.playerUniqueId=account.getUniqueId();
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
packet.setupAndSend(channelHandlerContext);
|
packet.setupAndSend(channelHandlerContext);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue