Compare commits
3 commits
896dd49fd2
...
7c4921843b
Author | SHA1 | Date | |
---|---|---|---|
|
7c4921843b | ||
|
fdbe58fc9a | ||
|
d778a57348 |
4 changed files with 153 additions and 7 deletions
|
@ -1,17 +1,18 @@
|
|||
package net.pietru.cookie_utils;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import finalforeach.cosmicreach.GameAssetLoader;
|
||||
import finalforeach.cosmicreach.blockevents.BlockEvents;
|
||||
import finalforeach.cosmicreach.blocks.Block;
|
||||
import finalforeach.cosmicreach.GameSingletons;
|
||||
import dev.crmodders.cosmicquilt.api.entrypoint.ModInitializer;
|
||||
import finalforeach.cosmicreach.world.Zone;
|
||||
import net.pietru.cookie_utils.api.Region;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
import net.pietru.cookie_utils.setups.setupCreator;
|
||||
import org.quiltmc.loader.api.ModContainer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static net.pietru.cookie_utils.utils.prop.get_server_property_array;
|
||||
|
||||
public class CookieUtils implements ModInitializer {
|
||||
public static final String MOD_ID = "cookie_utils";
|
||||
public static final String[] blocks = {};
|
||||
|
@ -32,6 +33,20 @@ public class CookieUtils implements ModInitializer {
|
|||
setupCreator.registerSetupCreators();
|
||||
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"));
|
||||
// for (String path : paths){
|
||||
// if (path.contains("block_events")) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.pietru.cookie_utils.api;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import finalforeach.cosmicreach.GameSingletons;
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
|
@ -8,11 +9,15 @@ import finalforeach.cosmicreach.networking.NetworkIdentity;
|
|||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import finalforeach.cosmicreach.savelib.utils.TriConsumer;
|
||||
import finalforeach.cosmicreach.world.Zone;
|
||||
import finalforeach.cosmicreach.worldgen.ZoneGenerator;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
import net.pietru.cookie_utils.setups.Setup;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -22,6 +27,9 @@ 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.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.parseAsPlayer;
|
||||
import static net.pietru.cookie_utils.utils.prop.get_server_property_array;
|
||||
import static net.pietru.cookie_utils.utils.prop.set_server_property;
|
||||
|
||||
public class TextCommands {
|
||||
public static final Map<String, TriConsumer<String[], NetworkIdentity, ChannelHandlerContext>> commands = new HashMap<>();
|
||||
|
@ -40,7 +48,6 @@ public class TextCommands {
|
|||
|
||||
static {
|
||||
commands.put("help",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
MessagePacket packet;
|
||||
packet = new MessagePacket("You have access to following commands:");
|
||||
|
@ -172,7 +179,7 @@ public class TextCommands {
|
|||
else {
|
||||
File region = new File(get_path_string(SaveLocation.getSaveFolder().getPath(), "regions", area.name));
|
||||
if (region.exists()) {
|
||||
region.delete();
|
||||
boolean ignored = region.delete();
|
||||
packet = new MessagePacket("[Server] Usage :region area_name.json ACTION value(if required)");
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +195,68 @@ public class TextCommands {
|
|||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
|
||||
commands.put("make_zone",(args, networkIdentity, channelHandlerContext) -> {
|
||||
boolean created = false;
|
||||
ArrayList<String> zones;
|
||||
try {
|
||||
zones = get_server_property_array("zones","[]");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
zones = new ArrayList<>();
|
||||
}
|
||||
if (args.length==2){
|
||||
String zoneId = args[1];
|
||||
created = GameSingletons.world.getZoneIfExists(zoneId)==null;
|
||||
if(created) {
|
||||
GameSingletons.world.addNewZone(zoneId, ZoneGenerator.getZoneGenerator(zoneId));
|
||||
zones.add(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));
|
||||
zones.add(zoneId);
|
||||
}
|
||||
}
|
||||
|
||||
if (created){
|
||||
try {
|
||||
set_server_property("zones",zones);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
|
@ -246,7 +315,7 @@ public class TextCommands {
|
|||
});
|
||||
|
||||
commands.put("reload_groups",(args, networkIdentity, channelHandlerContext) -> {
|
||||
MessagePacket packet = new MessagePacket("Reloaded groups...");;
|
||||
MessagePacket packet = new MessagePacket("Reloaded groups...");
|
||||
reload_perm_groups();
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
packet.playerUniqueId=account.getUniqueId();
|
||||
|
|
|
@ -35,6 +35,7 @@ public class regionSetup extends Setup {
|
|||
if (!name.endsWith(".json"))
|
||||
name+=".json";
|
||||
area.name=name;
|
||||
area.zoneId=zoneId;
|
||||
run_setup_finish();
|
||||
});
|
||||
|
||||
|
|
61
src/main/java/net/pietru/cookie_utils/utils/prop.java
Normal file
61
src/main/java/net/pietru/cookie_utils/utils/prop.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
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.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<>(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(config_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(config_file.toString()));
|
||||
prop.put(key,value);
|
||||
|
||||
// Storing the properties in the file with a heading comment.
|
||||
prop.store(new FileWriter(config_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(config_file.toString()));
|
||||
|
||||
boolean save = false;
|
||||
|
||||
if (!panel_prop.containsKey("zones")){
|
||||
panel_prop.put("zones",new ArrayList<String>()); save=true;}
|
||||
|
||||
if (save)
|
||||
panel_prop.store(new FileWriter(config_file.toString()), "This file is CookieServerUtils config file.");
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue