Wide variety of changes for release

This commit is contained in:
2023-12-27 01:16:58 +01:00
parent c63e4badf4
commit 7ea619c596
46 changed files with 484 additions and 63 deletions

View File

@@ -24,7 +24,15 @@ public enum Commands {
FAKEPLAYER(new FakeplayerCommand()),
KICK(new KickCommand()),
SKIN(new SkinCommand()),
SETOWNER(new SetRoomOwnerCommand());
SETOWNER(new SetRoomOwnerCommand()),
SETREWARD(new SetRewardCommand()),
PUBLISHREWARD(new PublishRewardCommand()),
ROOMPROXYMOVE(new InstanceProxyMoveCommand()),
GAMESTART(new GameStartCommand()),
GAMESTOP(new GameStopCommand()),
GAMETIMEOUT(new GameTimeoutCommand()),
PLAYERLIMIT(new PlayerLimitCommand()),
SETMEMORIAL(new SetMemorialCommand());
Commands(Command handler) {
MinecraftServer.getCommandManager().register(handler);

View File

@@ -0,0 +1,17 @@
package eu.mhsl.minenet.minigames.command.privileged;
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import net.minestom.server.entity.Player;
public class GameStartCommand extends PrivilegedCommand {
public GameStartCommand() {
super("gameStart");
setDefaultExecutor((sender, context) -> {
Player player = (Player) sender;
if(player.getInstance() instanceof StatelessGame game) {
game.startAccessor();
}
});
}
}

View File

@@ -0,0 +1,17 @@
package eu.mhsl.minenet.minigames.command.privileged;
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import net.minestom.server.entity.Player;
public class GameStopCommand extends PrivilegedCommand {
public GameStopCommand() {
super("gameStop");
setDefaultExecutor((sender, context) -> {
Player player = (Player) sender;
if(player.getInstance() instanceof StatelessGame game) {
game.stop();
}
});
}
}

View File

@@ -0,0 +1,22 @@
package eu.mhsl.minenet.minigames.command.privileged;
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
import net.minestom.server.entity.Player;
public class GameTimeoutCommand extends PrivilegedCommand {
public GameTimeoutCommand() {
super("gameTimeout");
ArgumentInteger timeout = ArgumentType.Integer("timeout");
addSyntax((sender, context) -> {
Player player = (Player) sender;
if(player.getInstance() instanceof StatelessGame game) {
game.setTimeLimit(context.get(timeout));
}
}, timeout);
}
}

View File

@@ -0,0 +1,24 @@
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.util.PluginMessageUtil;
import net.minestom.server.command.builder.arguments.ArgumentWord;
import net.minestom.server.entity.Player;
import net.minestom.server.instance.Instance;
public class InstanceProxyMoveCommand extends PrivilegedCommand {
public InstanceProxyMoveCommand() {
super("instanceProxyMove");
ArgumentWord serverArgument = new ArgumentWord("server");
addSyntax((sender, context) -> {
Instance room = ((Player) sender).getInstance();
room.getPlayers().forEach(player -> {
Room.unsetRoom(player);
PluginMessageUtil.connect(player, context.get(serverArgument));
});
}, serverArgument);
}
}

View File

@@ -0,0 +1,17 @@
package eu.mhsl.minenet.minigames.command.privileged;
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
public class PlayerLimitCommand extends PrivilegedCommand {
public PlayerLimitCommand() {
super("playerLimit");
ArgumentInteger count = ArgumentType.Integer("count");
addSyntax((sender, context) -> {
System.setProperty("minenet.playerlimit", String.valueOf(context.get(count)));
}, count);
}
}

View File

@@ -0,0 +1,39 @@
package eu.mhsl.minenet.minigames.command.privileged;
import com.google.gson.Gson;
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import eu.mhsl.minenet.minigames.instance.room.Room;
import eu.mhsl.minenet.minigames.score.tournament.TournamentDisplay;
import net.minestom.server.entity.Player;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class PublishRewardCommand extends PrivilegedCommand {
private final HttpClient rewardPublishClient = HttpClient.newHttpClient();
public PublishRewardCommand() {
super("publishReward");
setDefaultExecutor((sender, context) -> {
try {
Room room = Room.getRoom((Player) sender).orElseThrow();
TournamentDisplay world = new TournamentDisplay(room.getTournament());
room.moveMembersToInstance(world);
String rewardRequestJson = new Gson().toJson(room.getTournament().getRewards());
HttpRequest giveRewardsRequest = HttpRequest.newBuilder()
.uri(new URI("http://10.20.6.1:8080/api/event/reward"))
.POST(HttpRequest.BodyPublishers.ofString(rewardRequestJson))
.build();
room.getTournament().getRewards();
HttpResponse<Void> rawResponse = rewardPublishClient.send(giveRewardsRequest, HttpResponse.BodyHandlers.discarding());
sender.sendMessage(String.format("Rewards published: HTTP %s", rawResponse.statusCode()));
} catch (Exception e) {
sender.sendMessage(e.getMessage());
}
});
}
}

View File

@@ -0,0 +1,57 @@
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.score.tournament.MemorialConfiguration;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.command.builder.arguments.ArgumentString;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
import net.minestom.server.entity.Player;
import net.minestom.server.item.Material;
public class SetMemorialCommand extends PrivilegedCommand {
public SetMemorialCommand() {
super("setMemorial");
ArgumentString materialArgument = ArgumentType.String("material");
ArgumentString titleArgument = ArgumentType.String("title");
ArgumentString loreArgument = ArgumentType.String("lore");
materialArgument.setSuggestionCallback((sender, context, suggestion) -> {
Material
.values()
.stream()
.map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
.forEach(suggestion::addEntry);
});
addSyntax((sender, context) -> {
Room
.getRoom((Player) sender)
.orElseThrow()
.getTournament()
.setMemorialConfiguration(
new MemorialConfiguration(
Material.fromNamespaceId(context.get(materialArgument)),
context.get(titleArgument),
context.get(loreArgument)
)
);
sender.sendMessage(
Component.text()
.append(Component.text("Memorial gesetzt:", NamedTextColor.GOLD))
.appendNewline()
.append(Component.text(context.get(materialArgument), NamedTextColor.AQUA))
.appendNewline()
.append(Component.text(context.get(titleArgument), NamedTextColor.RED))
.appendNewline()
.append(Component.text(context.get(loreArgument), NamedTextColor.DARK_RED))
.build()
);
}, materialArgument, titleArgument, loreArgument);
}
}

View File

@@ -0,0 +1,56 @@
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.score.tournament.RewardConfiguration;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.command.builder.arguments.ArgumentStringArray;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.ArgumentWord;
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
import net.minestom.server.entity.Player;
import net.minestom.server.item.Material;
import java.util.Arrays;
import java.util.stream.Collectors;
public class SetRewardCommand extends PrivilegedCommand {
public SetRewardCommand() {
super("setRewards");
ArgumentWord materialArgument = ArgumentType.Word("material");
ArgumentStringArray amountsArgument = ArgumentType.StringArray("amount");
materialArgument.setSuggestionCallback((sender, context, suggestion) -> {
Material
.values()
.stream()
.map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
.forEach(suggestion::addEntry);
});
addSyntax((sender, context) -> {
Room
.getRoom((Player) sender)
.orElseThrow()
.getTournament()
.setRewardConfiguration(
new RewardConfiguration(
Material.fromNamespaceId(context.get(materialArgument)),
Arrays.stream(context.get(amountsArgument)).map(Integer::valueOf).collect(Collectors.toList())
)
);
sender.sendMessage(
Component.text()
.append(Component.text("Belohnung gesetzt:", NamedTextColor.GOLD))
.appendNewline()
.append(Component.text(context.get(materialArgument), NamedTextColor.AQUA))
.appendNewline()
.append(Component.text(String.join(", ", context.get(amountsArgument)), NamedTextColor.RED))
.build()
);
}, materialArgument, amountsArgument);
}
}