Compare commits
No commits in common. "7c4921843bdeba3347a1812bc21cb78c9c2947d8" and "896dd49fd26f1b432f64249188ddbd33f039bb5b" have entirely different histories.
7c4921843b
...
896dd49fd2
4 changed files with 7 additions and 153 deletions
|
@ -1,18 +1,17 @@
|
||||||
package net.pietru.cookie_utils;
|
package net.pietru.cookie_utils;
|
||||||
|
|
||||||
import finalforeach.cosmicreach.GameSingletons;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import finalforeach.cosmicreach.GameAssetLoader;
|
||||||
|
import finalforeach.cosmicreach.blockevents.BlockEvents;
|
||||||
|
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 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 = {};
|
||||||
|
@ -33,20 +32,6 @@ 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,7 +1,6 @@
|
||||||
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;
|
||||||
|
@ -9,15 +8,11 @@ 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;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -27,9 +22,6 @@ 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;
|
|
||||||
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 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<>();
|
||||||
|
@ -48,6 +40,7 @@ public class TextCommands {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
commands.put("help",(args, networkIdentity, channelHandlerContext) -> {
|
commands.put("help",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
|
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
MessagePacket packet;
|
MessagePacket packet;
|
||||||
packet = new MessagePacket("You have access to following commands:");
|
packet = new MessagePacket("You have access to following commands:");
|
||||||
|
@ -179,7 +172,7 @@ public class TextCommands {
|
||||||
else {
|
else {
|
||||||
File region = new File(get_path_string(SaveLocation.getSaveFolder().getPath(), "regions", area.name));
|
File region = new File(get_path_string(SaveLocation.getSaveFolder().getPath(), "regions", area.name));
|
||||||
if (region.exists()) {
|
if (region.exists()) {
|
||||||
boolean ignored = region.delete();
|
region.delete();
|
||||||
packet = new MessagePacket("[Server] Usage :region area_name.json ACTION value(if required)");
|
packet = new MessagePacket("[Server] Usage :region area_name.json ACTION value(if required)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,68 +188,6 @@ public class TextCommands {
|
||||||
packet.setupAndSend(channelHandlerContext);
|
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) -> {
|
commands.put("perm_code",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
|
@ -315,7 +246,7 @@ public class TextCommands {
|
||||||
});
|
});
|
||||||
|
|
||||||
commands.put("reload_groups",(args, networkIdentity, channelHandlerContext) -> {
|
commands.put("reload_groups",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
MessagePacket packet = new MessagePacket("Reloaded groups...");
|
MessagePacket packet = new MessagePacket("Reloaded groups...");;
|
||||||
reload_perm_groups();
|
reload_perm_groups();
|
||||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
packet.playerUniqueId=account.getUniqueId();
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
|
|
|
@ -35,7 +35,6 @@ public class regionSetup extends Setup {
|
||||||
if (!name.endsWith(".json"))
|
if (!name.endsWith(".json"))
|
||||||
name+=".json";
|
name+=".json";
|
||||||
area.name=name;
|
area.name=name;
|
||||||
area.zoneId=zoneId;
|
|
||||||
run_setup_finish();
|
run_setup_finish();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
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