Compare commits
4 commits
2e527d0ef4
...
89193d52f6
Author | SHA1 | Date | |
---|---|---|---|
89193d52f6 | |||
9fce2a0eb7 | |||
c954fed7af | |||
c7f308bbb1 |
28 changed files with 1119 additions and 472 deletions
|
@ -4,15 +4,15 @@ org.gradle.parallel=true
|
|||
org.gradle.caching=false
|
||||
|
||||
# Project Info
|
||||
version=1.0.8
|
||||
version=1.0.9
|
||||
group=net.pietru
|
||||
id=cookie_utils
|
||||
|
||||
# Dependency Versions
|
||||
cosmic_reach_rev=alpha
|
||||
cosmic_reach_version=0.4.2
|
||||
cosmic_reach_version=0.4.4
|
||||
# If unspecified, will use the version above
|
||||
cosmic_reach_server_version=0.4.2
|
||||
cosmic_reach_server_version=0.4.4
|
||||
cosmic_quilt_version=2.3.1
|
||||
#2.2.0
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.pietru.cookie_utils;
|
|||
import dev.crmodders.cosmicquilt.api.entrypoint.ModInitializer;
|
||||
import finalforeach.cosmicreach.GameSingletons;
|
||||
import net.pietru.cookie_utils.api.Region;
|
||||
import net.pietru.cookie_utils.kits.Kits;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
import net.pietru.cookie_utils.scripting.ScriptsDB;
|
||||
import net.pietru.cookie_utils.setups.setupCreator;
|
||||
|
@ -43,6 +44,9 @@ public class CookieUtils implements ModInitializer {
|
|||
setupCreator.registerSetupCreators();
|
||||
System.out.println("CookieUtils loaded setup creators...");
|
||||
|
||||
Kits.reload_player_kits();
|
||||
System.out.println("CookieUtils loaded kits...");
|
||||
|
||||
GameSingletons.updateObservers.add(new CookieUtilsLogicRunner());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +1,21 @@
|
|||
package net.pietru.cookie_utils.api;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonWriter;
|
||||
import finalforeach.cosmicreach.GameSingletons;
|
||||
import finalforeach.cosmicreach.ZoneLoader;
|
||||
import finalforeach.cosmicreach.ZoneLoaders;
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.entities.EntityLaserProjectile;
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import finalforeach.cosmicreach.particles.GameParticleSystem;
|
||||
import finalforeach.cosmicreach.savelib.utils.TriConsumer;
|
||||
import finalforeach.cosmicreach.world.IZoneLoader;
|
||||
import finalforeach.cosmicreach.world.Zone;
|
||||
import finalforeach.cosmicreach.worldgen.ZoneGenerator;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.npcs.NpcDef;
|
||||
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.commands.*;
|
||||
import net.pietru.cookie_utils.commands.my_cmds.*;
|
||||
import net.pietru.cookie_utils.commands.perm_cmds.*;
|
||||
import net.pietru.cookie_utils.commands.reload_cmds.*;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.*;
|
||||
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.scripting.ScriptsDB.reload_scripts;
|
||||
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<>();
|
||||
public static final Map<String, BaseCommand> commands = new HashMap<>();
|
||||
|
||||
public static void run(String[] args, NetworkIdentity id, ChannelHandlerContext ctx){
|
||||
if (args.length==0)
|
||||
|
@ -55,454 +25,43 @@ public class TextCommands {
|
|||
Account account = ServerSingletons.getAccount(id);
|
||||
if (!has_perm(account.getUniqueId(),args[0]))
|
||||
return;
|
||||
TriConsumer<String[], NetworkIdentity, ChannelHandlerContext> cmd = commands.get(args[0]);
|
||||
BaseCommand cmd = commands.get(args[0]);
|
||||
cmd.accept(args, id, ctx);
|
||||
System.out.println("[CookieCMDS] Player "+account.getDisplayName()+" ("+account.getUniqueId()+") has used/tried to use "+ Arrays.toString(args));
|
||||
if (prop.log_level>-1)
|
||||
System.out.println("[CookieCMDS] Player "+account.getDisplayName()+" ("+account.getUniqueId()+") has used/tried to use "+ Arrays.toString(args));
|
||||
}
|
||||
|
||||
static {
|
||||
commands.put("help",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
MessagePacket packet;
|
||||
packet = new MessagePacket("[Server] You have access to following commands:");
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
for (String cmd : commands.keySet()){
|
||||
if (!has_perm(account.getUniqueId(),cmd))
|
||||
continue;
|
||||
packet = new MessagePacket(" - "+cmd);
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
}
|
||||
});
|
||||
commands.put("my_rank",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
MessagePacket packet;
|
||||
GroupPerms groupPerms = Permissions.get_group(account.getUniqueId());
|
||||
packet = new MessagePacket("[Server] Your rank is "+groupPerms.group_DisplayName);
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
packet = new MessagePacket(groupPerms.group_Desc);
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("gpos",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
commands.put("help", new help_command());
|
||||
commands.put("my_rank",new my_rank_command());
|
||||
commands.put("gpos",new gpos_command());
|
||||
commands.put("my_zone",new my_zone_command());
|
||||
commands.put("my_id",new my_id_command());
|
||||
commands.put("my_name",new my_name_command());
|
||||
commands.put("my_area",new my_area_command());
|
||||
commands.put("my_claims",new my_claims_command());
|
||||
commands.put("setup",new setup_command());
|
||||
commands.put("region",new region_command());
|
||||
commands.put("kit",new kit_command());
|
||||
|
||||
Vector3 pos = player.getPosition();
|
||||
MessagePacket packet = new MessagePacket("[Server] You are at "+(int)pos.x+" "+(int)pos.y+" "+(int)pos.z);
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("my_zone",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
commands.put("npc", new npc_command());
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] You are in "+player.zoneId);
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("my_id",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
commands.put("make_zone",new make_zone_command());
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] Your id is "+account.getUniqueId());
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("my_name",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] Your name is "+account.getUsername());
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("my_area",(args, networkIdentity, ctx) -> {
|
||||
Player plr = ServerSingletons.getPlayer(networkIdentity);
|
||||
Area area = get_area_at_pos(plr.getPosition(), plr.getZone());
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] You are in "+(area!=null?area.name : "no area atm..."));
|
||||
packet.setupAndSend(ctx);
|
||||
|
||||
if (area==null)
|
||||
return;
|
||||
|
||||
BoundingBox bb = area.getBox();
|
||||
|
||||
GameParticleSystem system = GameParticleSystem.laserParticleSystem.copy();
|
||||
system.startColor.set(Color.YELLOW);
|
||||
system.duration = 20.0F;
|
||||
|
||||
Vector3 m = new Vector3(.5f,.5f,.5f);
|
||||
|
||||
for (int x = (int) bb.min.x; x<=bb.max.x; x++){
|
||||
ParticleUtil.send_particle(x, (int) bb.min.y, (int) bb.min.z,system,ctx,m);
|
||||
ParticleUtil.send_particle(x, (int) bb.max.y, (int) bb.min.z,system,ctx,m);
|
||||
ParticleUtil.send_particle(x, (int) bb.min.y, (int) bb.max.z,system,ctx,m);
|
||||
ParticleUtil.send_particle(x, (int) bb.max.y, (int) bb.max.z,system,ctx,m);
|
||||
}
|
||||
for (int y = (int) bb.min.y; y<=bb.max.y; y++){
|
||||
ParticleUtil.send_particle((int) bb.min.x,y, (int) bb.min.z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.max.x,y, (int) bb.min.z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.min.x,y, (int) bb.max.z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.max.x,y, (int) bb.max.z,system,ctx,m);
|
||||
}
|
||||
for (int z = (int) bb.min.z; z<=bb.max.z; z++){
|
||||
ParticleUtil.send_particle((int) bb.min.x, (int) bb.min.y,z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.max.x, (int) bb.min.y,z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.min.x, (int) bb.max.y,z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.max.x, (int) bb.max.y,z,system,ctx,m);
|
||||
}
|
||||
});
|
||||
commands.put("my_claims",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] You have "+Region.get_owned_areas(account.getUniqueId())+" claims...");
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("setup",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
boolean cancel = false;
|
||||
boolean setup_perm_check = false;
|
||||
boolean started = false;
|
||||
if (args.length==2) {
|
||||
boolean a = has_perm(account.getUniqueId(), Setup.get_perm(args[1]));
|
||||
if (args[1].equalsIgnoreCase("cancel"))
|
||||
cancel = Setup.cancel(account.getUniqueId());
|
||||
else if (a)
|
||||
started = Setup.start(account.getUniqueId(), args[1]);
|
||||
|
||||
}
|
||||
|
||||
MessagePacket packet = new MessagePacket(
|
||||
(started || cancel)
|
||||
?
|
||||
(cancel ? "[Server] Setup canceled.." : "[Server] Starting setup..") :
|
||||
(setup_perm_check ? "[Server] Failed to start setup... (There might be one running)" : "[Server] No setup perm..."));
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
|
||||
if (started){
|
||||
packet = new MessagePacket(Setup.setups.get(account.getUniqueId()).get_step_hint());
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
}
|
||||
});
|
||||
commands.put("region",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
MessagePacket packet = new MessagePacket("[Server] Usage :region area_name.json action value(optional)");
|
||||
if (args.length>=3) {
|
||||
String txt = args[1];
|
||||
if (!txt.endsWith(".json"))
|
||||
txt+=".json";
|
||||
Area area = null;
|
||||
for (int i = 0; i < areas.size; i++) {
|
||||
if (areas.get(i).name.equals(txt)){
|
||||
area=areas.get(i);
|
||||
}
|
||||
}
|
||||
boolean a = has_perm(account.getUniqueId(), "region."+args[2]);
|
||||
if (a && area!=null){
|
||||
switch (args[2]){
|
||||
case "enabled":
|
||||
if (args.length==4){
|
||||
try {
|
||||
area.enabled=Boolean.parseBoolean(args[3]);
|
||||
area.save(false);
|
||||
} catch (Exception ignored) {}
|
||||
packet = new MessagePacket("[Server] Area is now "+(area.enabled?"ENABLED":"DISABLED"));
|
||||
} else
|
||||
packet = new MessagePacket("[Server] Area is "+(area.enabled?"ENABLED":"DISABLED"));
|
||||
break;
|
||||
case "protect":
|
||||
if (args.length==4){
|
||||
try {
|
||||
area.protect=Boolean.parseBoolean(args[3]);
|
||||
area.save(false);
|
||||
} catch (Exception ignored) {}
|
||||
packet = new MessagePacket("[Server] Area protection is now "+(area.protect?"ENABLED":"DISABLED"));
|
||||
} else
|
||||
packet = new MessagePacket("[Server] Area protection is "+(area.protect?"ENABLED":"DISABLED"));
|
||||
break;
|
||||
case "priority", "piority":
|
||||
if (args.length==4){
|
||||
try {
|
||||
area.piority=Integer.parseInt(args[3]);
|
||||
area.save(false);
|
||||
sort_areas();
|
||||
} catch (Exception ignored) {}
|
||||
packet = new MessagePacket("[Server] Area priority is now "+area.piority);
|
||||
|
||||
} else
|
||||
packet = new MessagePacket("[Server] Area priority is "+area.piority);
|
||||
break;
|
||||
case "delete":
|
||||
if (area.protect)
|
||||
packet = new MessagePacket("[Server] Sorry but this area is protected...");
|
||||
else {
|
||||
File region = new File(get_path_string(SaveLocation.getSaveFolder().getPath(), "regions", area.name));
|
||||
if (region.exists()) {
|
||||
boolean ignored = region.delete();
|
||||
packet = new MessagePacket("[Server] Usage :region area_name.json ACTION value(if required)");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
packet = new MessagePacket("[Server] Insufficient permissions or wrong area...");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
|
||||
commands.put("npc",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Player plr = networkIdentity.getPlayer();
|
||||
MessagePacket packet = new MessagePacket("[Server] Usage :npc action id values(optional)");
|
||||
if (args.length>=4) {
|
||||
String arg2 = args[2];
|
||||
String arg3 = args[3];
|
||||
switch (args[1]) {
|
||||
case "name":
|
||||
try {
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2)).change_zone(plr.getZone()).setName(arg3);
|
||||
packet.message="[Server] Changed npc with ID: %s, NAME: %s".formatted(arg2,arg3);
|
||||
} catch (Exception ignored){
|
||||
packet.message="[Server] Failed to modify npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
case "rot":
|
||||
try {
|
||||
String[] ps = arg3.split(":");
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2))
|
||||
.change_view_dir(new Vector3(
|
||||
Float.parseFloat(ps[0]),
|
||||
Float.parseFloat(ps[1]),
|
||||
Float.parseFloat(ps[2])
|
||||
)).send_update();
|
||||
packet.message="[Server] Rotated npc with ID: %s".formatted(arg2);
|
||||
} catch (Exception ignored){
|
||||
packet.message="[Server] Failed to modify npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (args.length==3) {
|
||||
String arg2 = args[2];
|
||||
switch (args[1]) {
|
||||
case "add":
|
||||
new NpcDef(arg2, plr.getPosition(), plr.getZone()).register().show_npc();
|
||||
packet.message="[Server] Added npc with ID: %s".formatted(NpcDef.registered_npc_list.size()-1);
|
||||
break;
|
||||
case "tphere":
|
||||
try {
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2))
|
||||
.change_zone(plr.getZone())
|
||||
.change_position(plr.getPosition())
|
||||
.send_update();
|
||||
packet.message="[Server] Moved npc with ID: %s".formatted(arg2);
|
||||
} catch (Exception ignored){
|
||||
packet.message="[Server] Failed to parse npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
case "myrot":
|
||||
try {
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2))
|
||||
.change_view_dir(plr.getEntity().viewDirection)
|
||||
.send_update();
|
||||
packet.message="[Server] Rotated npc with ID: %s".formatted(arg2);
|
||||
} catch (Exception ignored){
|
||||
packet.message="[Server] Failed to parse npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
case "remove", "del":
|
||||
try {
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2)).unregister();
|
||||
packet.message="[Server] Removed npc with ID: %s".formatted(arg2);
|
||||
} catch (Exception ignored){
|
||||
packet.message="[Server] Failed to parse npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
switch (args[1]) {
|
||||
case "list":
|
||||
StringBuilder msg = new StringBuilder("[Server] NPC List:\n");
|
||||
for (int i = 0; i < NpcDef.registered_npc_list.size(); i++) {
|
||||
msg.append(" - ID: %d | Name: %s \n".formatted(i, NpcDef.registered_npc_list.get(i).getName()));
|
||||
}
|
||||
packet.message=msg.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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.toString());
|
||||
} 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) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
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 && has_perm(account.getUniqueId(), "send.other")){
|
||||
player = parseAsPlayer(args[2]);
|
||||
}
|
||||
|
||||
if (player!=null && zone!=null){
|
||||
txt="[Server] Sended "+player.getAccount().getDisplayName()+" to zone "+zoneId;
|
||||
Zone old = player.getZone();
|
||||
if (old.zoneId.equals(zoneId)) {
|
||||
txt = "[Server] Player " + player.getAccount().getDisplayName() + " is already in zone " + zoneId;
|
||||
}else {
|
||||
zone.addPlayer(player);
|
||||
player.setZone(zoneId);
|
||||
player.respawn(zone);
|
||||
old.removePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessagePacket packet = new MessagePacket(txt);
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("send",new send_command());
|
||||
|
||||
|
||||
commands.put("perm_code",(args, networkIdentity, channeleHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
if (args.length==1)
|
||||
Permissions.generate_new_code();
|
||||
if (args.length==2)
|
||||
Permissions.check_code_and_add_user(args[1],account.getUniqueId());
|
||||
});
|
||||
commands.put("perm_code",new perm_code_command());
|
||||
|
||||
commands.put("perm_clear",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
if (args.length==1) {
|
||||
Permissions.clear_user_perm(account.getUniqueId(),true);
|
||||
System.out.println("[Permissions] Users %s permission revoked - user request...".replace("%s",account.getUniqueId()));
|
||||
}
|
||||
});
|
||||
commands.put("perm_clear",new perm_clear_command());
|
||||
|
||||
commands.put("group",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
MessagePacket packet=null;
|
||||
if (args.length==4) {
|
||||
if (Objects.equals(args[1], "set")) {
|
||||
boolean res = Permissions.set_group(get_player_id(args[2]), args[3]);
|
||||
packet = new MessagePacket(res ? "[Server] Group set for user..." : "[Server] Failed to set group for user...");
|
||||
}
|
||||
}
|
||||
else if (args.length==3) {
|
||||
if (Objects.equals(args[1], "clear")) {
|
||||
Permissions.clear_group(get_player_id(args[2]));
|
||||
packet = new MessagePacket("[Server] If user had perm it was cleared...");
|
||||
}
|
||||
}
|
||||
|
||||
if (packet==null)
|
||||
return;
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("group",new group_command());
|
||||
|
||||
|
||||
commands.put("reload_regions",(args, networkIdentity, channelHandlerContext) -> {
|
||||
MessagePacket packet = null;
|
||||
if (args.length==1) {
|
||||
reload_regions();
|
||||
packet = new MessagePacket("Reloaded regions...");
|
||||
}
|
||||
if (args.length==2) {
|
||||
reload_area_player_perms(args[1]);
|
||||
packet = new MessagePacket("Reloaded %s area...".replace("%s", args[1]));
|
||||
}
|
||||
if (packet==null)
|
||||
return;
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("reload_regions",new reload_regions_command());
|
||||
|
||||
commands.put("reload",(args, networkIdentity, channelHandlerContext) -> {
|
||||
List<String> arg_list = Arrays.stream(args).toList();
|
||||
String reloaded_funcs = "";
|
||||
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 ";
|
||||
}
|
||||
MessagePacket packet = new MessagePacket("Reloaded: "+reloaded_funcs);
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("reload",new reload_command());
|
||||
|
||||
commands.put("dump",(args, networkIdentity, channelHandlerContext) -> {
|
||||
File dumps_folder = new File(SaveLocation.getSaveFolder(),"dumps");
|
||||
if (!dumps_folder.exists())
|
||||
dumps_folder.mkdirs();
|
||||
List<String> arg_list = Arrays.stream(args).toList();
|
||||
String reloaded_funcs = "";
|
||||
if (arg_list.contains("zones") || args.length==1) {
|
||||
int i = 0;
|
||||
for(IZoneLoader z : ZoneLoaders.INSTANCE.getAllZoneLoaders()) {
|
||||
File dump_file = new File(get_path_string(SaveLocation.getSaveFolder().getPath(), "dumps", "zone_"+String.valueOf(i++)+".json"));
|
||||
try {
|
||||
Json json = new Json();
|
||||
json.setOutputType(JsonWriter.OutputType.json);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(dump_file.getPath()));
|
||||
writer.write(json.prettyPrint(z));
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
reloaded_funcs+="zones ";
|
||||
}
|
||||
MessagePacket packet = new MessagePacket("Dumped: "+reloaded_funcs);
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("dump",new dump_command());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.savelib.utils.TriConsumer;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
public abstract class BaseCommand implements TriConsumer<String[], NetworkIdentity, ChannelHandlerContext> {
|
||||
public abstract String get_command_key();
|
||||
public abstract void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx);
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonWriter;
|
||||
import finalforeach.cosmicreach.ZoneLoaders;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.world.IZoneLoader;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
||||
|
||||
public class dump_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "dump";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
File dumps_folder = new File(SaveLocation.getSaveFolder(),"dumps");
|
||||
if (!dumps_folder.exists())
|
||||
dumps_folder.mkdirs();
|
||||
List<String> arg_list = Arrays.stream(args).toList();
|
||||
String reloaded_funcs = "";
|
||||
if (arg_list.contains("zones") || args.length==1) {
|
||||
int i = 0;
|
||||
for(IZoneLoader z : ZoneLoaders.INSTANCE.getAllZoneLoaders()) {
|
||||
File dump_file = new File(get_path_string(SaveLocation.getSaveFolder().getPath(), "dumps", "zone_"+String.valueOf(i++)+".json"));
|
||||
try {
|
||||
Json json = new Json();
|
||||
json.setOutputType(JsonWriter.OutputType.json);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(dump_file.getPath()));
|
||||
writer.write(json.prettyPrint(z));
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
reloaded_funcs+="zones ";
|
||||
}
|
||||
MessagePacket packet = new MessagePacket("Dumped: "+reloaded_funcs);
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.api.TextCommands;
|
||||
|
||||
import static net.pietru.cookie_utils.permissions.Permissions.has_perm;
|
||||
|
||||
public class help_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
MessagePacket packet;
|
||||
packet = new MessagePacket("[Server] You have access to following commands:");
|
||||
packet.setupAndSend(ctx);
|
||||
for (String cmd : TextCommands.commands.keySet()){
|
||||
if (!has_perm(account.getUniqueId(),cmd))
|
||||
continue;
|
||||
packet = new MessagePacket(" - "+cmd);
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.kits.Kits;
|
||||
|
||||
public class kit_command extends BaseCommand{
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "kit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(identity);
|
||||
boolean used = false;
|
||||
long timeout = 0;
|
||||
String kitId = "";
|
||||
if (args.length>=2){
|
||||
kitId = args[1];
|
||||
|
||||
if (account!=null && kitId!=null){
|
||||
timeout = Kits.get_kit_timeout(account.getUniqueId(),kitId);
|
||||
timeout = timeout/1000;
|
||||
used = Kits.use_kit(account.getUniqueId(),kitId);
|
||||
}
|
||||
}
|
||||
|
||||
String claim_kit_in_msg = "[Server] You can claim this kit in ";
|
||||
if (timeout>0){
|
||||
long seconds = timeout%60;
|
||||
long minutes = timeout-seconds;
|
||||
long hours = timeout-minutes-seconds;
|
||||
long days = timeout-hours-minutes-seconds;
|
||||
if (timeout>59){
|
||||
if (timeout>3599){
|
||||
if (timeout>86399){
|
||||
claim_kit_in_msg+=days/(60*60824)+"d ";
|
||||
}
|
||||
claim_kit_in_msg+=hours/(60*60)+"h ";
|
||||
}
|
||||
claim_kit_in_msg+=minutes/60+"m ";
|
||||
}
|
||||
claim_kit_in_msg+=seconds+"s ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
MessagePacket packet = new MessagePacket(used ? "[Server] Claimed kit "+Kits.get_kit_name(kitId) : (timeout>0 ? claim_kit_in_msg : "[Server] Could not claim kit..."));
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import finalforeach.cosmicreach.GameSingletons;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.worldgen.ZoneGenerator;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
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 make_zone_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "make_zone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
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.toString());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
MessagePacket packet = new MessagePacket(created ? "[Server] Created new zone..." : "[Server] Could not create new zone...");
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package net.pietru.cookie_utils.commands.my_cmds;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
|
||||
public class gpos_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "gpos";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||
|
||||
Vector3 pos = player.getPosition();
|
||||
MessagePacket packet = new MessagePacket("[Server] You are at "+(int)pos.x+" "+(int)pos.y+" "+(int)pos.z);
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package net.pietru.cookie_utils.commands.my_cmds;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import finalforeach.cosmicreach.particles.GameParticleSystem;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.api.Area;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
import net.pietru.cookie_utils.utils.ParticleUtil;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.get_area_at_pos;
|
||||
|
||||
public class my_area_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "my_area";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Player plr = ServerSingletons.getPlayer(networkIdentity);
|
||||
Area area = get_area_at_pos(plr.getPosition(), plr.getZone());
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] You are in "+(area!=null?area.name : "no area atm..."));
|
||||
packet.setupAndSend(ctx);
|
||||
|
||||
if (area==null)
|
||||
return;
|
||||
|
||||
BoundingBox bb = area.getBox();
|
||||
|
||||
GameParticleSystem system = GameParticleSystem.laserParticleSystem.copy();
|
||||
system.startColor.set(Color.YELLOW);
|
||||
system.duration = 20.0F;
|
||||
|
||||
Vector3 m = new Vector3(.5f,.5f,.5f);
|
||||
|
||||
for (int x = (int) bb.min.x; x<=bb.max.x; x++){
|
||||
ParticleUtil.send_particle(x, (int) bb.min.y, (int) bb.min.z,system,ctx,m);
|
||||
ParticleUtil.send_particle(x, (int) bb.max.y, (int) bb.min.z,system,ctx,m);
|
||||
ParticleUtil.send_particle(x, (int) bb.min.y, (int) bb.max.z,system,ctx,m);
|
||||
ParticleUtil.send_particle(x, (int) bb.max.y, (int) bb.max.z,system,ctx,m);
|
||||
}
|
||||
for (int y = (int) bb.min.y; y<=bb.max.y; y++){
|
||||
ParticleUtil.send_particle((int) bb.min.x,y, (int) bb.min.z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.max.x,y, (int) bb.min.z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.min.x,y, (int) bb.max.z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.max.x,y, (int) bb.max.z,system,ctx,m);
|
||||
}
|
||||
for (int z = (int) bb.min.z; z<=bb.max.z; z++){
|
||||
ParticleUtil.send_particle((int) bb.min.x, (int) bb.min.y,z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.max.x, (int) bb.min.y,z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.min.x, (int) bb.max.y,z,system,ctx,m);
|
||||
ParticleUtil.send_particle((int) bb.max.x, (int) bb.max.y,z,system,ctx,m);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package net.pietru.cookie_utils.commands.my_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.api.Region;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
|
||||
public class my_claims_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "my_claims";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] You have "+ Region.get_owned_areas(account.getUniqueId())+" claims...");
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package net.pietru.cookie_utils.commands.my_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
|
||||
public class my_id_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "my_id";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] Your id is "+account.getUniqueId());
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package net.pietru.cookie_utils.commands.my_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
|
||||
public class my_name_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "my_name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] Your name is "+account.getUsername());
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package net.pietru.cookie_utils.commands.my_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
import net.pietru.cookie_utils.permissions.GroupPerms;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
|
||||
public class my_rank_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "my_rank";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
MessagePacket packet;
|
||||
GroupPerms groupPerms = Permissions.get_group(account.getUniqueId());
|
||||
packet = new MessagePacket("[Server] Your rank is "+groupPerms.group_DisplayName);
|
||||
packet.setupAndSend(ctx);
|
||||
packet = new MessagePacket(groupPerms.group_Desc);
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package net.pietru.cookie_utils.commands.my_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
|
||||
public class my_zone_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "my_zone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Player player = ServerSingletons.getPlayer(networkIdentity);
|
||||
|
||||
MessagePacket packet = new MessagePacket("[Server] You are in "+player.zoneId);
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.npcs.NpcDef;
|
||||
|
||||
public class npc_command extends BaseCommand{
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "npc";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Player plr = networkIdentity.getPlayer();
|
||||
MessagePacket packet = new MessagePacket("[Server] Usage :npc action id values(optional)");
|
||||
if (args.length >= 4) {
|
||||
String arg2 = args[2];
|
||||
String arg3 = args[3];
|
||||
switch (args[1]) {
|
||||
case "name":
|
||||
try {
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2)).change_zone(plr.getZone()).setName(arg3);
|
||||
packet.message = "[Server] Changed npc with ID: %s, NAME: %s".formatted(arg2, arg3);
|
||||
} catch (Exception ignored) {
|
||||
packet.message = "[Server] Failed to modify npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
case "rot":
|
||||
try {
|
||||
String[] ps = arg3.split(":");
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2))
|
||||
.change_view_dir(new Vector3(
|
||||
Float.parseFloat(ps[0]),
|
||||
Float.parseFloat(ps[1]),
|
||||
Float.parseFloat(ps[2])
|
||||
)).send_update();
|
||||
packet.message = "[Server] Rotated npc with ID: %s".formatted(arg2);
|
||||
} catch (Exception ignored) {
|
||||
packet.message = "[Server] Failed to modify npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
String arg2 = args[2];
|
||||
switch (args[1]) {
|
||||
case "add":
|
||||
new NpcDef(arg2, plr.getPosition(), plr.getZone()).register().show_npc();
|
||||
packet.message = "[Server] Added npc with ID: %s".formatted(NpcDef.registered_npc_list.size() - 1);
|
||||
break;
|
||||
case "tphere":
|
||||
try {
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2))
|
||||
.change_zone(plr.getZone())
|
||||
.change_position(plr.getPosition())
|
||||
.send_update();
|
||||
packet.message = "[Server] Moved npc with ID: %s".formatted(arg2);
|
||||
} catch (Exception ignored) {
|
||||
packet.message = "[Server] Failed to parse npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
case "myrot":
|
||||
try {
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2))
|
||||
.change_view_dir(plr.getEntity().viewDirection)
|
||||
.send_update();
|
||||
packet.message = "[Server] Rotated npc with ID: %s".formatted(arg2);
|
||||
} catch (Exception ignored) {
|
||||
packet.message = "[Server] Failed to parse npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
case "remove", "del":
|
||||
try {
|
||||
NpcDef.registered_npc_list.get(Integer.parseInt(arg2)).unregister();
|
||||
packet.message = "[Server] Removed npc with ID: %s".formatted(arg2);
|
||||
} catch (Exception ignored) {
|
||||
packet.message = "[Server] Failed to parse npc ID: %s".formatted(arg2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
switch (args[1]) {
|
||||
case "list":
|
||||
StringBuilder msg = new StringBuilder("[Server] NPC List:\n");
|
||||
for (int i = 0; i < NpcDef.registered_npc_list.size(); i++) {
|
||||
msg.append(" - ID: %d | Name: %s \n".formatted(i, NpcDef.registered_npc_list.get(i).getName()));
|
||||
}
|
||||
packet.message = msg.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package net.pietru.cookie_utils.commands.perm_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.pietru.cookie_utils.utils.player_utils.get_player_id;
|
||||
|
||||
public class group_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "group";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(identity);
|
||||
MessagePacket packet=null;
|
||||
if (args.length==4) {
|
||||
if (Objects.equals(args[1], "set")) {
|
||||
boolean res = Permissions.set_group(get_player_id(args[2]), args[3]);
|
||||
packet = new MessagePacket(res ? "[Server] Group set for user..." : "[Server] Failed to set group for user...");
|
||||
}
|
||||
}
|
||||
else if (args.length==3) {
|
||||
if (Objects.equals(args[1], "clear")) {
|
||||
Permissions.clear_group(get_player_id(args[2]));
|
||||
packet = new MessagePacket("[Server] If user had perm it was cleared...");
|
||||
}
|
||||
}
|
||||
|
||||
if (packet==null)
|
||||
return;
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package net.pietru.cookie_utils.commands.perm_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
|
||||
public class perm_clear_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "perm_clear";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(identity);
|
||||
if (args.length==1) {
|
||||
Permissions.clear_user_perm(account.getUniqueId(),true);
|
||||
System.out.println("[Permissions] Users %s permission revoked - user request...".replace("%s",account.getUniqueId()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package net.pietru.cookie_utils.commands.perm_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
|
||||
public class perm_code_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "perm_code";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(identity);
|
||||
if (args.length==1)
|
||||
Permissions.generate_new_code();
|
||||
if (args.length==2)
|
||||
Permissions.check_code_and_add_user(args[1],account.getUniqueId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.api.Area;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.areas;
|
||||
import static net.pietru.cookie_utils.api.Region.sort_areas;
|
||||
import static net.pietru.cookie_utils.permissions.Permissions.has_perm;
|
||||
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
||||
|
||||
public class region_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "region";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(identity);
|
||||
MessagePacket packet = new MessagePacket("[Server] Usage :region area_name.json action value(optional)");
|
||||
if (args.length>=3) {
|
||||
String txt = args[1];
|
||||
if (!txt.endsWith(".json"))
|
||||
txt+=".json";
|
||||
Area area = null;
|
||||
for (int i = 0; i < areas.size; i++) {
|
||||
if (areas.get(i).name.equals(txt)){
|
||||
area=areas.get(i);
|
||||
}
|
||||
}
|
||||
boolean a = has_perm(account.getUniqueId(), "region."+args[2]);
|
||||
if (a && area!=null){
|
||||
switch (args[2]){
|
||||
case "enabled":
|
||||
if (args.length==4){
|
||||
try {
|
||||
area.enabled=Boolean.parseBoolean(args[3]);
|
||||
area.save(false);
|
||||
} catch (Exception ignored) {}
|
||||
packet = new MessagePacket("[Server] Area is now "+(area.enabled?"ENABLED":"DISABLED"));
|
||||
} else
|
||||
packet = new MessagePacket("[Server] Area is "+(area.enabled?"ENABLED":"DISABLED"));
|
||||
break;
|
||||
case "protect":
|
||||
if (args.length==4){
|
||||
try {
|
||||
area.protect=Boolean.parseBoolean(args[3]);
|
||||
area.save(false);
|
||||
} catch (Exception ignored) {}
|
||||
packet = new MessagePacket("[Server] Area protection is now "+(area.protect?"ENABLED":"DISABLED"));
|
||||
} else
|
||||
packet = new MessagePacket("[Server] Area protection is "+(area.protect?"ENABLED":"DISABLED"));
|
||||
break;
|
||||
case "priority", "piority":
|
||||
if (args.length==4){
|
||||
try {
|
||||
area.piority=Integer.parseInt(args[3]);
|
||||
area.save(false);
|
||||
sort_areas();
|
||||
} catch (Exception ignored) {}
|
||||
packet = new MessagePacket("[Server] Area priority is now "+area.piority);
|
||||
|
||||
} else
|
||||
packet = new MessagePacket("[Server] Area priority is "+area.piority);
|
||||
break;
|
||||
case "delete":
|
||||
if (area.protect)
|
||||
packet = new MessagePacket("[Server] Sorry but this area is protected...");
|
||||
else {
|
||||
File region = new File(get_path_string(SaveLocation.getSaveFolder().getPath(), "regions", area.name));
|
||||
if (region.exists()) {
|
||||
boolean ignored = region.delete();
|
||||
packet = new MessagePacket("[Server] Usage :region area_name.json ACTION value(if required)");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
packet = new MessagePacket("[Server] Insufficient permissions or wrong area...");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package net.pietru.cookie_utils.commands.reload_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.reload_regions;
|
||||
import static net.pietru.cookie_utils.kits.Kits.reload_player_kits;
|
||||
import static net.pietru.cookie_utils.permissions.Permissions.reload_perm_groups;
|
||||
import static net.pietru.cookie_utils.scripting.ScriptsDB.reload_scripts;
|
||||
|
||||
public class reload_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
List<String> arg_list = Arrays.stream(args).toList();
|
||||
String reloaded_funcs = "";
|
||||
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 ";
|
||||
}
|
||||
if (arg_list.contains("kits") || args.length==1) {
|
||||
reload_player_kits();
|
||||
reloaded_funcs+="kits ";
|
||||
}
|
||||
MessagePacket packet = new MessagePacket("Reloaded: "+reloaded_funcs);
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package net.pietru.cookie_utils.commands.reload_cmds;
|
||||
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.commands.BaseCommand;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.reload_area_player_perms;
|
||||
import static net.pietru.cookie_utils.api.Region.reload_regions;
|
||||
|
||||
public class reload_regions_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "reload_regions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
MessagePacket packet = null;
|
||||
if (args.length==1) {
|
||||
reload_regions();
|
||||
packet = new MessagePacket("Reloaded regions...");
|
||||
}
|
||||
if (args.length==2) {
|
||||
reload_area_player_perms(args[1]);
|
||||
packet = new MessagePacket("Reloaded %s area...".replace("%s", args[1]));
|
||||
}
|
||||
if (packet==null)
|
||||
return;
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import finalforeach.cosmicreach.GameSingletons;
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import finalforeach.cosmicreach.world.Zone;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import static net.pietru.cookie_utils.permissions.Permissions.has_perm;
|
||||
import static net.pietru.cookie_utils.utils.player_utils.parseAsPlayer;
|
||||
|
||||
public class send_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "send";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity identity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(identity);
|
||||
Player player = ServerSingletons.getPlayer(identity);
|
||||
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 && has_perm(account.getUniqueId(), "send.other")){
|
||||
player = parseAsPlayer(args[2]);
|
||||
}
|
||||
|
||||
if (player!=null && zone!=null){
|
||||
txt="[Server] Sended "+player.getAccount().getDisplayName()+" to zone "+zoneId;
|
||||
Zone old = player.getZone();
|
||||
if (old.zoneId.equals(zoneId)) {
|
||||
txt = "[Server] Player " + player.getAccount().getDisplayName() + " is already in zone " + zoneId;
|
||||
}else {
|
||||
zone.addPlayer(player);
|
||||
player.setZone(zoneId);
|
||||
player.respawn(zone);
|
||||
old.removePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessagePacket packet = new MessagePacket(txt);
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package net.pietru.cookie_utils.commands;
|
||||
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.networking.NetworkIdentity;
|
||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.setups.Setup;
|
||||
|
||||
import static net.pietru.cookie_utils.permissions.Permissions.has_perm;
|
||||
|
||||
public class setup_command extends BaseCommand {
|
||||
@Override
|
||||
public String get_command_key() {
|
||||
return "setup";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String[] args, NetworkIdentity networkIdentity, ChannelHandlerContext ctx) {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
boolean cancel = false;
|
||||
boolean setup_perm_check = false;
|
||||
boolean started = false;
|
||||
if (args.length==2) {
|
||||
boolean a = has_perm(account.getUniqueId(), Setup.get_perm(args[1]));
|
||||
if (args[1].equalsIgnoreCase("cancel"))
|
||||
cancel = Setup.cancel(account.getUniqueId());
|
||||
else if (a)
|
||||
started = Setup.start(account.getUniqueId(), args[1]);
|
||||
|
||||
}
|
||||
|
||||
MessagePacket packet = new MessagePacket(
|
||||
(started || cancel)
|
||||
?
|
||||
(cancel ? "[Server] Setup canceled.." : "[Server] Starting setup..") :
|
||||
(setup_perm_check ? "[Server] Failed to start setup... (There might be one running)" : "[Server] No setup perm..."));
|
||||
packet.setupAndSend(ctx);
|
||||
|
||||
if (started){
|
||||
packet = new MessagePacket(Setup.setups.get(account.getUniqueId()).get_step_hint());
|
||||
packet.setupAndSend(ctx);
|
||||
}
|
||||
}
|
||||
}
|
160
src/main/java/net/pietru/cookie_utils/kits/Kits.java
Normal file
160
src/main/java/net/pietru/cookie_utils/kits/Kits.java
Normal file
|
@ -0,0 +1,160 @@
|
|||
package net.pietru.cookie_utils.kits;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonWriter;
|
||||
import finalforeach.cosmicreach.accounts.Account;
|
||||
import finalforeach.cosmicreach.entities.player.Player;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import finalforeach.cosmicreach.items.Item;
|
||||
import finalforeach.cosmicreach.items.ItemMergeStrategy;
|
||||
import finalforeach.cosmicreach.items.ItemStack;
|
||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
import net.pietru.cookie_utils.utils.directory_utils;
|
||||
import net.pietru.cookie_utils.utils.prop;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.*;
|
||||
|
||||
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
||||
|
||||
public class Kits {
|
||||
static Json json = new Json();
|
||||
|
||||
static Map<String,kit_info> kitsMap = new HashMap<>();
|
||||
static Map<String,kit_use_info> player_kit_uses = new HashMap<>();
|
||||
|
||||
public static void reload_player_kit_uses(boolean load){
|
||||
File def = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"player_kit_uses.json"));
|
||||
if (load && def.exists()) {
|
||||
try {
|
||||
player_kit_uses = json.fromJson(HashMap.class, Gdx.files.absolute(def.getPath()));
|
||||
} catch (Exception ignored) {
|
||||
if (prop.log_level>0)
|
||||
System.err.println("[KITS] Encountered exception while loading player kit uses...");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Json json = new Json();
|
||||
json.setOutputType(JsonWriter.OutputType.json);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(def.getPath()));
|
||||
writer.write(json.prettyPrint(player_kit_uses));
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (prop.log_level>0)
|
||||
System.out.println("[KITS] Saved player kit uses.");
|
||||
}
|
||||
|
||||
public static void reload_player_kits(){
|
||||
kitsMap.clear();
|
||||
|
||||
File perms_folder = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"kits"));
|
||||
if (!perms_folder.exists()) {
|
||||
perms_folder.mkdirs();
|
||||
}
|
||||
File def = new File(get_path_string(perms_folder.getPath(),"example.json"));
|
||||
ArrayList<File> perms = directory_utils.list_files_in_dir_recursive(perms_folder,((dir, name) -> name.endsWith(".json")));
|
||||
if (prop.log_level>0)
|
||||
System.out.println("[KITS] Trying to load %s perm kits.".replace("%s", String.valueOf(perms.size())));
|
||||
for (File f : perms) {
|
||||
kit_info kit;
|
||||
try {
|
||||
kit=json.fromJson(kit_info.class,Gdx.files.absolute(f.getPath()));
|
||||
} catch (Exception ignored){
|
||||
if (prop.log_level>0)
|
||||
System.err.println("[KITS] Perm group file \"%s\" had encountered exception while loading...".replace("%s", f.getPath()));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kit.kit_id.isEmpty())
|
||||
continue;
|
||||
|
||||
|
||||
kitsMap.put(kit.kit_id,kit);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (!def.exists()) {
|
||||
Json json = new Json();
|
||||
json.setOutputType(JsonWriter.OutputType.json);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(def.getPath()));
|
||||
writer.write(json.prettyPrint(kit_info.get_default_kit()));
|
||||
writer.close();
|
||||
reload_player_kits();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
reload_player_kit_uses(true);
|
||||
|
||||
if (prop.log_level>0)
|
||||
System.out.println("[KITS] Loaded %s permissions.".replace("%s",String.valueOf(kitsMap.size())));
|
||||
}
|
||||
|
||||
public static Set<String> get_kits(){
|
||||
return kitsMap.keySet();
|
||||
}
|
||||
|
||||
public static String get_kit_name(String kit_id){
|
||||
return kitsMap.getOrDefault(kit_id,new kit_info()).kit_DisplayName;
|
||||
}
|
||||
|
||||
public static boolean can_use_kit(String playerId,String kit_id){
|
||||
if (!kitsMap.containsKey(kit_id))
|
||||
return false;
|
||||
kit_info kit = kitsMap.get(kit_id);
|
||||
boolean perm = Permissions.has_perm(playerId,kitsMap.get(kit_id).kit_perm);
|
||||
if (!player_kit_uses.containsKey(playerId))
|
||||
return perm;
|
||||
kit_use_info info = player_kit_uses.get(playerId);
|
||||
if (!info.kit_use.containsKey(kit_id))
|
||||
return perm;
|
||||
long use_time = info.kit_use.get(kit_id);
|
||||
long delay_time = (long) ((kit.kit_delay_seconds + kit.kit_delay_minutes*60 + kit.kit_delay_hours*60*60 + kit.kit_delay_days*60*60*24)*1000);
|
||||
return perm && System.currentTimeMillis()>(use_time+delay_time);
|
||||
}
|
||||
|
||||
public static boolean use_kit(String playerId,String kit_id){
|
||||
if (!can_use_kit(playerId,kit_id))
|
||||
return false;
|
||||
if (!kitsMap.containsKey(kit_id))
|
||||
return false;
|
||||
kit_info kit = kitsMap.get(kit_id);
|
||||
Account account = ServerSingletons.getAccountByUniqueId(playerId);
|
||||
Player player = account.getPlayer();
|
||||
for (String id : kit.items.keySet())
|
||||
player.inventory.merge(new ItemStack(Item.getItem(id),kit.items.getOrDefault(id,1)), ItemMergeStrategy.PRESERVE);
|
||||
player.inventory.syncDirtySlots(0,ServerSingletons.getConnection(player));
|
||||
kit_use_info info = player_kit_uses.getOrDefault(playerId,new kit_use_info());
|
||||
info.kit_use.put(kit_id,System.currentTimeMillis());
|
||||
player_kit_uses.put(playerId,info);
|
||||
reload_player_kit_uses(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static long get_kit_timeout(String playerId,String kit_id){
|
||||
if (!kitsMap.containsKey(kit_id))
|
||||
return 0;
|
||||
kit_info kit = kitsMap.get(kit_id);
|
||||
if (!player_kit_uses.containsKey(playerId))
|
||||
return 0;
|
||||
kit_use_info info = player_kit_uses.get(playerId);
|
||||
if (!info.kit_use.containsKey(kit_id))
|
||||
return 0;
|
||||
long use_time = info.kit_use.get(kit_id);
|
||||
long delay_time = (long) ((kit.kit_delay_seconds + kit.kit_delay_minutes*60 + kit.kit_delay_hours*60*60 + kit.kit_delay_days*60*60*24)*1000);
|
||||
long remaining_time= (use_time+delay_time)-System.currentTimeMillis();
|
||||
return Math.max(0,remaining_time);
|
||||
}
|
||||
}
|
27
src/main/java/net/pietru/cookie_utils/kits/kit_info.java
Normal file
27
src/main/java/net/pietru/cookie_utils/kits/kit_info.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package net.pietru.cookie_utils.kits;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class kit_info {
|
||||
public String kit_id = "";
|
||||
public String kit_DisplayName = "";
|
||||
public String kit_Desc = "";
|
||||
public String kit_perm = "";
|
||||
public Float kit_delay_seconds = 0F;
|
||||
public Float kit_delay_minutes = 0F;
|
||||
public Float kit_delay_hours = 0F;
|
||||
public Float kit_delay_days = 0F;
|
||||
public Map<String,Integer> items = new HashMap<>();
|
||||
|
||||
public static kit_info get_default_kit(){
|
||||
kit_info val = new kit_info();
|
||||
val.kit_id="example";
|
||||
val.kit_DisplayName="Example kit";
|
||||
val.kit_Desc="The example user kit...";
|
||||
val.kit_perm="kit.example";
|
||||
val.kit_delay_minutes=1F;
|
||||
val.items.put("base:stick",1);
|
||||
return val;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package net.pietru.cookie_utils.kits;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class kit_use_info {
|
||||
public Map<String,Long> kit_use = new HashMap<>();
|
||||
}
|
|
@ -61,6 +61,15 @@ public class prop {
|
|||
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;}
|
||||
|
||||
|
||||
/*
|
||||
* level 2 - sudo_code info error debug debug+
|
||||
* level 1 - sudo_code info error debug
|
||||
* level 0 - sudo_code info error
|
||||
* level -1 - sudo_code
|
||||
* level -2 - no logs
|
||||
* */
|
||||
if (!panel_prop.containsKey("log_level")){
|
||||
panel_prop.put("log_level","1"); save=true;}
|
||||
log_level = Integer.parseInt((String) panel_prop.getOrDefault("log_level",1));
|
||||
|
|
Loading…
Reference in a new issue