Refactored Command structure, began support for API driven Rooms
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										4
									
								
								src/main/java/eu/mhsl/minenet/minigames/Api.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/main/java/eu/mhsl/minenet/minigames/Api.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					package eu.mhsl.minenet.minigames;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Api {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -18,9 +18,11 @@ public enum Commands {
 | 
				
			|||||||
    GC(new GcCommand()),
 | 
					    GC(new GcCommand()),
 | 
				
			||||||
    LANGTEST(new LangTestCommand()),
 | 
					    LANGTEST(new LangTestCommand()),
 | 
				
			||||||
    ROOM(new RoomCommand()),
 | 
					    ROOM(new RoomCommand()),
 | 
				
			||||||
    UPDATE(new UpdateCommand()),
 | 
					    UPDATE(new RefreshCommandsCommand()),
 | 
				
			||||||
    OP(new OpCommand()),
 | 
					    OP(new OpCommand()),
 | 
				
			||||||
    FAKEPLAYER(new FakeplayerCommand());
 | 
					    FAKEPLAYER(new FakeplayerCommand()),
 | 
				
			||||||
 | 
					    KICK(new KickCommand()),
 | 
				
			||||||
 | 
					    SETOWNER(new SetRoomOwnerCommand());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Commands(Command handler) {
 | 
					    Commands(Command handler) {
 | 
				
			||||||
        MinecraftServer.getCommandManager().register(handler);
 | 
					        MinecraftServer.getCommandManager().register(handler);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					package eu.mhsl.minenet.minigames.command;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import net.minestom.server.command.builder.Command;
 | 
				
			||||||
 | 
					import net.minestom.server.command.builder.condition.CommandCondition;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.Nullable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class PrivilegedCommand extends Command {
 | 
				
			||||||
 | 
					    private final List<CommandCondition> conditions = new ArrayList<>();
 | 
				
			||||||
 | 
					    public PrivilegedCommand(@NotNull String name, @Nullable String... aliases) {
 | 
				
			||||||
 | 
					        super(name, aliases);
 | 
				
			||||||
 | 
					        construct();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public PrivilegedCommand(@NotNull String name) {
 | 
				
			||||||
 | 
					        super(name);
 | 
				
			||||||
 | 
					        construct();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void construct() {
 | 
				
			||||||
 | 
					        addCondition(isPrivileged());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        setCondition((sender, commandString) -> conditions.parallelStream().allMatch(condition -> condition.canUse(sender, commandString)));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected CommandCondition isPrivileged() {
 | 
				
			||||||
 | 
					        return (sender, commandString) -> sender.hasPermission("admin");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected void addCondition(CommandCondition condition) {
 | 
				
			||||||
 | 
					        conditions.add(condition);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,20 +1,18 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.Icon;
 | 
					import eu.mhsl.minenet.minigames.message.Icon;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.ActionBarMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.ActionBarMessage;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.TitleMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.TitleMessage;
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class DebugCommand extends Command {
 | 
					public class DebugCommand extends PrivilegedCommand {
 | 
				
			||||||
    public DebugCommand() {
 | 
					    public DebugCommand() {
 | 
				
			||||||
        super("debug");
 | 
					        super("debug");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setCondition((sender, commandString) -> sender.hasPermission("admin"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        setDefaultExecutor((sender, args) -> {
 | 
					        setDefaultExecutor((sender, args) -> {
 | 
				
			||||||
            new ChatMessage(Icon.CHAT).appendTranslated("sample").send(sender);
 | 
					            new ChatMessage(Icon.CHAT).appendTranslated("sample").send(sender);
 | 
				
			||||||
            new ActionBarMessage().appendTranslated("sample").send(sender);
 | 
					            new ActionBarMessage().appendTranslated("sample").send(sender);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
 | 
					import eu.mhsl.minenet.minigames.instance.room.Room;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.Icon;
 | 
					import eu.mhsl.minenet.minigames.message.Icon;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					 | 
				
			||||||
import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
					import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
				
			||||||
import net.minestom.server.entity.Player;
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
import net.minestom.server.entity.fakeplayer.FakePlayer;
 | 
					import net.minestom.server.entity.fakeplayer.FakePlayer;
 | 
				
			||||||
@@ -11,7 +11,7 @@ import net.minestom.server.entity.fakeplayer.FakePlayerOption;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FakeplayerCommand extends Command {
 | 
					public class FakeplayerCommand extends PrivilegedCommand {
 | 
				
			||||||
    public FakeplayerCommand() {
 | 
					    public FakeplayerCommand() {
 | 
				
			||||||
        super("fakeplayer");
 | 
					        super("fakeplayer");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,13 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import net.minestom.server.coordinate.Vec;
 | 
					import net.minestom.server.coordinate.Vec;
 | 
				
			||||||
import net.minestom.server.entity.Player;
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FlyCommand extends Command {
 | 
					public class FlyCommand extends PrivilegedCommand {
 | 
				
			||||||
    public FlyCommand() {
 | 
					    public FlyCommand() {
 | 
				
			||||||
        super("fly");
 | 
					        super("fly");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setCondition((sender, commandString) -> sender.hasPermission("admin"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        setDefaultExecutor((sender, context) -> {
 | 
					        setDefaultExecutor((sender, context) -> {
 | 
				
			||||||
            Player p = (Player) sender;
 | 
					            Player p = (Player) sender;
 | 
				
			||||||
            p.setVelocity(new Vec(0, 5, 0));
 | 
					            p.setVelocity(new Vec(0, 5, 0));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,16 +1,15 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import net.minestom.server.command.builder.arguments.ArgumentEnum;
 | 
					import net.minestom.server.command.builder.arguments.ArgumentEnum;
 | 
				
			||||||
import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
					import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
				
			||||||
import net.minestom.server.entity.GameMode;
 | 
					import net.minestom.server.entity.GameMode;
 | 
				
			||||||
import net.minestom.server.entity.Player;
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GamemodeCommand extends Command {
 | 
					public class GamemodeCommand extends PrivilegedCommand {
 | 
				
			||||||
    public GamemodeCommand() {
 | 
					    public GamemodeCommand() {
 | 
				
			||||||
        super("gamemode", "gm");
 | 
					        super("gamemode", "gm");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setCondition((sender, commandString) -> sender.hasPermission("admin"));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        addSyntax((sender, context) -> ((Player) sender).setGameMode(
 | 
					        addSyntax((sender, context) -> ((Player) sender).setGameMode(
 | 
				
			||||||
                context.get("target")),
 | 
					                context.get("target")),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,17 +1,15 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.Icon;
 | 
					import eu.mhsl.minenet.minigames.message.Icon;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.util.Monitoring;
 | 
					import eu.mhsl.minenet.minigames.util.Monitoring;
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GcCommand extends Command {
 | 
					public class GcCommand extends PrivilegedCommand {
 | 
				
			||||||
    private static long lastRun = System.currentTimeMillis();
 | 
					    private static long lastRun = System.currentTimeMillis();
 | 
				
			||||||
    public GcCommand() {
 | 
					    public GcCommand() {
 | 
				
			||||||
        super("gc");
 | 
					        super("gc");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setCondition((sender, commandString) -> sender.hasPermission("admin"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        setDefaultExecutor((sender, context) -> {
 | 
					        setDefaultExecutor((sender, context) -> {
 | 
				
			||||||
            long nextRun = (lastRun - (System.currentTimeMillis() - 30*1000)) / 1000;
 | 
					            long nextRun = (lastRun - (System.currentTimeMillis() - 30*1000)) / 1000;
 | 
				
			||||||
            if(nextRun > 0) {
 | 
					            if(nextRun > 0) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
 | 
					import net.minestom.server.MinecraftServer;
 | 
				
			||||||
 | 
					import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
				
			||||||
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class KickCommand extends PrivilegedCommand {
 | 
				
			||||||
 | 
					    public KickCommand() {
 | 
				
			||||||
 | 
					        super("kick");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        addSyntax(
 | 
				
			||||||
 | 
					            (sender, context) ->
 | 
				
			||||||
 | 
					                kick(context.getRaw("player"), ""),
 | 
				
			||||||
 | 
					                ArgumentType.Entity("player").onlyPlayers(true)
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        addSyntax(
 | 
				
			||||||
 | 
					            (sender, context) ->
 | 
				
			||||||
 | 
					                kick(context.getRaw("player"), context.getRaw("reason")),
 | 
				
			||||||
 | 
					                ArgumentType.Entity("player").onlyPlayers(true),
 | 
				
			||||||
 | 
					                ArgumentType.String("reason")
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void kick(String playername, String reason) {
 | 
				
			||||||
 | 
					        Player playerToKick = MinecraftServer.getConnectionManager().findPlayer(playername);
 | 
				
			||||||
 | 
					        Objects.requireNonNull(playerToKick).kick(reason);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,20 +1,18 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.lang.Languages;
 | 
					import eu.mhsl.minenet.minigames.lang.Languages;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.lang.Lang;
 | 
					import eu.mhsl.minenet.minigames.lang.Lang;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.Icon;
 | 
					import eu.mhsl.minenet.minigames.message.Icon;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
 | 
					import eu.mhsl.minenet.minigames.message.TranslatableMessage;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					 | 
				
			||||||
import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
					import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
				
			||||||
import net.minestom.server.entity.Player;
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class LangTestCommand extends Command {
 | 
					public class LangTestCommand extends PrivilegedCommand {
 | 
				
			||||||
    public LangTestCommand() {
 | 
					    public LangTestCommand() {
 | 
				
			||||||
        super("langtest");
 | 
					        super("langtest");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setCondition((sender, commandString) -> sender.hasPermission("admin"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        setDefaultExecutor((sender, context) -> sendMessage(Languages.getInstance().getLanguage((Player) sender), "sample").send(sender));
 | 
					        setDefaultExecutor((sender, context) -> sendMessage(Languages.getInstance().getLanguage((Player) sender), "sample").send(sender));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var targetString = ArgumentType.String("mapId");
 | 
					        var targetString = ArgumentType.String("mapId");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,19 +1,17 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.Icon;
 | 
					import eu.mhsl.minenet.minigames.message.Icon;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
				
			||||||
import net.minestom.server.MinecraftServer;
 | 
					import net.minestom.server.MinecraftServer;
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					 | 
				
			||||||
import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
					import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
				
			||||||
import net.minestom.server.entity.Player;
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
import net.minestom.server.permission.Permission;
 | 
					import net.minestom.server.permission.Permission;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class OpCommand extends Command {
 | 
					public class OpCommand extends PrivilegedCommand {
 | 
				
			||||||
    public OpCommand() {
 | 
					    public OpCommand() {
 | 
				
			||||||
        super("op");
 | 
					        super("op");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setCondition((sender, commandString) -> sender.hasPermission("admin"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        addSyntax((sender, context) -> {
 | 
					        addSyntax((sender, context) -> {
 | 
				
			||||||
            Player target = MinecraftServer.getConnectionManager().getPlayer(context.getRaw("target"));
 | 
					            Player target = MinecraftServer.getConnectionManager().getPlayer(context.getRaw("target"));
 | 
				
			||||||
            if(target != null) {
 | 
					            if(target != null) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +1,17 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.Icon;
 | 
					import eu.mhsl.minenet.minigames.message.Icon;
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					import net.minestom.server.MinecraftServer;
 | 
				
			||||||
import net.minestom.server.entity.Player;
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class UpdateCommand extends Command {
 | 
					public class RefreshCommandsCommand extends PrivilegedCommand {
 | 
				
			||||||
    public UpdateCommand() {
 | 
					    public RefreshCommandsCommand() {
 | 
				
			||||||
        super("update");
 | 
					        super("refreshCommands");
 | 
				
			||||||
 | 
					 | 
				
			||||||
        setCondition((sender, commandString) -> sender.hasPermission("admin"));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setDefaultExecutor((sender, context) -> {
 | 
					        setDefaultExecutor((sender, context) -> {
 | 
				
			||||||
            ((Player) sender).refreshCommands();
 | 
					            MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(Player::refreshCommands);
 | 
				
			||||||
            new ChatMessage(Icon.SUCCESS).appendStatic("Updated command syntax!").send(sender);
 | 
					            new ChatMessage(Icon.SUCCESS).appendStatic("Updated command syntax!").send(sender);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -1,20 +1,18 @@
 | 
				
			|||||||
package eu.mhsl.minenet.minigames.command.privileged;
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.Icon;
 | 
					import eu.mhsl.minenet.minigames.message.Icon;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
 | 
					import eu.mhsl.minenet.minigames.message.TranslatableMessage;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
					import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
				
			||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
 | 
					import eu.mhsl.minenet.minigames.instance.room.Room;
 | 
				
			||||||
import net.minestom.server.command.builder.Command;
 | 
					 | 
				
			||||||
import net.minestom.server.entity.Player;
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.stream.Collectors;
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class RoomCommand extends Command {
 | 
					public class RoomCommand extends PrivilegedCommand {
 | 
				
			||||||
    public RoomCommand() {
 | 
					    public RoomCommand() {
 | 
				
			||||||
        super("room");
 | 
					        super("room");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setCondition((sender, commandString) -> sender.hasPermission("admin"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        setDefaultExecutor((sender, context) -> {
 | 
					        setDefaultExecutor((sender, context) -> {
 | 
				
			||||||
            TranslatableMessage out = new ChatMessage(Icon.SCIENCE).appendStatic("Rooms:").newLine();
 | 
					            TranslatableMessage out = new ChatMessage(Icon.SCIENCE).appendStatic("Rooms:").newLine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					package eu.mhsl.minenet.minigames.command.privileged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.instance.room.Room;
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.message.Icon;
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.message.type.ChatMessage;
 | 
				
			||||||
 | 
					import net.minestom.server.MinecraftServer;
 | 
				
			||||||
 | 
					import net.minestom.server.command.builder.arguments.ArgumentType;
 | 
				
			||||||
 | 
					import net.minestom.server.command.builder.condition.CommandCondition;
 | 
				
			||||||
 | 
					import net.minestom.server.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SetRoomOwnerCommand extends PrivilegedCommand {
 | 
				
			||||||
 | 
					    public SetRoomOwnerCommand() {
 | 
				
			||||||
 | 
					        super("setRoomOwner");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        addCondition((sender, commandString) -> ((Player) sender).getInstance() instanceof Room);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        setDefaultExecutor((sender, context) -> {
 | 
				
			||||||
 | 
					            if(sender instanceof Player p) {
 | 
				
			||||||
 | 
					                Room.getRoom(p).setOwner(p);
 | 
				
			||||||
 | 
					                new ChatMessage(Icon.SUCCESS).appendStatic("You are now the owner of this room!").send(sender);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        addSyntax((sender, context) -> {
 | 
				
			||||||
 | 
					            System.out.println("Test");
 | 
				
			||||||
 | 
					            if(sender instanceof Player p) {
 | 
				
			||||||
 | 
					                Player newOwner = MinecraftServer.getConnectionManager().getPlayer(context.getRaw("player"));
 | 
				
			||||||
 | 
					                Room.getRoom(p).setOwner(Objects.requireNonNull(newOwner));
 | 
				
			||||||
 | 
					                new ChatMessage(Icon.SUCCESS).appendStatic("The new owner has been set!").send(sender);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }, ArgumentType.Entity("player").onlyPlayers(true));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    protected CommandCondition isPrivileged() {
 | 
				
			||||||
 | 
					        return (sender, commandString) -> super.isPrivileged().canUse(sender, commandString) || Room.getRoom(((Player) sender)).getOwner() == sender;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -70,24 +70,28 @@ public class Room extends MineNetInstance implements Spawnable {
 | 
				
			|||||||
    private Player owner;
 | 
					    private Player owner;
 | 
				
			||||||
    private Room(Player owner) {
 | 
					    private Room(Player owner) {
 | 
				
			||||||
        super(Dimension.THE_END.DIMENSION);
 | 
					        super(Dimension.THE_END.DIMENSION);
 | 
				
			||||||
 | 
					        construct();
 | 
				
			||||||
 | 
					        setOwner(owner);
 | 
				
			||||||
 | 
					        new GameSelector().setInstance(this, new Pos(0.5, 16, 9.5));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected Room() {
 | 
				
			||||||
 | 
					        super(Dimension.THE_END.DIMENSION);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void construct() {
 | 
				
			||||||
        MinecraftServer.getInstanceManager().registerInstance(this);
 | 
					        MinecraftServer.getInstanceManager().registerInstance(this);
 | 
				
			||||||
        setChunkLoader(new AnvilLoader(Resource.LOBBY_MAP.getPath()));
 | 
					        setChunkLoader(new AnvilLoader(Resource.LOBBY_MAP.getPath()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        eventNode().addListener(PlayerBlockBreakEvent.class, CommonEventHandles::cancel);
 | 
					        eventNode().addListener(PlayerBlockBreakEvent.class, CommonEventHandles::cancel);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        eventNode().addListener(PlayerDisconnectEvent.class, playerDisconnectEvent -> unsetRoom(playerDisconnectEvent.getPlayer()));
 | 
					        eventNode().addListener(PlayerDisconnectEvent.class, playerDisconnectEvent -> unsetRoom(playerDisconnectEvent.getPlayer()));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        setOwner(owner);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        new GameSelector().setInstance(this, new Pos(0.5, 16, 9.5));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Player getOwner() {
 | 
					    public Player getOwner() {
 | 
				
			||||||
        return owner;
 | 
					        return owner;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void setOwner(Player newOwner) {
 | 
					    public void setOwner(Player newOwner) {
 | 
				
			||||||
        this.owner = newOwner;
 | 
					        this.owner = newOwner;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.owner.eventNode().addListener(PlayerDisconnectEvent.class, playerDisconnectEvent -> {
 | 
					        this.owner.eventNode().addListener(PlayerDisconnectEvent.class, playerDisconnectEvent -> {
 | 
				
			||||||
@@ -97,7 +101,7 @@ public class Room extends MineNetInstance implements Spawnable {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            getAllMembers().stream()
 | 
					            getAllMembers().stream()
 | 
				
			||||||
                    .filter(player -> player != p) // exclude the current leaving owner
 | 
					                    .filter(player -> player != p) // exclude the current leaving owner
 | 
				
			||||||
                    .findFirst() // find first user meeting the requirement
 | 
					                    .findFirst() // find the first user meeting the requirement
 | 
				
			||||||
                    .ifPresentOrElse(
 | 
					                    .ifPresentOrElse(
 | 
				
			||||||
                            this::setOwner, // set the new owner
 | 
					                            this::setOwner, // set the new owner
 | 
				
			||||||
                            () -> Room.deleteRoom(Room.getRoom(p)) // or else delete the room (no players in the room)
 | 
					                            () -> Room.deleteRoom(Room.getRoom(p)) // or else delete the room (no players in the room)
 | 
				
			||||||
@@ -108,10 +112,7 @@ public class Room extends MineNetInstance implements Spawnable {
 | 
				
			|||||||
            new ChatMessage(Icon.ERROR).appendStatic("The room leader left!").send(getAllMembers());
 | 
					            new ChatMessage(Icon.ERROR).appendStatic("The room leader left!").send(getAllMembers());
 | 
				
			||||||
            new ChatMessage(Icon.SCIENCE).appendStatic(this.owner.getUsername()).appendStatic(" is the new Leader!").send(getAllMembers().stream().filter(player -> player != this.owner).collect(Collectors.toSet()));
 | 
					            new ChatMessage(Icon.SCIENCE).appendStatic(this.owner.getUsername()).appendStatic(" is the new Leader!").send(getAllMembers().stream().filter(player -> player != this.owner).collect(Collectors.toSet()));
 | 
				
			||||||
            new ChatMessage(Icon.SUCCESS).appendStatic("You are now the leader.").send(this.owner);
 | 
					            new ChatMessage(Icon.SUCCESS).appendStatic("You are now the leader.").send(this.owner);
 | 
				
			||||||
 | 
					 | 
				
			||||||
            logger.info("Room owner changed from " + p.getUsername() + " to " + owner.getUsername());
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void moveMembersToGame(Game game) {
 | 
					    public void moveMembersToGame(Game game) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					package eu.mhsl.minenet.minigames.instance.virtualRoom;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.mhsl.minenet.minigames.instance.room.Room;
 | 
				
			||||||
 | 
					import net.minestom.server.coordinate.Pos;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class VirtualRoom extends Room {
 | 
				
			||||||
 | 
					    public VirtualRoom() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Pos getSpawn() {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -30,6 +30,7 @@ public abstract class Score {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setDone() {
 | 
					    public void setDone() {
 | 
				
			||||||
 | 
					        if(isDone) return;
 | 
				
			||||||
        isDone = true;
 | 
					        isDone = true;
 | 
				
			||||||
        new ChatMessage(Icon.STAR, true)
 | 
					        new ChatMessage(Icon.STAR, true)
 | 
				
			||||||
                .appendTranslated("score#result")
 | 
					                .appendTranslated("score#result")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user