add more options to config, add logging levels
All checks were successful
/ Auto-Build-App (push) Successful in 1m22s
All checks were successful
/ Auto-Build-App (push) Successful in 1m22s
This commit is contained in:
parent
fb67da4535
commit
899c6be294
9 changed files with 102 additions and 39 deletions
|
@ -6,8 +6,11 @@ import net.pietru.cookie_utils.api.Region;
|
|||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
import net.pietru.cookie_utils.scripting.ScriptsDB;
|
||||
import net.pietru.cookie_utils.setups.setupCreator;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
import org.quiltmc.loader.api.ModContainer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CookieUtils implements ModInitializer {
|
||||
public static final String MOD_ID = "cookie_utils";
|
||||
public static final String[] blocks = {};
|
||||
|
@ -15,7 +18,14 @@ public class CookieUtils implements ModInitializer {
|
|||
public void onInitialize(ModContainer mod) {
|
||||
System.out.println("CookieUtils Mod/Plugin Initialized!");
|
||||
|
||||
Permissions.reload_perm_groups();
|
||||
try {
|
||||
prop.load_panel_config();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println("CookieUtils loaded config...");
|
||||
|
||||
Permissions.reload_perm_groups();
|
||||
System.out.println("CookieUtils loaded perm groups...");
|
||||
|
||||
Permissions.reload_player_groups(true);
|
||||
|
|
|
@ -10,6 +10,7 @@ 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 net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
|
@ -143,22 +144,26 @@ public class Region {
|
|||
if (!regions_folder.exists())
|
||||
regions_folder.mkdirs();
|
||||
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())));
|
||||
if (prop.log_level>-1)
|
||||
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.err.println("[REGIONS] Region file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
if (prop.log_level>0)
|
||||
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.err.println("[REGIONS] Region file \"%s\" missing x1, y1 or z1.".replace("%s", f.getPath()));
|
||||
if (prop.log_level>0)
|
||||
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.err.println("[REGIONS] Region file \"%s\" missing x2, y2 or z2.".replace("%s", f.getPath()));
|
||||
if (prop.log_level>0)
|
||||
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"));
|
||||
|
@ -204,7 +209,8 @@ public class Region {
|
|||
if (area.parent.isEmpty())
|
||||
load_area_player_perms(area);
|
||||
|
||||
System.out.println("[REGIONS] Loaded region file \"%s\"".replace("%s", area.name));
|
||||
if (prop.log_level>0)
|
||||
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);
|
||||
|
@ -223,7 +229,8 @@ public class Region {
|
|||
|
||||
is_not_reloading=true;
|
||||
|
||||
System.out.println("[REGIONS] Loaded %s areas.".replace("%s",String.valueOf(areas.size)));
|
||||
if (prop.log_level>-1)
|
||||
System.out.println("[REGIONS] Loaded %s areas.".replace("%s",String.valueOf(areas.size)));
|
||||
}
|
||||
|
||||
public static void sort_areas(){
|
||||
|
@ -268,7 +275,8 @@ public class Region {
|
|||
}
|
||||
|
||||
ArrayList<File> perms = directory_utils.list_files_in_dir_recursive(perms_folder,((dir, name) -> name.endsWith(".json")));
|
||||
System.out.println("[AREA] Trying to load %s perms.".replace("%s", String.valueOf(perms.size())));
|
||||
if (prop.log_level>1)
|
||||
System.out.println("[AREA] Trying to load %s perms.".replace("%s", String.valueOf(perms.size())));
|
||||
for (File f : perms) {
|
||||
if (f.getName().equals("example.json"))
|
||||
continue;
|
||||
|
@ -276,11 +284,13 @@ public class Region {
|
|||
try {
|
||||
perm_json=jsonReader.parse(Gdx.files.absolute(f.getPath()));
|
||||
} catch (Exception ignored){
|
||||
System.err.println("[AREA] Perms file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
if (prop.log_level>0)
|
||||
System.err.println("[AREA] Perms file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
if (perm_json==null){
|
||||
System.err.println("[AREA] Perms file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
if (prop.log_level>0)
|
||||
System.err.println("[AREA] Perms file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -311,6 +321,7 @@ public class Region {
|
|||
area.player_perms.add(perm);
|
||||
}
|
||||
|
||||
System.out.println("[AREA] Loaded %s permissions.".replace("%s",String.valueOf(area.player_perms.size)));
|
||||
if (prop.log_level>1)
|
||||
System.out.println("[AREA] Loaded %s permissions.".replace("%s",String.valueOf(area.player_perms.size)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import net.pietru.cookie_utils.permissions.GroupPerms;
|
|||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
import net.pietru.cookie_utils.setups.Setup;
|
||||
import net.pietru.cookie_utils.utils.ParticleUtil;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
|
@ -371,14 +372,22 @@ public class TextCommands {
|
|||
commands.put("reload",(args, networkIdentity, channelHandlerContext) -> {
|
||||
List<String> arg_list = Arrays.stream(args).toList();
|
||||
String reloaded_funcs = "";
|
||||
if (arg_list.contains("scripts") || args.length==1) {
|
||||
reload_scripts();
|
||||
reloaded_funcs+="scripts ";
|
||||
if (arg_list.contains("config") || args.length==1) {
|
||||
try {
|
||||
prop.load_panel_config();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
reloaded_funcs+="config ";
|
||||
}
|
||||
if (arg_list.contains("groups") || args.length==1) {
|
||||
reload_perm_groups();
|
||||
reloaded_funcs+="groups ";
|
||||
}
|
||||
if (arg_list.contains("scripts") || args.length==1) {
|
||||
reload_scripts();
|
||||
reloaded_funcs+="scripts ";
|
||||
}
|
||||
if (arg_list.contains("regions") || args.length==1) {
|
||||
reload_regions();
|
||||
reloaded_funcs+="regions ";
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||
import net.pietru.cookie_utils.api.TextCommands;
|
||||
import net.pietru.cookie_utils.setups.Setup;
|
||||
import net.pietru.cookie_utils.utils.MessageInfo;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
@ -31,16 +32,16 @@ public class MessagePacketMixin {
|
|||
|
||||
@Inject(method = "handle", at = @At("HEAD"), cancellable = true)
|
||||
private void event_on_message(CallbackInfo ci, @Local NetworkIdentity identity, @Local ChannelHandlerContext ctx){
|
||||
if (ply_msgs.containsKey(playerUniqueId)){
|
||||
if (((boolean)prop.panel_prop.getOrDefault("chat_shadow_enabled",true)) && ply_msgs.containsKey(playerUniqueId)){
|
||||
MessageInfo msg = ply_msgs.get(playerUniqueId);
|
||||
long time = System.currentTimeMillis();
|
||||
if (msg.last_msg+msg.msg_delay>time || (msg.last_msg_txt.equals(message) && msg.last_msg+msg.msg_delay*2>time)) {
|
||||
msg.msg_delay += 500;
|
||||
msg.msg_delay += Integer.parseInt((String) prop.panel_prop.getOrDefault("chat_shadow_delay",500));
|
||||
if (msg.msg_delay>10000)
|
||||
msg.msg_delay=10000;
|
||||
ci.cancel();
|
||||
} else {
|
||||
msg.msg_delay = 500;
|
||||
msg.msg_delay = Integer.parseInt((String) prop.panel_prop.getOrDefault("chat_shadow_delay",500));
|
||||
msg.last_msg_txt = message;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ 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 net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
|
@ -36,7 +37,8 @@ public class Permissions {
|
|||
try {
|
||||
player_group = json.fromJson(HashMap.class, Gdx.files.absolute(def.getPath()));
|
||||
} catch (Exception ignored) {
|
||||
System.err.println("[GROUPS] Encountered exception while loading player groups...");
|
||||
if (prop.log_level>0)
|
||||
System.err.println("[GROUPS] Encountered exception while loading player groups...");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -52,7 +54,8 @@ public class Permissions {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("[GROUPS] Saved player groups.");
|
||||
if (prop.log_level>0)
|
||||
System.out.println("[GROUPS] Saved player groups.");
|
||||
}
|
||||
|
||||
public static void reload_perm_groups(){
|
||||
|
@ -64,13 +67,15 @@ public class Permissions {
|
|||
}
|
||||
File def = new File(get_path_string(perms_folder.getPath(),"default.json"));
|
||||
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())));
|
||||
if (prop.log_level>0)
|
||||
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.err.println("[GROUPS] Perm group file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
if (prop.log_level>0)
|
||||
System.err.println("[GROUPS] Perm group file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -100,7 +105,8 @@ public class Permissions {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("[GROUPS] Loaded %s permissions.".replace("%s",String.valueOf(groupPermsMap.size())));
|
||||
if (prop.log_level>0)
|
||||
System.out.println("[GROUPS] Loaded %s permissions.".replace("%s",String.valueOf(groupPermsMap.size())));
|
||||
}
|
||||
|
||||
public static boolean has_perm(String playerId,String perm){
|
||||
|
@ -160,7 +166,8 @@ public class Permissions {
|
|||
|
||||
public static void generate_new_code(){
|
||||
code = generateRandomString(6);
|
||||
System.out.println("[Permissions] New perm code is %s".replace("%s",code));
|
||||
if (prop.log_level>-2)
|
||||
System.out.println("[Permissions] New perm code is %s".replace("%s",code));
|
||||
// Create a new Thread object
|
||||
t = new Thread(new Delay(60,"reset_permission_code"));
|
||||
|
||||
|
@ -170,7 +177,8 @@ public class Permissions {
|
|||
|
||||
public static void check_code_and_add_user(String cd, String playerId){
|
||||
if (playerUniqueIds.contains(playerId,false)) {
|
||||
System.out.println("[Permissions] Player %s tried re-verificate too early...".replace("%s", playerId));
|
||||
if (prop.log_level>-2)
|
||||
System.out.println("[Permissions] Player %s tried re-verificate too early...".replace("%s", playerId));
|
||||
return;
|
||||
}
|
||||
if (code.isEmpty())
|
||||
|
@ -179,7 +187,8 @@ public class Permissions {
|
|||
return;
|
||||
t.interrupt();
|
||||
code="";
|
||||
System.out.println("[Permissions] Player %s passed verification...".replace("%s",playerId));
|
||||
if (prop.log_level>-2)
|
||||
System.out.println("[Permissions] Player %s passed verification...".replace("%s",playerId));
|
||||
Map<String,String> data = new HashMap<>();
|
||||
data.put("id",playerId);
|
||||
Thread player_t = new Thread(new Delay(60*2,"revoke_usr_perm",data));
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.pietru.cookie_utils.scripting;
|
|||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import net.pietru.cookie_utils.scripting.tokens.*;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -124,10 +125,12 @@ public class BaseScript {
|
|||
}
|
||||
i+=valid_tokens;
|
||||
} else {
|
||||
System.err.printf("[SCRIPTS] Script file \"%s\" failed to parse token \"%s\" at line %d with token %d.\n", name, code_tokens[i], line_counter,i+1);
|
||||
if (prop.log_level>-1)
|
||||
System.err.printf("[SCRIPTS] Script file \"%s\" failed to parse token \"%s\" at line %d with token %d.\n", name, code_tokens[i], line_counter,i+1);
|
||||
}
|
||||
} else {
|
||||
System.err.printf("[SCRIPTS] Script file \"%s\" unknown token \"%s\" at line %d with token %d.\n", name, code_tokens[i],line_counter,i+1);
|
||||
if (prop.log_level>-1)
|
||||
System.err.printf("[SCRIPTS] Script file \"%s\" unknown token \"%s\" at line %d with token %d.\n", name, code_tokens[i],line_counter,i+1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -147,12 +150,14 @@ public class BaseScript {
|
|||
if (baseToken.handle(code_tokens,i,context)){
|
||||
i+=baseToken.next_token(code_tokens,i);
|
||||
} else {
|
||||
System.err.printf("[SCRIPTS] Script file \"%s\" failed to handle token \"%s\" of event %s at token %d.\n", name, code_tokens[i], event,i+1);
|
||||
if (prop.log_level>-1)
|
||||
System.err.printf("[SCRIPTS] Script file \"%s\" failed to handle token \"%s\" of event %s at token %d.\n", name, code_tokens[i], event,i+1);
|
||||
code_event_fails.put(event,code_event_fails.getOrDefault(event,0)+1);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
System.err.printf("[SCRIPTS] Script file \"%s\" unknown token \"%s\" at line %s with token %d.\n", name, code_tokens[i], event,i+1);
|
||||
if (prop.log_level>-1)
|
||||
System.err.printf("[SCRIPTS] Script file \"%s\" unknown token \"%s\" at line %s with token %d.\n", name, code_tokens[i], event,i+1);
|
||||
code_event_fails.put(event,code_event_fails.getOrDefault(event,0)+1);
|
||||
i++;
|
||||
}
|
||||
|
@ -160,7 +165,8 @@ public class BaseScript {
|
|||
}
|
||||
|
||||
public static void log_token_error(BaseToken token, String msg){
|
||||
System.err.printf("[SCRIPTS][%s] %s\n", token.get_token_checker_id(),msg);
|
||||
if (prop.log_level>-1)
|
||||
System.err.printf("[SCRIPTS][%s] %s\n", token.get_token_checker_id(),msg);
|
||||
}
|
||||
|
||||
public static ArrayList<String> get_string(String[] tokens, int step){
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.pietru.cookie_utils.scripting;
|
|||
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import net.pietru.cookie_utils.utils.directory_utils;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -31,7 +32,8 @@ public class ScriptsDB {
|
|||
scripts_folder.mkdirs();
|
||||
ArrayList<File> scripts = directory_utils.list_files_in_dir_recursive(scripts_folder,((dir, name) -> name.endsWith(".ck")));
|
||||
|
||||
System.out.println("[SCRIPTS] Trying to load %s scripts.".replace("%s", String.valueOf(scripts.size())));
|
||||
if (prop.log_level>0)
|
||||
System.out.println("[SCRIPTS] Trying to load %s scripts.".replace("%s", String.valueOf(scripts.size())));
|
||||
for (File f : scripts) {
|
||||
BaseScript script = new BaseScript();
|
||||
|
||||
|
@ -42,17 +44,20 @@ public class ScriptsDB {
|
|||
try {
|
||||
script.parse_file(f);
|
||||
} catch (Exception ignored) {
|
||||
System.err.println("[SCRIPTS] Script file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
if (prop.log_level>0)
|
||||
System.err.println("[SCRIPTS] Script file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
|
||||
scripts_storage.put(script.name, script);
|
||||
|
||||
System.out.println("[SCRIPTS] Loaded script file \"%s\"".replace("%s", script.name));
|
||||
if (prop.log_level>1)
|
||||
System.out.println("[SCRIPTS] Loaded script file \"%s\"".replace("%s", script.name));
|
||||
}
|
||||
|
||||
is_not_reloading = true;
|
||||
|
||||
System.out.println("[SCRIPTS] Loaded %s scripts.".replace("%s", String.valueOf(scripts_storage.size())));
|
||||
if (prop.log_level>0)
|
||||
System.out.println("[SCRIPTS] Loaded %s scripts.".replace("%s", String.valueOf(scripts_storage.size())));
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import finalforeach.cosmicreach.entities.player.Player;
|
|||
import finalforeach.cosmicreach.world.Zone;
|
||||
import net.pietru.cookie_utils.scripting.BaseScript;
|
||||
import net.pietru.cookie_utils.scripting.ExecutionContext;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import static net.pietru.cookie_utils.permissions.Permissions.has_perm;
|
||||
import static net.pietru.cookie_utils.utils.player_utils.parseAsPlayer;
|
||||
|
@ -55,11 +56,13 @@ public class TokenSwitchZone implements BaseToken {
|
|||
old.removePlayer(player);
|
||||
}
|
||||
|
||||
// System.out.println("--------------------------");
|
||||
// System.out.println("Player "+player.getUsername());
|
||||
// System.out.println("Old "+old.zoneId);
|
||||
// System.out.println("New "+zone.zoneId);
|
||||
// System.out.println("--------------------------");
|
||||
if (prop.log_level>2) {
|
||||
System.out.println("--------------------------");
|
||||
System.out.println("Player " + player.getUsername());
|
||||
System.out.println("Old " + old.zoneId);
|
||||
System.out.println("New " + zone.zoneId);
|
||||
System.out.println("--------------------------");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
|||
public class prop {
|
||||
static File config_file = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"config", "cookie.config"));
|
||||
public static Properties panel_prop;
|
||||
public static int log_level = 1;
|
||||
|
||||
public static ArrayList<String> get_server_property_array(String key, Object defaultValue) throws IOException {
|
||||
String txt = (String) get_server_property(key,defaultValue);
|
||||
|
@ -56,6 +57,14 @@ public class prop {
|
|||
if (!panel_prop.containsKey("zones")){
|
||||
panel_prop.put("zones",new ArrayList<String>()); save=true;}
|
||||
|
||||
if (!panel_prop.containsKey("chat_shadow_enabled")){
|
||||
panel_prop.put("chat_shadow_enabled",true); save=true;}
|
||||
if (!panel_prop.containsKey("chat_shadow_delay")){
|
||||
panel_prop.put("chat_shadow_delay",500); save=true;}
|
||||
if (!panel_prop.containsKey("log_level")){
|
||||
panel_prop.put("log_level",1); save=true;}
|
||||
log_level = (int) panel_prop.getOrDefault("log_level",1);
|
||||
|
||||
if (save)
|
||||
panel_prop.store(new FileWriter(config_file.toString()), "This file is CookieServerUtils config file.");
|
||||
|
||||
|
|
Loading…
Reference in a new issue