mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-02 13:44:43 +02:00
New and Improved Scoreboard System
- Scoreboards now AUTO-UPDATE - Scoreboards now COME IN COLOR - If you want, they can come in EVERY COLOR (Config setting) - Scoreboards can be displayed alongside chat output! - Prevention of denial of service to SQL via spamming /mctop using a cooldown - Added /mccooldown command to show cooldowns for all available skills
This commit is contained in:
@ -11,36 +11,39 @@ import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
|
||||
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class MctopCommand implements TabExecutor {
|
||||
private SkillType skill;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
SkillType skill;
|
||||
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
display(1, "ALL", sender, command);
|
||||
display(1, null, sender, command);
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
if (StringUtils.isInt(args[0])) {
|
||||
display(Math.abs(Integer.parseInt(args[0])), "ALL", sender, command);
|
||||
display(Math.abs(Integer.parseInt(args[0])), null, sender, command);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!extractSkill(sender, args[0])) {
|
||||
if ((skill = extractSkill(sender, args[0])) == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
display(1, skill.toString(), sender, command);
|
||||
display(1, skill, sender, command);
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
@ -48,11 +51,11 @@ public class MctopCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!extractSkill(sender, args[0])) {
|
||||
if ((skill = extractSkill(sender, args[0])) == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
display(Math.abs(Integer.parseInt(args[1])), skill.toString(), sender, command);
|
||||
display(Math.abs(Integer.parseInt(args[1])), skill, sender, command);
|
||||
return true;
|
||||
|
||||
default:
|
||||
@ -70,35 +73,41 @@ public class MctopCommand implements TabExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private void display(int page, String skill, CommandSender sender, Command command) {
|
||||
if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, this.skill)) {
|
||||
private void display(int page, SkillType skill, CommandSender sender, Command command) {
|
||||
if (skill != null && !Permissions.mctop(sender, skill)) {
|
||||
sender.sendMessage(command.getPermissionMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender instanceof Player && Config.getInstance().getMctopScoreboardEnabled()) {
|
||||
ScoreboardManager.enableGlobalStatsScoreboard((Player) sender, skill, page);
|
||||
}
|
||||
else {
|
||||
display(page, skill, sender);
|
||||
if (sender instanceof Player) {
|
||||
McMMOPlayer mcpl = UserManager.getPlayer(sender.getName());
|
||||
if (mcpl.getDatabaseATS() + Misc.PLAYER_DATABASE_COOLDOWN_MILLIS > System.currentTimeMillis()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Database.Cooldown"));
|
||||
return;
|
||||
}
|
||||
mcpl.actualizeDatabaseATS();
|
||||
}
|
||||
|
||||
display(page, skill, sender);
|
||||
}
|
||||
|
||||
private void display(int page, String query, CommandSender sender) {
|
||||
new MctopCommandAsyncTask(page, query, sender).runTaskAsynchronously(mcMMO.p);
|
||||
private void display(int page, SkillType skill, CommandSender sender) {
|
||||
boolean useBoard = (sender instanceof Player) && (Config.getInstance().getTopUseBoard());
|
||||
boolean useChat = useBoard ? Config.getInstance().getTopUseChat() : true;
|
||||
|
||||
new MctopCommandAsyncTask(page, skill, sender, useBoard, useChat).runTaskAsynchronously(mcMMO.p);
|
||||
}
|
||||
|
||||
private boolean extractSkill(CommandSender sender, String skillName) {
|
||||
private SkillType extractSkill(CommandSender sender, String skillName) {
|
||||
if (CommandUtils.isInvalidSkill(sender, skillName)) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
SkillType skill = SkillType.getSkill(skillName);
|
||||
|
||||
if (skill != null && CommandUtils.isChildSkill(sender, skill)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
skill = SkillType.getSkill(skillName);
|
||||
|
||||
if (CommandUtils.isChildSkill(sender, skill)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return skill;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user