allow region setup to set owner
All checks were successful
/ Auto-Build-App (push) Successful in 5m9s
All checks were successful
/ Auto-Build-App (push) Successful in 5m9s
This commit is contained in:
parent
3575d56063
commit
380276f266
5 changed files with 78 additions and 17 deletions
|
@ -104,18 +104,19 @@ public class TextCommands {
|
|||
});
|
||||
commands.put("setup",(args, networkIdentity, channelHandlerContext) -> {
|
||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||
boolean cancel = false;
|
||||
boolean started = false;
|
||||
if (args.length==2) {
|
||||
boolean a = has_perm(account.getUniqueId(), Setup.get_perm(args[1]));
|
||||
boolean b = has_perm(account.getUniqueId(), "setup.*");
|
||||
if (args[1].equalsIgnoreCase("cancel") || args[1].equalsIgnoreCase("c"))
|
||||
Setup.cancel(account.getUniqueId());
|
||||
if (args[1].equalsIgnoreCase("cancel"))
|
||||
cancel = Setup.cancel(account.getUniqueId());
|
||||
else if (a || b)
|
||||
started = Setup.start(account.getUniqueId(), args[1]);
|
||||
|
||||
}
|
||||
|
||||
MessagePacket packet = new MessagePacket(started ? "[Server] Starting setup.." : "[Server] Failed to start setup... (There might be one running)");
|
||||
MessagePacket packet = new MessagePacket(started ? (cancel ? "[Server] Setup canceled.." : "[Server] Starting setup..") : "[Server] Failed to start setup... (There might be one running)");
|
||||
packet.setupAndSend(channelHandlerContext);
|
||||
|
||||
if (started){
|
||||
|
|
|
@ -57,7 +57,7 @@ public class MessagePacketMixin {
|
|||
TextCommands.run(data,identity,ctx);
|
||||
ci.cancel();
|
||||
} else if (Setup.setups.containsKey(account.getUniqueId())){
|
||||
if (message.equals("!")) {
|
||||
if (message.equals("!") || message.equals("!cancel")) {
|
||||
Setup.cancel(account.getUniqueId());
|
||||
} else {
|
||||
Setup setup = Setup.setups.get(account.getUniqueId());
|
||||
|
@ -72,5 +72,6 @@ public class MessagePacketMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
message=message.replace("\n","");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
package net.pietru.cookie_utils.permissions;
|
||||
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonValue;
|
||||
import com.badlogic.gdx.utils.JsonWriter;
|
||||
import finalforeach.cosmicreach.io.SaveLocation;
|
||||
import net.pietru.cookie_utils.api.Area;
|
||||
import net.pietru.cookie_utils.api.Region;
|
||||
|
||||
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 PlayerAreaPerm {
|
||||
public String filename = "";
|
||||
|
@ -31,4 +42,32 @@ public class PlayerAreaPerm {
|
|||
ObjectPermList.get_default_perms(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
public static PlayerAreaPerm get_owner_perm(String ownerID){
|
||||
PlayerAreaPerm val = new PlayerAreaPerm();
|
||||
val.player_id=ownerID;
|
||||
val.type="owner";
|
||||
val.enabled=true;
|
||||
val.filename=ownerID.replace(":","_")+".json";
|
||||
val.perms.set_bool_perm("place", true);
|
||||
val.perms.set_bool_perm("break", true);
|
||||
val.perms.set_bool_perm("interact", true);
|
||||
val.perms.set_bool_perm("enter", true);
|
||||
return val;
|
||||
}
|
||||
|
||||
public void save(Area area, boolean reload){
|
||||
File perm_file = new File(get_path_string(SaveLocation.getSaveFolder().getPath(), "region_perms", area.name, filename));
|
||||
try {
|
||||
Json json = new Json();
|
||||
json.setOutputType(JsonWriter.OutputType.json);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(perm_file.getPath()));
|
||||
writer.write(json.prettyPrint(get_json().toString()));
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (reload)
|
||||
Region.load_area_player_perms(area);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,17 +107,8 @@ public class areaPermSetup extends Setup {
|
|||
@Override
|
||||
public void run_setup_finish() {
|
||||
isActive=false;
|
||||
File perm_file = new File(get_path_string(SaveLocation.getSaveFolder().getPath(),"region_perms",area.name,plr_perm.filename));
|
||||
try {
|
||||
Json json = new Json();
|
||||
JsonValue val = plr_perm.get_json();
|
||||
json.setOutputType(JsonWriter.OutputType.json);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(perm_file.getPath()));
|
||||
writer.write(json.prettyPrint(val.toString()));
|
||||
writer.close();
|
||||
Region.load_area_player_perms(area);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (plr_perm!=null) {
|
||||
plr_perm.save(area,true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,14 @@ package net.pietru.cookie_utils.setups;
|
|||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonValue;
|
||||
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.api.Region;
|
||||
import net.pietru.cookie_utils.permissions.ObjectPermList;
|
||||
import net.pietru.cookie_utils.permissions.PlayerAreaPerm;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
|
@ -15,16 +17,20 @@ import java.io.FileWriter;
|
|||
import java.util.Objects;
|
||||
|
||||
import static net.pietru.cookie_utils.utils.directory_utils.get_path_string;
|
||||
import static net.pietru.cookie_utils.utils.player_utils.*;
|
||||
|
||||
public class regionSetup extends Setup {
|
||||
Vector3 p1;
|
||||
Vector3 p2;
|
||||
String name="";
|
||||
String zoneId="";
|
||||
String ownerId="";
|
||||
|
||||
Area area;
|
||||
PlayerAreaPerm plr_perm=null;
|
||||
|
||||
public regionSetup() {
|
||||
steps.add(()->{});
|
||||
steps.add(()->{});
|
||||
steps.add(()->{});
|
||||
steps.add(()->{
|
||||
|
@ -36,13 +42,24 @@ public class regionSetup extends Setup {
|
|||
name+=".json";
|
||||
area.name=name;
|
||||
area.zoneId=zoneId;
|
||||
|
||||
|
||||
if (is_plr_valid(ownerId)) {
|
||||
plr_perm = PlayerAreaPerm.get_owner_perm(ownerId);
|
||||
area.player_perms.add(plr_perm);
|
||||
|
||||
step_hints.add("Region creation complete");
|
||||
}else{
|
||||
step_hints.add("Region creation complete. Setting Owner Failed - incorrect ID.");
|
||||
}
|
||||
|
||||
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)...");
|
||||
step_hints.add("Region creation complete");
|
||||
step_hints.add("Should add Owner - Yes/No (Y/N)");
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
|
@ -59,6 +76,10 @@ public class regionSetup extends Setup {
|
|||
isActive=false;
|
||||
area.save(false);
|
||||
|
||||
if (plr_perm!=null) {
|
||||
plr_perm.save(area,false);
|
||||
}
|
||||
|
||||
Region.areas.add(area);
|
||||
Region.sort_areas();
|
||||
|
||||
|
@ -75,7 +96,15 @@ public class regionSetup extends Setup {
|
|||
public boolean set_setup_text(String value) {
|
||||
if (step==2)
|
||||
name=value;
|
||||
return step==2;
|
||||
if (step==3) {
|
||||
if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("yes"))
|
||||
step_hints.add("Please enter player id...");
|
||||
else
|
||||
step_hints.add("Region creation complete");
|
||||
}
|
||||
if (step==4)
|
||||
ownerId=get_player_id(value);
|
||||
return step==2 || step==3 || step==4;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue