Skip to content

Commit

Permalink
Use kit module from Nucleus for the reward service
Browse files Browse the repository at this point in the history
First register the reward kit with Nucleus `/kit create <name>`. Then register it with BlockyArena `/ba create kit <name>`. To unregister the kit with BlockyArena, execute `/ba remove kit <name>`.
  • Loading branch information
Darcy Chen committed Jan 26, 2021
1 parent d8c6055 commit f589f17
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/io/github/mrdarcychen/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
10 changes: 9 additions & 1 deletion src/main/java/io/github/mrdarcychen/commands/CmdCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <type>. Must be arena."));
}
return CommandResult.empty();
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/io/github/mrdarcychen/commands/CmdRemove.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,6 +46,7 @@ private CmdRemove() {

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Player player = (Player) src;
String type = args.<String>getOne("type").get().toLowerCase();
String id = args.<String>getOne("id").get().toLowerCase();
switch (type) {
Expand All @@ -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("<type> must be arena."));
return CommandResult.empty();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/github/mrdarcychen/commands/RewardService.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +62,7 @@ public StoppingState(GameSession gameSession, List<Player> players, Team winner,
new Timer(5, (tMinus) -> {
if (tMinus == 0) {
gameSession.setMatchState(new LeavingState(gameSession, players));
winner.getPlayers().forEach(RewardService::offer);
}
});
}
Expand Down

0 comments on commit f589f17

Please sign in to comment.