mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
Add command to clear or change scoreboards.
This commit is contained in:
parent
6cbf960dea
commit
88f43d9a91
@ -0,0 +1,141 @@
|
|||||||
|
package com.gmail.nossr50.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.config.Config;
|
||||||
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
|
import com.gmail.nossr50.util.StringUtils;
|
||||||
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||||
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
|
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
public class McscoreboardCommand implements TabExecutor {
|
||||||
|
private static final List<String> SCOREBOARD_TYPES = ImmutableList.of("clear", "rank", "stats", "top");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (CommandUtils.noConsoleUsage(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
switch (args.length) {
|
||||||
|
case 0:
|
||||||
|
clearScoreboard(player);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
if (args[0].equalsIgnoreCase("clear")) {
|
||||||
|
clearScoreboard(player);
|
||||||
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("rank")) {
|
||||||
|
if (!Config.getInstance().getMcrankScoreboardEnabled()) {
|
||||||
|
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreboardManager.setupPlayerScoreboard(player.getName());
|
||||||
|
ScoreboardManager.enablePlayerRankScoreboard(player);
|
||||||
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("stats")) {
|
||||||
|
if (!Config.getInstance().getMcstatsScoreboardsEnabled()) {
|
||||||
|
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreboardManager.setupPlayerScoreboard(player.getName());
|
||||||
|
ScoreboardManager.enablePlayerStatsScoreboard(UserManager.getPlayer(player));
|
||||||
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("top")) {
|
||||||
|
if (!Config.getInstance().getMctopScoreboardEnabled()) {
|
||||||
|
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreboardManager.enableGlobalStatsScoreboard(player, "all", 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
if (!args[0].equalsIgnoreCase("top")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Config.getInstance().getMctopScoreboardEnabled()) {
|
||||||
|
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isInt(args[1])) {
|
||||||
|
ScoreboardManager.enableGlobalStatsScoreboard(player, "all", Math.abs(Integer.parseInt(args[1])));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CommandUtils.isInvalidSkill(sender, args[1])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreboardManager.enableGlobalStatsScoreboard(player, args[1], 1);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
if (!args[0].equalsIgnoreCase("top")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Config.getInstance().getMctopScoreboardEnabled()) {
|
||||||
|
sender.sendMessage("This scoreboard is not enabled."); //TODO: Localize
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CommandUtils.isInvalidSkill(sender, args[1])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CommandUtils.isInvalidInteger(sender, args[2])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreboardManager.enableGlobalStatsScoreboard(player, args[1], Math.abs(Integer.parseInt(args[2])));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
switch (args.length) {
|
||||||
|
case 1:
|
||||||
|
return StringUtil.copyPartialMatches(args[0], SCOREBOARD_TYPES, new ArrayList<String>(SCOREBOARD_TYPES.size()));
|
||||||
|
case 2:
|
||||||
|
if (args[0].equalsIgnoreCase("top")) {
|
||||||
|
return StringUtil.copyPartialMatches(args[1], SkillType.SKILL_NAMES, new ArrayList<String>(SkillType.SKILL_NAMES.size()));
|
||||||
|
}
|
||||||
|
// Fallthrough
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearScoreboard(Player player) {
|
||||||
|
player.setScoreboard(mcMMO.p.getServer().getScoreboardManager().getMainScoreboard());
|
||||||
|
player.sendMessage("Your scoreboard has been cleared!"); //TODO: Locale
|
||||||
|
}
|
||||||
|
}
|
@ -348,6 +348,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
CommandRegistrationManager.registerMctopCommand();
|
CommandRegistrationManager.registerMctopCommand();
|
||||||
CommandRegistrationManager.registerMcrankCommand();
|
CommandRegistrationManager.registerMcrankCommand();
|
||||||
CommandRegistrationManager.registerMcstatsCommand();
|
CommandRegistrationManager.registerMcstatsCommand();
|
||||||
|
CommandRegistrationManager.registerMcscoreboardCommand();
|
||||||
|
|
||||||
// Party commands
|
// Party commands
|
||||||
CommandRegistrationManager.registerAdminChatCommand();
|
CommandRegistrationManager.registerAdminChatCommand();
|
||||||
|
@ -11,6 +11,7 @@ import com.gmail.nossr50.commands.McgodCommand;
|
|||||||
import com.gmail.nossr50.commands.McmmoCommand;
|
import com.gmail.nossr50.commands.McmmoCommand;
|
||||||
import com.gmail.nossr50.commands.McnotifyCommand;
|
import com.gmail.nossr50.commands.McnotifyCommand;
|
||||||
import com.gmail.nossr50.commands.McrefreshCommand;
|
import com.gmail.nossr50.commands.McrefreshCommand;
|
||||||
|
import com.gmail.nossr50.commands.McscoreboardCommand;
|
||||||
import com.gmail.nossr50.commands.MobhealthCommand;
|
import com.gmail.nossr50.commands.MobhealthCommand;
|
||||||
import com.gmail.nossr50.commands.XprateCommand;
|
import com.gmail.nossr50.commands.XprateCommand;
|
||||||
import com.gmail.nossr50.commands.chat.AdminChatCommand;
|
import com.gmail.nossr50.commands.chat.AdminChatCommand;
|
||||||
@ -376,4 +377,14 @@ public final class CommandRegistrationManager {
|
|||||||
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mobhealth", "<DISABLED | HEARTS | BAR>"));
|
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mobhealth", "<DISABLED | HEARTS | BAR>"));
|
||||||
command.setExecutor(new MobhealthCommand());
|
command.setExecutor(new MobhealthCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerMcscoreboardCommand() {
|
||||||
|
PluginCommand command = mcMMO.p.getCommand("mcscoreboard");
|
||||||
|
command.setDescription("Change the current mcMMO scoreboard being displayed"); //TODO: Localize
|
||||||
|
command.setPermission("mcmmo.commands.mcscoreboard");
|
||||||
|
command.setPermissionMessage(permissionsMessage);
|
||||||
|
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcscoreboard", "<CLEAR | RANK | STATS | TOP>"));
|
||||||
|
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.3", "mcscoreboard", "top", "[" + LocaleLoader.getString("Commands.Usage.Skill") + "]", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]"));
|
||||||
|
command.setExecutor(new McscoreboardCommand());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,8 @@ commands:
|
|||||||
mobhealth:
|
mobhealth:
|
||||||
aliases: [mcmobhealth]
|
aliases: [mcmobhealth]
|
||||||
description: Change the style of the mob healthbar
|
description: Change the style of the mob healthbar
|
||||||
|
mcscoreboard:
|
||||||
|
description: Change the current mcMMO scoreboard being displayed
|
||||||
permissions:
|
permissions:
|
||||||
mcmmo.*:
|
mcmmo.*:
|
||||||
default: false
|
default: false
|
||||||
@ -665,6 +667,7 @@ permissions:
|
|||||||
mcmmo.commands.mcmmo.all: true
|
mcmmo.commands.mcmmo.all: true
|
||||||
mcmmo.commands.mcnotify: true
|
mcmmo.commands.mcnotify: true
|
||||||
mcmmo.commands.mcrank: true
|
mcmmo.commands.mcrank: true
|
||||||
|
mcmmo.commands.mcscoreboard: true
|
||||||
mcmmo.commands.mcstats: true
|
mcmmo.commands.mcstats: true
|
||||||
mcmmo.commands.mctop.all: true
|
mcmmo.commands.mctop.all: true
|
||||||
mcmmo.commands.mining: true
|
mcmmo.commands.mining: true
|
||||||
@ -821,6 +824,8 @@ permissions:
|
|||||||
mcmmo.commands.mcremove:
|
mcmmo.commands.mcremove:
|
||||||
default: false
|
default: false
|
||||||
description: Allows access to the mcremove command
|
description: Allows access to the mcremove command
|
||||||
|
mcmmo.commands.mcscoreboard:
|
||||||
|
description: Allows access to the mcscoreboard command
|
||||||
mcmmo.commands.mcstats:
|
mcmmo.commands.mcstats:
|
||||||
description: Allows access to the mcstats command
|
description: Allows access to the mcstats command
|
||||||
mcmmo.commands.mctop.*:
|
mcmmo.commands.mctop.*:
|
||||||
|
Loading…
Reference in New Issue
Block a user