From f589f17283b7d465fcc8854a7d8c1d13b5702af3 Mon Sep 17 00:00:00 2001 From: Darcy Chen Date: Tue, 26 Jan 2021 10:07:52 -0800 Subject: [PATCH] Use kit module from Nucleus for the reward service First register the reward kit with Nucleus `/kit create `. Then register it with BlockyArena `/ba create kit `. To unregister the kit with BlockyArena, execute `/ba remove kit `. --- build.gradle.kts | 2 +- .../java/io/github/mrdarcychen/ConfigManager.java | 8 ++++++-- .../io/github/mrdarcychen/commands/CmdCreate.java | 10 +++++++++- .../io/github/mrdarcychen/commands/CmdRemove.java | 8 ++++++++ .../mrdarcychen/commands/RewardService.java | 15 +++++++++++++++ .../mrdarcychen/games/states/StoppingState.java | 2 ++ 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/main/java/io/github/mrdarcychen/commands/RewardService.java diff --git a/build.gradle.kts b/build.gradle.kts index 7d295b8..8d63772 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "io.github.mrdarcychen" -version = "0.6.1" +version = "0.7.0-rc1" description = "A deathmatch plugin for Minecraft servers" dependencies { diff --git a/src/main/java/io/github/mrdarcychen/ConfigManager.java b/src/main/java/io/github/mrdarcychen/ConfigManager.java index 8578f91..f696d4d 100644 --- a/src/main/java/io/github/mrdarcychen/ConfigManager.java +++ b/src/main/java/io/github/mrdarcychen/ConfigManager.java @@ -55,7 +55,7 @@ public void load(Path defaultConfigDir) { System.out.println("Creating a default config for BlockyArena."); this.rootNode = loader.createEmptyNode(ConfigurationOptions.defaults()); this.rootNode.getNode("timers", "lobby", "cooldownSec").setValue(15); - + this.rootNode.getNode("reward").setValue(""); try { loader.save(rootNode); @@ -101,4 +101,8 @@ public ConfigurationNode getConfNode(Object... path) { public int getLobbyCountdown() { return rootNode.getNode("timers", "lobby", "cooldownSec").getInt(); } -} + + public String getRewardKitName() { + return rootNode.getNode("reward").getString(); + } +} diff --git a/src/main/java/io/github/mrdarcychen/commands/CmdCreate.java b/src/main/java/io/github/mrdarcychen/commands/CmdCreate.java index 6a3a281..6a7d14e 100644 --- a/src/main/java/io/github/mrdarcychen/commands/CmdCreate.java +++ b/src/main/java/io/github/mrdarcychen/commands/CmdCreate.java @@ -16,6 +16,8 @@ package io.github.mrdarcychen.commands; +import io.github.mrdarcychen.ConfigManager; +import org.spongepowered.api.Sponge; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; @@ -61,9 +63,15 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm player.sendMessage(Text.of("Execute /ba edit " + id + " save when you're done.")); player.sendMessage(Text.of("Execute /ba create arena " + id + " to start over.")); return CommandResult.success(); + case "reward": + ConfigManager.getInstance().getConfNode("reward").setValue(id); + Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "kit onetime " + id + " true"); + player.sendMessage(Text.of("Reward has been set to " + id + ". Winners must have the permission \n" + + "nucleus.kits." + id + " in order to receive this reward.")); + return CommandResult.success(); default: player.sendMessage(Text.of("Invalid argument . Must be arena.")); } return CommandResult.empty(); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/mrdarcychen/commands/CmdRemove.java b/src/main/java/io/github/mrdarcychen/commands/CmdRemove.java index c191dda..3e5b1ef 100644 --- a/src/main/java/io/github/mrdarcychen/commands/CmdRemove.java +++ b/src/main/java/io/github/mrdarcychen/commands/CmdRemove.java @@ -17,12 +17,15 @@ package io.github.mrdarcychen.commands; import io.github.mrdarcychen.BlockyArena; +import io.github.mrdarcychen.ConfigManager; +import org.spongepowered.api.Sponge; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.args.CommandContext; import org.spongepowered.api.command.spec.CommandExecutor; import org.spongepowered.api.command.spec.CommandSpec; +import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.text.Text; import static org.spongepowered.api.command.args.GenericArguments.onlyOne; @@ -43,6 +46,7 @@ private CmdRemove() { @Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { + Player player = (Player) src; String type = args.getOne("type").get().toLowerCase(); String id = args.getOne("id").get().toLowerCase(); switch (type) { @@ -54,6 +58,10 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm src.sendMessage(Text.of(e.getMessage())); return CommandResult.empty(); } + case "reward": + ConfigManager.getInstance().getConfNode("reward").setValue(""); + Sponge.getCommandManager().process(Sponge.getServer().getConsole(), "kit onetime " + id + " false"); + player.sendMessage(Text.of("Winner(s) will no longer receive " + id + " as the reward.")); default: src.sendMessage(Text.of(" must be arena.")); return CommandResult.empty(); diff --git a/src/main/java/io/github/mrdarcychen/commands/RewardService.java b/src/main/java/io/github/mrdarcychen/commands/RewardService.java new file mode 100644 index 0000000..3303e55 --- /dev/null +++ b/src/main/java/io/github/mrdarcychen/commands/RewardService.java @@ -0,0 +1,15 @@ +package io.github.mrdarcychen.commands; + +import io.github.mrdarcychen.ConfigManager; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.entity.living.player.Player; + +public class RewardService { + + public static void offer(Player player) { + String kitName = ConfigManager.getInstance().getRewardKitName(); + Sponge.getCommandManager().process(Sponge.getServer().getConsole(), + "kit resetusage " + player.getName() + " " + kitName); + Sponge.getCommandManager().process(player, "kit " + kitName); + } +} diff --git a/src/main/java/io/github/mrdarcychen/games/states/StoppingState.java b/src/main/java/io/github/mrdarcychen/games/states/StoppingState.java index 2121749..3fbc572 100644 --- a/src/main/java/io/github/mrdarcychen/games/states/StoppingState.java +++ b/src/main/java/io/github/mrdarcychen/games/states/StoppingState.java @@ -16,6 +16,7 @@ package io.github.mrdarcychen.games.states; +import io.github.mrdarcychen.commands.RewardService; import io.github.mrdarcychen.games.GameSession; import org.spongepowered.api.effect.sound.SoundTypes; import org.spongepowered.api.entity.living.player.Player; @@ -61,6 +62,7 @@ public StoppingState(GameSession gameSession, List players, Team winner, new Timer(5, (tMinus) -> { if (tMinus == 0) { gameSession.setMatchState(new LeavingState(gameSession, players)); + winner.getPlayers().forEach(RewardService::offer); } }); }