This commit is contained in:
parent
c8143a139e
commit
564fa502f6
4 changed files with 108 additions and 84 deletions
|
@ -23,6 +23,7 @@ public class Area {
|
|||
public String name = "none";
|
||||
public String zoneId = "";
|
||||
public String parent = "";
|
||||
public String scriptFile = "";
|
||||
public boolean enabled = true;
|
||||
public boolean protect = false;
|
||||
public ObjectPermList perms = new ObjectPermList();
|
||||
|
@ -96,6 +97,7 @@ public class Area {
|
|||
val.addChild("protect", new JsonValue(protect));
|
||||
val.addChild("zoneId", new JsonValue(zoneId));
|
||||
val.addChild("parent", new JsonValue(parent));
|
||||
val.addChild("scriptFile", new JsonValue(scriptFile));
|
||||
perms.get_json(val);
|
||||
val.addChild("piority", new JsonValue(piority));
|
||||
return val;
|
||||
|
|
|
@ -9,10 +9,12 @@ import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
|||
import finalforeach.cosmicreach.world.Zone;
|
||||
import net.pietru.cookie_utils.permissions.ObjectPermList;
|
||||
import net.pietru.cookie_utils.permissions.PlayerAreaPerm;
|
||||
import net.pietru.cookie_utils.utils.directory_utils;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
||||
|
||||
|
@ -124,6 +126,14 @@ public class Region {
|
|||
return c;
|
||||
}
|
||||
|
||||
public static Area get_area(String area_name){
|
||||
for (Area a : areas){
|
||||
if (a.name.equals(area_name))
|
||||
return a;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void reload_regions(){
|
||||
is_not_reloading=false;
|
||||
|
||||
|
@ -132,24 +142,23 @@ public class Region {
|
|||
File regions_folder = new File(SaveLocation.getSaveFolder(),"regions");
|
||||
if (!regions_folder.exists())
|
||||
regions_folder.mkdirs();
|
||||
File[] regions = regions_folder.listFiles(((dir, name) -> name.endsWith(".json")));
|
||||
if (regions!=null) {
|
||||
System.out.println("[REGIONS] Trying to load %s areas.".replace("%s",String.valueOf(regions.length)));
|
||||
ArrayList<File> regions = directory_utils.list_files_in_dir_recursive(regions_folder,((dir, name) -> name.endsWith(".json")));
|
||||
System.out.println("[REGIONS] Trying to load %s areas.".replace("%s", String.valueOf(regions.size())));
|
||||
for (File f : regions) {
|
||||
JsonValue region;
|
||||
try {
|
||||
region=jsonReader.parse(Gdx.files.absolute(f.getPath()));
|
||||
} catch (Exception ignored){
|
||||
System.out.println("[REGIONS] Region file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
System.err.println("[REGIONS] Region file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
Area area = new Area();
|
||||
if (!region.has("x1") || !region.has("y1") || !region.has("z1")) {
|
||||
System.out.println("[REGIONS] Region file \"%s\" missing x1, y1 or z1.".replace("%s", f.getPath()));
|
||||
System.err.println("[REGIONS] Region file \"%s\" missing x1, y1 or z1.".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
if (!region.has("x2") || !region.has("y2") || !region.has("z2")) {
|
||||
System.out.println("[REGIONS] Region file \"%s\" missing x2, y2 or z2.".replace("%s", f.getPath()));
|
||||
System.err.println("[REGIONS] Region file \"%s\" missing x2, y2 or z2.".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
Vector3 a = new Vector3(region.getFloat("x1"), region.getFloat("y1"), region.getFloat("z1"));
|
||||
|
@ -163,6 +172,9 @@ public class Region {
|
|||
|
||||
area.zoneId = region.getString("zoneId","");
|
||||
area.parent = region.getString("parent","");
|
||||
|
||||
area.scriptFile = region.getString("scriptFile","");
|
||||
|
||||
if (area.parent.isEmpty()) {
|
||||
ObjectPermList perms = area.perms;
|
||||
|
||||
|
@ -187,7 +199,6 @@ public class Region {
|
|||
|
||||
System.out.println("[REGIONS] Loaded region file \"%s\"".replace("%s", area.name));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < areas.size; i++) {
|
||||
Area area = areas.get(i);
|
||||
if (area.parent.isEmpty())
|
||||
|
@ -236,15 +247,15 @@ public class Region {
|
|||
if (!perms_folder.exists()) {
|
||||
perms_folder.mkdirs();
|
||||
}
|
||||
File[] perms = perms_folder.listFiles(((dir, name) -> name.endsWith(".json")));
|
||||
ArrayList<File> perms = directory_utils.list_files_in_dir_recursive(perms_folder,((dir, name) -> name.endsWith(".json")));
|
||||
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.size())));
|
||||
for (File f : perms) {
|
||||
JsonValue perm_json;
|
||||
try {
|
||||
perm_json=jsonReader.parse(Gdx.files.absolute(f.getPath()));
|
||||
} catch (Exception ignored){
|
||||
System.out.println("[AREA] Perms file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
System.err.println("[AREA] Perms file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
PlayerAreaPerm perm = new PlayerAreaPerm();
|
||||
|
|
|
@ -6,14 +6,12 @@ import com.badlogic.gdx.utils.Json;
|
|||
import com.badlogic.gdx.utils.JsonWriter;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import net.pietru.cookie_utils.api.Delay;
|
||||
import net.pietru.cookie_utils.utils.directory_utils;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
||||
import static net.pietru.cookie_utils.utils.player_utils.is_plr_valid;
|
||||
|
@ -38,7 +36,7 @@ public class Permissions {
|
|||
try {
|
||||
player_group = json.fromJson(HashMap.class, Gdx.files.absolute(def.getPath()));
|
||||
} catch (Exception ignored) {
|
||||
System.out.println("[GROUPS] Encountered exception while loading player groups...");
|
||||
System.err.println("[GROUPS] Encountered exception while loading player groups...");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -65,15 +63,14 @@ public class Permissions {
|
|||
perms_folder.mkdirs();
|
||||
}
|
||||
File def = new File(get_path_string(perms_folder.getPath(),"default.json"));
|
||||
File[] perms = perms_folder.listFiles(((dir, name) -> name.endsWith(".json")));
|
||||
if (perms!=null) {
|
||||
System.out.println("[GROUPS] Trying to load %s perm groups.".replace("%s",String.valueOf(perms.length)));
|
||||
ArrayList<File> perms = directory_utils.list_files_in_dir_recursive(perms_folder,((dir, name) -> name.endsWith(".json")));
|
||||
System.out.println("[GROUPS] Trying to load %s perm groups.".replace("%s", String.valueOf(perms.size())));
|
||||
for (File f : perms) {
|
||||
GroupPerms group;
|
||||
try {
|
||||
group=json.fromJson(GroupPerms.class,Gdx.files.absolute(f.getPath()));
|
||||
} catch (Exception ignored){
|
||||
System.out.println("[GROUPS] Perm group file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
System.err.println("[GROUPS] Perm group file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -88,7 +85,6 @@ public class Permissions {
|
|||
|
||||
groupPermsMap.put(group.group_id,group);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,10 +1,25 @@
|
|||
package net.pietru.cookie_utils.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class directory_utils {
|
||||
|
||||
public static String get_path_string(String ...path_parts){
|
||||
return String.join(File.separator, path_parts);
|
||||
}
|
||||
|
||||
public static ArrayList<File> list_files_in_dir_recursive(File dir, FilenameFilter filter){
|
||||
ArrayList<File> files = new ArrayList<>();
|
||||
File[] files_lst = dir.listFiles();
|
||||
if (files_lst!=null)
|
||||
for (File sub_thing : files_lst) {
|
||||
if (sub_thing.isDirectory())
|
||||
files.addAll(list_files_in_dir_recursive(sub_thing, filter));
|
||||
else if ((filter == null) || filter.accept(dir,sub_thing.getName()))
|
||||
files.add(sub_thing);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue