add experimental zone loading...
This commit is contained in:
parent
d778a57348
commit
fdbe58fc9a
3 changed files with 133 additions and 0 deletions
|
@ -2,16 +2,23 @@ package net.pietru.cookie_utils;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import finalforeach.cosmicreach.GameAssetLoader;
|
import finalforeach.cosmicreach.GameAssetLoader;
|
||||||
|
import finalforeach.cosmicreach.GameSingletons;
|
||||||
|
import finalforeach.cosmicreach.ZoneLoaders;
|
||||||
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 finalforeach.cosmicreach.world.Zone;
|
||||||
import net.pietru.cookie_utils.api.Region;
|
import net.pietru.cookie_utils.api.Region;
|
||||||
import net.pietru.cookie_utils.permissions.Permissions;
|
import net.pietru.cookie_utils.permissions.Permissions;
|
||||||
import net.pietru.cookie_utils.setups.setupCreator;
|
import net.pietru.cookie_utils.setups.setupCreator;
|
||||||
|
import net.pietru.cookie_utils.utils.prop;
|
||||||
import org.quiltmc.loader.api.ModContainer;
|
import org.quiltmc.loader.api.ModContainer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static net.pietru.cookie_utils.utils.prop.get_server_property_array;
|
||||||
|
|
||||||
public class CookieUtils implements ModInitializer {
|
public class CookieUtils implements ModInitializer {
|
||||||
public static final String MOD_ID = "cookie_utils";
|
public static final String MOD_ID = "cookie_utils";
|
||||||
public static final String[] blocks = {};
|
public static final String[] blocks = {};
|
||||||
|
@ -32,6 +39,20 @@ public class CookieUtils implements ModInitializer {
|
||||||
setupCreator.registerSetupCreators();
|
setupCreator.registerSetupCreators();
|
||||||
System.out.println("CookieUtils loaded setup creators...");
|
System.out.println("CookieUtils loaded setup creators...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ArrayList<String> zones = get_server_property_array("zones","[]");
|
||||||
|
for (String zoneId : zones){
|
||||||
|
Zone z = GameSingletons.world.getZoneIfExists(zoneId);
|
||||||
|
if (z == null && GameSingletons.isHost) {
|
||||||
|
z = Zone.loadZone(GameSingletons.world, zoneId);
|
||||||
|
GameSingletons.world.addZone(z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("CookieUtils loaded setup creators...");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
// List<String> paths = List.of(Gdx.files.internal(MOD_ID + "/assets.txt").readString().split("\n"));
|
// List<String> paths = List.of(Gdx.files.internal(MOD_ID + "/assets.txt").readString().split("\n"));
|
||||||
// for (String path : paths){
|
// for (String path : paths){
|
||||||
// if (path.contains("block_events")) {
|
// if (path.contains("block_events")) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.pietru.cookie_utils.api;
|
package net.pietru.cookie_utils.api;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import finalforeach.cosmicreach.GameSingletons;
|
||||||
import finalforeach.cosmicreach.accounts.Account;
|
import finalforeach.cosmicreach.accounts.Account;
|
||||||
import finalforeach.cosmicreach.entities.player.Player;
|
import finalforeach.cosmicreach.entities.player.Player;
|
||||||
import finalforeach.cosmicreach.io.SaveLocation;
|
import finalforeach.cosmicreach.io.SaveLocation;
|
||||||
|
@ -8,6 +9,8 @@ import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||||
import finalforeach.cosmicreach.savelib.utils.TriConsumer;
|
import finalforeach.cosmicreach.savelib.utils.TriConsumer;
|
||||||
|
import finalforeach.cosmicreach.world.Zone;
|
||||||
|
import finalforeach.cosmicreach.worldgen.ZoneGenerator;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import net.pietru.cookie_utils.permissions.Permissions;
|
import net.pietru.cookie_utils.permissions.Permissions;
|
||||||
import net.pietru.cookie_utils.setups.Setup;
|
import net.pietru.cookie_utils.setups.Setup;
|
||||||
|
@ -22,6 +25,7 @@ import static net.pietru.cookie_utils.permissions.Permissions.has_perm;
|
||||||
import static net.pietru.cookie_utils.permissions.Permissions.reload_perm_groups;
|
import static net.pietru.cookie_utils.permissions.Permissions.reload_perm_groups;
|
||||||
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
||||||
import static net.pietru.cookie_utils.utils.player_utils.get_player_id;
|
import static net.pietru.cookie_utils.utils.player_utils.get_player_id;
|
||||||
|
import static net.pietru.cookie_utils.utils.player_utils.parseAsPlayer;
|
||||||
|
|
||||||
public class TextCommands {
|
public class TextCommands {
|
||||||
public static final Map<String, TriConsumer<String[], NetworkIdentity, ChannelHandlerContext>> commands = new HashMap<>();
|
public static final Map<String, TriConsumer<String[], NetworkIdentity, ChannelHandlerContext>> commands = new HashMap<>();
|
||||||
|
@ -188,6 +192,50 @@ public class TextCommands {
|
||||||
packet.setupAndSend(channelHandlerContext);
|
packet.setupAndSend(channelHandlerContext);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
commands.put("make_zone",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
|
boolean created = false;
|
||||||
|
if (args.length==2){
|
||||||
|
String zoneId = args[1];
|
||||||
|
created = GameSingletons.world.getZoneIfExists(zoneId)==null;
|
||||||
|
if(created)
|
||||||
|
GameSingletons.world.addNewZone(zoneId, ZoneGenerator.getZoneGenerator(zoneId));
|
||||||
|
}
|
||||||
|
if (args.length>=3){
|
||||||
|
String zoneId = args[1];
|
||||||
|
String genId = args[2];
|
||||||
|
created = GameSingletons.world.getZoneIfExists(zoneId)==null;
|
||||||
|
if(created)
|
||||||
|
GameSingletons.world.addNewZone(zoneId, ZoneGenerator.getZoneGenerator(genId));
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagePacket packet = new MessagePacket(created ? "[Server] Created new zone..." : "[Server] Could not create new zone...");
|
||||||
|
packet.setupAndSend(channelHandlerContext);
|
||||||
|
});
|
||||||
|
|
||||||
|
commands.put("send",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
|
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||||
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
|
String txt = "[Server] Could not send plr to zone...";
|
||||||
|
if (args.length>=2){
|
||||||
|
String zoneId = args[1];
|
||||||
|
Zone zone = GameSingletons.world.getZoneIfExists(zoneId);
|
||||||
|
|
||||||
|
if (args.length>=3){
|
||||||
|
player = parseAsPlayer(args[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player!=null && zone!=null){
|
||||||
|
txt="[server] Sended "+player.getAccount().getDisplayName()+" to zone "+zoneId;
|
||||||
|
player.getZone().removePlayer(player);
|
||||||
|
player.respawn(zone);
|
||||||
|
zone.addPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagePacket packet = new MessagePacket(txt);
|
||||||
|
packet.setupAndSend(channelHandlerContext);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
commands.put("perm_code",(args, networkIdentity, channelHandlerContext) -> {
|
commands.put("perm_code",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
|
|
64
src/main/java/net/pietru/cookie_utils/utils/prop.java
Normal file
64
src/main/java/net/pietru/cookie_utils/utils/prop.java
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package net.pietru.cookie_utils.utils;
|
||||||
|
|
||||||
|
import finalforeach.cosmicreach.io.SaveLocation;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
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 ArrayList<String> get_server_property_array(String key, Object defaultValue) throws IOException {
|
||||||
|
String txt = (String) get_server_property(key,defaultValue);
|
||||||
|
String replace = txt.replace("[","");
|
||||||
|
String replace1 = replace.replace("]","");
|
||||||
|
return new ArrayList<String>(Arrays.asList(replace1.split(",")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object get_server_property(String key, Object defaultValue) throws IOException {
|
||||||
|
if(!config_file.exists())
|
||||||
|
config_file.createNewFile();
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.load(new FileInputStream(file.toString()));
|
||||||
|
return prop.getOrDefault(key,defaultValue);
|
||||||
|
}
|
||||||
|
public static void set_server_property(String key, Object value) throws IOException {
|
||||||
|
System.out.println("[Properties] Setting "+key+" to "+value);
|
||||||
|
|
||||||
|
if(!config_file.exists())
|
||||||
|
config_file.createNewFile();
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.load(new FileInputStream(file.toString()));
|
||||||
|
prop.put(key,value);
|
||||||
|
|
||||||
|
// Storing the properties in the file with a heading comment.
|
||||||
|
prop.store(new FileWriter(file.toString()), "This file is CookieServerUtils config file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void load_panel_config() throws IOException {
|
||||||
|
if(!config_file.exists())
|
||||||
|
config_file.createNewFile();
|
||||||
|
panel_prop = new Properties();
|
||||||
|
panel_prop.load(new FileInputStream(file.toString()));
|
||||||
|
|
||||||
|
boolean save = false;
|
||||||
|
|
||||||
|
if (!panel_prop.containsKey("zones")){
|
||||||
|
panel_prop.put("zones",new ArrayList<String>()); save=true;}
|
||||||
|
if (!panel_prop.containsKey("passwd")){
|
||||||
|
panel_prop.put("passwd","1234"); save=true;}
|
||||||
|
|
||||||
|
if (save)
|
||||||
|
panel_prop.store(new FileWriter(file.toString()), "This file is CookieServerUtils config file.");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue