This commit is contained in:
parent
b48f3dbe19
commit
d547ca167a
4 changed files with 53 additions and 31 deletions
|
@ -5,6 +5,8 @@ import finalforeach.cosmicreach.GameAssetLoader;
|
||||||
import finalforeach.cosmicreach.blockevents.BlockEvents;
|
import finalforeach.cosmicreach.blockevents.BlockEvents;
|
||||||
import finalforeach.cosmicreach.blocks.Block;
|
import finalforeach.cosmicreach.blocks.Block;
|
||||||
import dev.crmodders.cosmicquilt.api.entrypoint.ModInitializer;
|
import dev.crmodders.cosmicquilt.api.entrypoint.ModInitializer;
|
||||||
|
import net.pietru.cookie_utils.api.Region;
|
||||||
|
import net.pietru.cookie_utils.permissions.Permissions;
|
||||||
import org.quiltmc.loader.api.ModContainer;
|
import org.quiltmc.loader.api.ModContainer;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -17,29 +19,38 @@ public class CookieUtils implements ModInitializer {
|
||||||
//if (QuiltLoader.isModLoaded("becraft"))
|
//if (QuiltLoader.isModLoaded("becraft"))
|
||||||
System.out.println("CookieUtils Mod/Plugin Initialized!");
|
System.out.println("CookieUtils Mod/Plugin Initialized!");
|
||||||
|
|
||||||
List<String> paths = List.of(Gdx.files.internal(MOD_ID + "/assets.txt").readString().split("\n"));
|
Permissions.reload_perm_groups();
|
||||||
for (String path : paths){
|
System.out.println("CookieUtils loaded perm groups...");
|
||||||
if (path.contains("block_events")) {
|
|
||||||
System.out.println("Loading " + path);
|
Permissions.reload_player_groups(true);
|
||||||
BlockEvents.loadBlockEventsFromAsset(GameAssetLoader.loadAsset(path)); //Gdx.files.classpath(path)
|
System.out.println("CookieUtils loaded player groups...");
|
||||||
}
|
|
||||||
}
|
Region.reload_regions();
|
||||||
|
System.out.println("CookieUtils loaded perm groups...");
|
||||||
System.out.println("Registered CookieUtils Events");
|
|
||||||
|
// List<String> paths = List.of(Gdx.files.internal(MOD_ID + "/assets.txt").readString().split("\n"));
|
||||||
|
// for (String path : paths){
|
||||||
System.out.println("Registered CookieUtils Entities");
|
// if (path.contains("block_events")) {
|
||||||
|
// System.out.println("Loading " + path);
|
||||||
for (String block:blocks) {
|
// BlockEvents.loadBlockEventsFromAsset(GameAssetLoader.loadAsset(path)); //Gdx.files.classpath(path)
|
||||||
System.out.println(block);
|
// }
|
||||||
try {
|
// }
|
||||||
Block.loadBlock(GameAssetLoader.loadAsset("cookie_utils:blocks/"+block+".json"));
|
//
|
||||||
} catch (Exception var3) {
|
// System.out.println("Registered CookieUtils Events");
|
||||||
throw new RuntimeException("Error parsing block: " + block, var3);
|
//
|
||||||
}
|
//
|
||||||
}
|
// System.out.println("Registered CookieUtils Entities");
|
||||||
|
//
|
||||||
System.out.println("Registered CookieUtils Blocks");
|
// for (String block:blocks) {
|
||||||
|
// System.out.println(block);
|
||||||
|
// try {
|
||||||
|
// Block.loadBlock(GameAssetLoader.loadAsset("cookie_utils:blocks/"+block+".json"));
|
||||||
|
// } catch (Exception var3) {
|
||||||
|
// throw new RuntimeException("Error parsing block: " + block, var3);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// System.out.println("Registered CookieUtils Blocks");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class TextCommands {
|
||||||
if (args.length==2)
|
if (args.length==2)
|
||||||
started = Setup.start(account.getUniqueId(),args[1]);
|
started = Setup.start(account.getUniqueId(),args[1]);
|
||||||
|
|
||||||
MessagePacket packet = new MessagePacket(started ? "Starting setup.." : "Failed to start setup...");
|
MessagePacket packet = new MessagePacket(started ? "[Server] Starting setup.." : "[Server] Failed to start setup...");
|
||||||
packet.playerUniqueId=account.getUniqueId();
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
packet.setupAndSend(channelHandlerContext);
|
packet.setupAndSend(channelHandlerContext);
|
||||||
|
|
||||||
|
@ -94,14 +94,25 @@ public class TextCommands {
|
||||||
});
|
});
|
||||||
|
|
||||||
commands.put("group",(args, networkIdentity, channelHandlerContext) -> {
|
commands.put("group",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
|
MessagePacket packet=null;
|
||||||
if (args.length==4) {
|
if (args.length==4) {
|
||||||
if (Objects.equals(args[1], "set"))
|
if (Objects.equals(args[1], "set")) {
|
||||||
Permissions.set_group(args[2],args[3]);
|
boolean res = Permissions.set_group(args[2], args[3]);
|
||||||
|
packet = new MessagePacket(res ? "Group set for user..." : "Failed to set group for user...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (args.length==3) {
|
else if (args.length==3) {
|
||||||
if (Objects.equals(args[1], "clear"))
|
if (Objects.equals(args[1], "clear")) {
|
||||||
Permissions.clear_group(args[2]);
|
Permissions.clear_group(args[2]);
|
||||||
|
packet = new MessagePacket("[Server] If user had perm it was cleared...");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packet==null)
|
||||||
|
return;
|
||||||
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
|
packet.setupAndSend(channelHandlerContext);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ public class ServerSingletonsMixin {
|
||||||
|
|
||||||
@Inject(method = "create", at = @At("HEAD"))
|
@Inject(method = "create", at = @At("HEAD"))
|
||||||
private static void on_singletons_create(CallbackInfo ci){
|
private static void on_singletons_create(CallbackInfo ci){
|
||||||
Permissions.reload_perm_groups();
|
// Permissions.reload_perm_groups();
|
||||||
Permissions.reload_player_groups(true);
|
// Permissions.reload_player_groups(true);
|
||||||
Region.reload_regions();
|
// Region.reload_regions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,9 @@ public class Permissions {
|
||||||
static Map<String,String> player_group = new HashMap<>();
|
static Map<String,String> player_group = new HashMap<>();
|
||||||
|
|
||||||
public static void reload_player_groups(boolean load){
|
public static void reload_player_groups(boolean load){
|
||||||
groupPermsMap.clear();
|
|
||||||
|
|
||||||
File def = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"player_groups.json"));
|
File def = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"player_groups.json"));
|
||||||
if (load && def.exists()) {
|
if (load && def.exists()) {
|
||||||
|
//player_group.clear();
|
||||||
try {
|
try {
|
||||||
player_group = json.fromJson(HashMap.class, Gdx.files.absolute(def.getPath()));
|
player_group = json.fromJson(HashMap.class, Gdx.files.absolute(def.getPath()));
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
@ -114,11 +113,12 @@ public class Permissions {
|
||||||
return has_user_special_perm(playerId) || group.has_perm(perm);
|
return has_user_special_perm(playerId) || group.has_perm(perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void set_group(String playerId,String group){
|
public static boolean set_group(String playerId,String group){
|
||||||
if (!groupPermsMap.containsKey(group))
|
if (!groupPermsMap.containsKey(group))
|
||||||
return;
|
return false;
|
||||||
player_group.put(playerId,group);
|
player_group.put(playerId,group);
|
||||||
reload_player_groups(false);
|
reload_player_groups(false);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clear_group(String playerId){
|
public static void clear_group(String playerId){
|
||||||
|
|
Loading…
Reference in a new issue