Add /ma addreward command.

This command takes an arena player and a Thing as input. The Thing is
parsed in the same way as all other rewards are parsed, so it supports
the new `all()` and `random()` functions and the `nothing` keyword.

The "target audience" of the command is mainly scripts. It opens up the
possibility of hooking into MobArena's rewards from command blocks or
other plugins, but with very low coupling.

Closes #643
This commit is contained in:
Andreas Troelsen
2020-09-19 10:32:03 +02:00
parent 3b132d28dd
commit dafae0cf07
4 changed files with 98 additions and 0 deletions
+1
View File
@@ -21,6 +21,7 @@ These changes will (most likely) be included in the next version.
- It is now possible to group rewards. For example, `all(stick, bone)` results a stick and a bone, while `random(all(stick, bone), all(dirt, stone))` results in getting _either_ a stick and a bone _or_ a dirt block and a stone block.
- The new `nothing` keyword can be used to _not_ grant a reward. This can be used in a crude way to create "loot table"-style reward systems where there is a _chance_ that something is reward, but it might also just be nothing.
- Boss rewards also support the `all()` and `random()` functions as well as the `nothing` keyword.
- New command `/ma addreward <player> <thing>` can be used to add a reward to an arena player's reward list. This can be useful for hooking into the rewards system from scripts or other plugins.
- The Root Target ability now uses potion effects (slowness, slow falling, and negative jump boost) instead of repeated teleports. This should make for a smoother root experience.
- Using `spectate-on-death: true` no longer forces players out to their join location/exit warp before moving them to the spectator area. This should prevent "jumpy" behavior in multi-world setups.
- Players should now properly respawn at the spectator area rather than at world spawn on servers with plugins that override respawn locations.
@@ -4,6 +4,7 @@ import com.garbagemule.MobArena.ConfigError;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.MobArena;
import com.garbagemule.MobArena.Msg;
import com.garbagemule.MobArena.commands.admin.AddRewardCommand;
import com.garbagemule.MobArena.commands.admin.DisableCommand;
import com.garbagemule.MobArena.commands.admin.EnableCommand;
import com.garbagemule.MobArena.commands.admin.ForceCommand;
@@ -319,6 +320,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter
register(ForceCommand.class);
register(KickCommand.class);
register(RestoreCommand.class);
register(AddRewardCommand.class);
// mobarena.setup
register(SetupCommand.class);
@@ -0,0 +1,91 @@
package com.garbagemule.MobArena.commands.admin;
import com.garbagemule.MobArena.Msg;
import com.garbagemule.MobArena.commands.Command;
import com.garbagemule.MobArena.commands.CommandInfo;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.framework.ArenaMaster;
import com.garbagemule.MobArena.things.Thing;
import com.garbagemule.MobArena.things.ThingPicker;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@CommandInfo(
name = "addreward",
pattern = "addreward",
usage = "/ma addreward <player> <thing>",
desc = "add a reward to an arena player's rewards list",
permission = "mobarena.admin.addreward"
)
public class AddRewardCommand implements Command {
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (args.length < 2) {
return false;
}
Player player = am.getPlugin().getServer().getPlayer(args[0]);
if (player == null) {
am.getGlobalMessenger().tell(sender, "Player not found.");
return true;
}
Arena arena = am.getArenaWithPlayer(player);
if (arena == null) {
am.getGlobalMessenger().tell(sender, "That player is not in an arena.");
return true;
}
if (!arena.isRunning()) {
am.getGlobalMessenger().tell(sender, "That arena is not running.");
return true;
}
if (!arena.getPlayersInArena().contains(player)) {
am.getGlobalMessenger().tell(sender, "That player is not an arena player.");
return true;
}
String[] rest = Arrays.copyOfRange(args, 1, args.length);
String input = String.join(" ", rest);
Thing thing;
try {
ThingPicker picker = am.getPlugin().getThingPickerManager().parse(input);
thing = picker.pick();
} catch (Exception e) {
am.getGlobalMessenger().tell(sender, e.getMessage());
return true;
}
arena.getRewardManager().addReward(player, thing);
arena.getMessenger().tell(player, Msg.WAVE_REWARD, thing.toString());
String msg = "Added " + ChatColor.YELLOW + thing + ChatColor.RESET + " to " + ChatColor.YELLOW + player.getName() + "'s" + ChatColor.RESET + " rewards.";
am.getGlobalMessenger().tell(sender, msg);
return true;
}
@Override
public List<String> tab(ArenaMaster am, Player player, String... args) {
if (args.length > 1) {
return Collections.emptyList();
}
String prefix = args[0].toLowerCase();
List<Player> players = am.getAllPlayers();
return players.stream()
.filter(p -> p.getName().toLowerCase().startsWith(prefix))
.map(Player::getName)
.collect(Collectors.toList());
}
}
+4
View File
@@ -46,6 +46,7 @@ permissions:
mobarena.admin.restore: true
mobarena.admin.force: true
mobarena.admin.teleport: true
mobarena.admin.addreward: true
mobarena.admin.enable:
description: Enable and disable MobArena and/or arenas.
default: false
@@ -61,6 +62,9 @@ permissions:
mobarena.admin.teleport:
description: Immune to teleport blocking rules.
default: false
mobarena.admin.addreward:
description: Add rewards to an arena player's reward list.
default: false
mobarena.setup:
description: Gives access to all setup commands