This commit is contained in:
parent
d547ca167a
commit
b22dcc6d50
5 changed files with 57 additions and 3 deletions
|
@ -7,6 +7,7 @@ import finalforeach.cosmicreach.blocks.Block;
|
||||||
import dev.crmodders.cosmicquilt.api.entrypoint.ModInitializer;
|
import dev.crmodders.cosmicquilt.api.entrypoint.ModInitializer;
|
||||||
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 org.quiltmc.loader.api.ModContainer;
|
import org.quiltmc.loader.api.ModContainer;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -28,6 +29,9 @@ public class CookieUtils implements ModInitializer {
|
||||||
Region.reload_regions();
|
Region.reload_regions();
|
||||||
System.out.println("CookieUtils loaded perm groups...");
|
System.out.println("CookieUtils loaded perm groups...");
|
||||||
|
|
||||||
|
setupCreator.registerSetupCreators();
|
||||||
|
System.out.println("CookieUtils loaded setup creators...");
|
||||||
|
|
||||||
// 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")) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ 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_area_player_perms;
|
||||||
import static net.pietru.cookie_utils.api.Region.reload_regions;
|
import static net.pietru.cookie_utils.api.Region.reload_regions;
|
||||||
|
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;
|
||||||
|
|
||||||
public class TextCommands {
|
public class TextCommands {
|
||||||
|
@ -62,8 +63,14 @@ public class TextCommands {
|
||||||
commands.put("setup",(args, networkIdentity, channelHandlerContext) -> {
|
commands.put("setup",(args, networkIdentity, channelHandlerContext) -> {
|
||||||
Account account = ServerSingletons.getAccount(networkIdentity);
|
Account account = ServerSingletons.getAccount(networkIdentity);
|
||||||
boolean started = false;
|
boolean started = false;
|
||||||
if (args.length==2)
|
if (args.length==2) {
|
||||||
|
if (has_perm(account.getUniqueId(), Setup.get_perm(args[1])) ||
|
||||||
|
has_perm(account.getUniqueId(), "setup.*"))
|
||||||
started = Setup.start(account.getUniqueId(), args[1]);
|
started = Setup.start(account.getUniqueId(), args[1]);
|
||||||
|
if (args[1].equals("cancel"))
|
||||||
|
Setup.cancel(account.getUniqueId());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
MessagePacket packet = new MessagePacket(started ? "[Server] Starting setup.." : "[Server] Failed to start setup...");
|
MessagePacket packet = new MessagePacket(started ? "[Server] Starting setup.." : "[Server] Failed to start setup...");
|
||||||
packet.playerUniqueId=account.getUniqueId();
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
|
|
|
@ -12,6 +12,7 @@ import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||||
import finalforeach.cosmicreach.world.Zone;
|
import finalforeach.cosmicreach.world.Zone;
|
||||||
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 org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -34,12 +35,24 @@ public class BlockBreakMixin {
|
||||||
private void event_block_break(CallbackInfo ci, @Local NetworkIdentity identity, @Local ChannelHandlerContext ctx){
|
private void event_block_break(CallbackInfo ci, @Local NetworkIdentity identity, @Local ChannelHandlerContext ctx){
|
||||||
if (identity.getSide() != NetworkSide.CLIENT) {
|
if (identity.getSide() != NetworkSide.CLIENT) {
|
||||||
Account account = ServerSingletons.getAccount(identity);
|
Account account = ServerSingletons.getAccount(identity);
|
||||||
|
|
||||||
if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_edit_block(blockPos,"break",account.getUniqueId())) {
|
if (!Permissions.has_user_special_perm(account.getUniqueId()) && !can_edit_block(blockPos,"break",account.getUniqueId())) {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
|
||||||
MessagePacket packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but this area is under protection." : "Sorry but you can't do this action right now. [Config Reload In Progress]"));
|
MessagePacket packet = new MessagePacket("[Server] " + (is_not_reloading ? "Sorry, but this area is under protection." : "Sorry but you can't do this action right now. [Config Reload In Progress]"));
|
||||||
packet.playerUniqueId=account.getUniqueId();
|
packet.playerUniqueId=account.getUniqueId();
|
||||||
packet.setupAndSend(ctx);
|
packet.setupAndSend(ctx);
|
||||||
|
} else if (Setup.setups.containsKey(account.getUniqueId())){
|
||||||
|
Setup setup = Setup.setups.get(account.getUniqueId());
|
||||||
|
if (setup.set_setup_block_pos(blockPos)) {
|
||||||
|
ci.cancel();
|
||||||
|
|
||||||
|
setup.run_step();
|
||||||
|
|
||||||
|
MessagePacket packet = new MessagePacket("[Server] " + setup.get_step_hint());
|
||||||
|
packet.playerUniqueId = account.getUniqueId();
|
||||||
|
packet.setupAndSend(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import finalforeach.cosmicreach.networking.NetworkSide;
|
||||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import net.pietru.cookie_utils.api.TextCommands;
|
import net.pietru.cookie_utils.api.TextCommands;
|
||||||
|
import net.pietru.cookie_utils.setups.Setup;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -26,6 +27,17 @@ public class MessagePacketMixin {
|
||||||
String[] data = cmd.split(" ");
|
String[] data = cmd.split(" ");
|
||||||
TextCommands.run(data,identity,ctx);
|
TextCommands.run(data,identity,ctx);
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
}else if (Setup.setups.containsKey(playerUniqueId)){
|
||||||
|
Setup setup = Setup.setups.get(playerUniqueId);
|
||||||
|
if (setup.set_setup_text(message.replace(" ","_"))) {
|
||||||
|
ci.cancel();
|
||||||
|
|
||||||
|
setup.run_step();
|
||||||
|
|
||||||
|
MessagePacket packet = new MessagePacket("[Server] " + setup.get_step_hint());
|
||||||
|
packet.playerUniqueId = playerUniqueId;
|
||||||
|
packet.setupAndSend(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public abstract class Setup {
|
||||||
public static Map<String, Setup> setups = new HashMap<>();
|
public static Map<String, Setup> setups = new HashMap<>();
|
||||||
|
|
||||||
public static boolean start(String playerId, String setupId){
|
public static boolean start(String playerId, String setupId){
|
||||||
if (!setups.containsKey(playerId))
|
if (setups.containsKey(playerId) && setups.get(playerId).isActive)
|
||||||
return false;
|
return false;
|
||||||
Setup setup = setupCreator.get(setupId);
|
Setup setup = setupCreator.get(setupId);
|
||||||
if (setup==null)
|
if (setup==null)
|
||||||
|
@ -21,6 +21,24 @@ public abstract class Setup {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean cancel(String playerId){
|
||||||
|
if (!setups.containsKey(playerId))
|
||||||
|
return false;
|
||||||
|
Setup setup = setups.get(playerId);
|
||||||
|
if (setup==null)
|
||||||
|
return false;
|
||||||
|
setup.run_setup_canceled();
|
||||||
|
setups.remove(playerId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String get_perm(String setupId){
|
||||||
|
Setup setup = setupCreator.get(setupId);
|
||||||
|
if (setup==null)
|
||||||
|
return "";
|
||||||
|
return setup.get_setup_perm();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isActive = true;
|
public boolean isActive = true;
|
||||||
public int step = 0;
|
public int step = 0;
|
||||||
|
|
Loading…
Reference in a new issue