add setup, add setting and clearing groups
Some checks failed
/ Auto-Build-App (push) Has been cancelled
Some checks failed
/ Auto-Build-App (push) Has been cancelled
This commit is contained in:
parent
b2b55f322b
commit
ce97ad3c86
8 changed files with 229 additions and 3 deletions
|
@ -3,8 +3,8 @@ Server sideMod/Plugin for game Cosmic Reach.\
|
|||
Based on the example mod for the [Cosmic Quilt](https://codeberg.org/CRModders/cosmic-quilt) Loader
|
||||
|
||||
## Mod requires
|
||||
- Cosmic Reach (0.3.2-pre5 +)
|
||||
- Cosmic Quilt (2.3.2+)
|
||||
- Cosmic Reach (0.3.2-pre10 +)
|
||||
- Cosmic Quilt (2.3.1+)
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
|
|
@ -9,9 +9,11 @@ import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
|||
import finalforeach.cosmicreach.savelib.utils.TriConsumer;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.pietru.cookie_utils.permissions.Permissions;
|
||||
import net.pietru.cookie_utils.setups.Setup;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.pietru.cookie_utils.api.Region.reload_area_player_perms;
|
||||
import static net.pietru.cookie_utils.api.Region.reload_regions;
|
||||
|
@ -57,6 +59,22 @@ public class TextCommands {
|
|||
packet.playerUniqueId=account.getUniqueId();
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
});
|
||||
commands.put("setup",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
boolean started = false;
|
||||
if (args.length==2)
|
||||
started = Setup.start(account.getUniqueId(),args[1]);
|
||||
|
||||
MessagePacket packet = new MessagePacket(started ? "Starting setup.." : "Failed to start setup...");
|
||||
packet.playerUniqueId=account.getUniqueId();
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
|
||||
if (started){
|
||||
packet = new MessagePacket(Setup.setups.get(account.getUniqueId()).get_step_hint());
|
||||
packet.playerUniqueId=account.getUniqueId();
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
commands.put("perm_code",(args, networkIdentity, channelHandlerContext) -> {
|
||||
|
@ -75,6 +93,17 @@ public class TextCommands {
|
|||
}
|
||||
});
|
||||
|
||||
commands.put("group",(args, networkIdentity, channelHandlerContext) -> {
|
||||
if (args.length==4) {
|
||||
if (Objects.equals(args[1], "set"))
|
||||
Permissions.set_group(args[2],args[3]);
|
||||
}
|
||||
else if (args.length==3) {
|
||||
if (Objects.equals(args[1], "clear"))
|
||||
Permissions.clear_group(args[2]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
commands.put("reload_regions",(args, networkIdentity, channelHandlerContext) -> {
|
||||
MessagePacket packet = null;
|
||||
|
|
|
@ -32,4 +32,13 @@ public class ObjectPermList {
|
|||
val.addChild("canExplode", new JsonValue(false));
|
||||
val.addChild("canEnter", new JsonValue(true));
|
||||
}
|
||||
|
||||
public static void get_default_perms(ObjectPermList val){
|
||||
val.set_bool_perm("canPlace", false);
|
||||
val.set_bool_perm("canBreak", false);
|
||||
val.set_bool_perm("canInteract", false);
|
||||
|
||||
val.set_bool_perm("canExplode", false);
|
||||
val.set_bool_perm("canEnter", true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,6 +114,16 @@ public class Permissions {
|
|||
return has_user_special_perm(playerId) || group.has_perm(perm);
|
||||
}
|
||||
|
||||
public static void set_group(String playerId,String group){
|
||||
player_group.put(playerId,group);
|
||||
reload_player_groups(false);
|
||||
}
|
||||
|
||||
public static void clear_group(String playerId){
|
||||
player_group.remove(playerId);
|
||||
reload_player_groups(false);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////sudo code/////////////////////////////////////////////////////////////////
|
||||
|
|
63
src/main/java/net/pietru/cookie_utils/setups/Setup.java
Normal file
63
src/main/java/net/pietru/cookie_utils/setups/Setup.java
Normal file
|
@ -0,0 +1,63 @@
|
|||
package net.pietru.cookie_utils.setups;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import finalforeach.cosmicreach.blocks.BlockPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Setup {
|
||||
|
||||
public static Map<String, Setup> setups = new HashMap<>();
|
||||
|
||||
public static boolean start(String playerId, String setupId){
|
||||
if (!setups.containsKey(playerId))
|
||||
return false;
|
||||
Setup setup = setupCreator.get(setupId);
|
||||
if (setup==null)
|
||||
return false;
|
||||
setups.put(playerId,setup);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean isActive = true;
|
||||
public int step = 0;
|
||||
public ArrayList<Runnable> steps = new ArrayList<>();
|
||||
public ArrayList<String> step_hints = new ArrayList<>();
|
||||
|
||||
public abstract void register();
|
||||
|
||||
public void run_step(){
|
||||
if (!isActive)
|
||||
return;
|
||||
if (steps.size()<=step) {
|
||||
isActive=false;
|
||||
run_setup_finish();
|
||||
return;
|
||||
}
|
||||
Runnable runnable = steps.get(step);
|
||||
step++;
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
public String get_step_hint(){
|
||||
if (step_hints.size()<=step) {
|
||||
return "";
|
||||
}
|
||||
return step_hints.get(step);
|
||||
}
|
||||
|
||||
public abstract String get_setup_perm();
|
||||
|
||||
public boolean is_last_step(){
|
||||
return steps.size()-1 == step;
|
||||
}
|
||||
public abstract void run_setup_finish();
|
||||
public abstract void run_setup_canceled();
|
||||
|
||||
public abstract boolean set_setup_text(String value);
|
||||
public abstract boolean set_setup_vector3(Vector3 value);
|
||||
public abstract boolean set_setup_block_pos(BlockPosition value);
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package net.pietru.cookie_utils.setups;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonWriter;
|
||||
import finalforeach.cosmicreach.blocks.BlockPosition;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import net.pietru.cookie_utils.api.Area;
|
||||
import net.pietru.cookie_utils.permissions.ObjectPermList;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
||||
|
||||
public class regionSetup extends Setup {
|
||||
Vector3 p1;
|
||||
Vector3 p2;
|
||||
String name="";
|
||||
|
||||
Area area;
|
||||
|
||||
public regionSetup() {
|
||||
steps.add(()->{});
|
||||
steps.add(()->{});
|
||||
steps.add(()->{
|
||||
area = new Area();
|
||||
area.enabled=true;
|
||||
ObjectPermList.get_default_perms(area.perms);
|
||||
area.setCorners(p1,p2);
|
||||
if (!name.endsWith(".json"))
|
||||
name+=".json";
|
||||
run_setup_finish();
|
||||
});
|
||||
|
||||
step_hints.add("Please select first position...");
|
||||
step_hints.add("Please select second position...");
|
||||
step_hints.add("Please enter region name (single word)...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
setupCreator.registerSetupCreator("region", regionSetup::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get_setup_perm() {
|
||||
return "setup.region";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run_setup_finish() {
|
||||
isActive=false;
|
||||
File area_file = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"regions",name));
|
||||
try {
|
||||
if (!area_file.exists()) {
|
||||
Json json = new Json();
|
||||
json.setOutputType(JsonWriter.OutputType.json);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(area_file.getPath()));
|
||||
writer.write(json.prettyPrint(area));
|
||||
writer.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run_setup_canceled() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set_setup_text(String value) {
|
||||
if (step==2)
|
||||
name=value;
|
||||
return step==2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set_setup_vector3(Vector3 value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set_setup_block_pos(BlockPosition value) {
|
||||
if (step==0)
|
||||
p1=new Vector3(value.getGlobalX(),value.getGlobalY(),value.getGlobalZ());
|
||||
else if (step==1)
|
||||
p2=new Vector3(value.getGlobalX(),value.getGlobalY(),value.getGlobalZ());
|
||||
return step==0 || step==1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package net.pietru.cookie_utils.setups;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
public interface setupCreator {
|
||||
ObjectMap<String, setupCreator> setupCreators = new ObjectMap<>();
|
||||
|
||||
static void registerSetupCreators() {
|
||||
regionSetup.register();
|
||||
}
|
||||
|
||||
static void registerSetupCreator(String setupId, setupCreator creator) {
|
||||
setupCreators.put(setupId, creator);
|
||||
}
|
||||
|
||||
Setup create();
|
||||
|
||||
static Setup get(String setupId) {
|
||||
return setupId == null ? null : setupCreators.get(setupId).create();
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@
|
|||
"depends": [
|
||||
{
|
||||
"id": "cosmic_quilt",
|
||||
"versions": ">=2.0.2"
|
||||
"versions": ">=2.3.1"
|
||||
},
|
||||
{
|
||||
"id": "cosmic_reach",
|
||||
|
|
Loading…
Reference in a new issue