Introduced Brigadier Command System. More Formatting Coming in next commit.

This commit is contained in:
Driftay
2019-09-14 15:13:01 -04:00
parent b06e6e0f04
commit 3c9b606bb9
207 changed files with 4465 additions and 4017 deletions

View File

@@ -1,9 +1,12 @@
package com.massivecraft.factions.cmd.check;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.OfflinePlayer;
@@ -20,34 +23,28 @@ public class CmdCheck extends FCommand {
this.aliases.add("check");
this.requiredArgs.add("walls/buffers/settings/leaderboard");
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.CHECK)
.playerOnly()
.withAction(PermissableAction.CHECK)
.memberOnly()
.build();
}
public void perform() {
if (myFaction == null || !myFaction.isNormal()) {
return;
}
String subCommand = argAsString(0, null);
Access access = myFaction.getAccess(fme, PermissableAction.CHECK);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_NOPERMISSION, "check");
public void perform(CommandContext context) {
if (context.faction == null || !context.faction.isNormal()) {
return;
}
String subCommand = context.argAsString(0, null);
long currentTime = System.currentTimeMillis();
if (subCommand.equalsIgnoreCase("leaderboard")) {
msg(TL.CHECK_LEADERBOARD_HEADER);
context.msg(TL.CHECK_LEADERBOARD_HEADER);
Map<UUID, Integer> players = new HashMap<>();
for (Map.Entry<UUID, Integer> entry : myFaction.getPlayerWallCheckCount().entrySet()) {
for (Map.Entry<UUID, Integer> entry : context.faction.getPlayerWallCheckCount().entrySet()) {
players.put(entry.getKey(), entry.getValue());
}
for (Map.Entry<UUID, Integer> entry : myFaction.getPlayerBufferCheckCount().entrySet()) {
for (Map.Entry<UUID, Integer> entry : context.faction.getPlayerBufferCheckCount().entrySet()) {
if (players.containsKey(entry.getKey())) {
players.replace(entry.getKey(), players.get(entry.getKey()) + entry.getValue());
} else {
@@ -57,54 +54,54 @@ public class CmdCheck extends FCommand {
List<Map.Entry<UUID, Integer>> entryList = players.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());
for (int max = (entryList.size() > 10) ? 10 : entryList.size(), current = 0; current < max; ++current) {
Map.Entry<UUID, Integer> entry = entryList.get(current);
OfflinePlayer offlinePlayer = p.getServer().getOfflinePlayer(entry.getKey());
msg(TL.CHECK_LEADERBOARD_LINE.format(current + 1, offlinePlayer.getName(), entry.getValue(), myFaction.getPlayerBufferCheckCount().getOrDefault(entry.getKey(), 0), myFaction.getPlayerWallCheckCount().getOrDefault(entry.getKey(), 0)));
OfflinePlayer offlinePlayer = FactionsPlugin.getInstance().getServer().getOfflinePlayer(entry.getKey());
context.msg(TL.CHECK_LEADERBOARD_LINE.format(current + 1, offlinePlayer.getName(), entry.getValue(), context.faction.getPlayerBufferCheckCount().getOrDefault(entry.getKey(), 0), context.faction.getPlayerWallCheckCount().getOrDefault(entry.getKey(), 0)));
}
if (entryList.isEmpty()) {
msg(TL.CHECK_LEADERBOARD_NO_DATA);
context.msg(TL.CHECK_LEADERBOARD_NO_DATA);
}
} else if (subCommand.equalsIgnoreCase("walls")) {
if (!CheckTask.wallCheck(myFaction.getId())) {
if (myFaction.getChecks().isEmpty()) {
msg(TL.CHECK_NO_CHECKS);
if (!CheckTask.wallCheck(context.faction.getId())) {
if (context.faction.getChecks().isEmpty()) {
context.msg(TL.CHECK_NO_CHECKS);
return;
}
msg(TL.CHECK_ALREADY_CHECKED);
context.msg(TL.CHECK_ALREADY_CHECKED);
} else {
int current = myFaction.getPlayerWallCheckCount().getOrDefault(me.getUniqueId(), 0);
int current = context.faction.getPlayerWallCheckCount().getOrDefault(context.player.getUniqueId(), 0);
if (current == 0) {
myFaction.getPlayerWallCheckCount().put(me.getUniqueId(), 1);
context.faction.getPlayerWallCheckCount().put(context.player.getUniqueId(), 1);
} else {
myFaction.getPlayerWallCheckCount().replace(me.getUniqueId(), current + 1);
context.faction.getPlayerWallCheckCount().replace(context.player.getUniqueId(), current + 1);
}
myFaction.getChecks().put(currentTime, "U" + fme.getNameAndTag());
msg(TL.CHECK_WALLS_MARKED_CHECKED);
context.faction.getChecks().put(currentTime, "U" + context.fPlayer.getNameAndTag());
context.msg(TL.CHECK_WALLS_MARKED_CHECKED);
}
} else if (subCommand.equalsIgnoreCase("buffers")) {
if (!CheckTask.bufferCheck(myFaction.getId())) {
if (myFaction.getChecks().isEmpty()) {
msg(TL.CHECK_NO_CHECKS);
if (!CheckTask.bufferCheck(context.faction.getId())) {
if (context.faction.getChecks().isEmpty()) {
context.msg(TL.CHECK_NO_CHECKS);
return;
}
msg(TL.CHECK_ALREADY_CHECKED);
context.msg(TL.CHECK_ALREADY_CHECKED);
} else {
int current = myFaction.getPlayerBufferCheckCount().getOrDefault(me.getUniqueId(), 0);
int current = context.faction.getPlayerBufferCheckCount().getOrDefault(context.player.getUniqueId(), 0);
if (current == 0) {
myFaction.getPlayerBufferCheckCount().put(me.getUniqueId(), 1);
context.faction.getPlayerBufferCheckCount().put(context.player.getUniqueId(), 1);
} else {
myFaction.getPlayerBufferCheckCount().replace(me.getUniqueId(), current + 1);
context.faction.getPlayerBufferCheckCount().replace(context.player.getUniqueId(), current + 1);
}
myFaction.getChecks().put(System.currentTimeMillis(), "Y" + fme.getNameAndTag());
msg(TL.CHECK_BUFFERS_MARKED_CHECKED);
context.faction.getChecks().put(System.currentTimeMillis(), "Y" + context.fPlayer.getNameAndTag());
context.msg(TL.CHECK_BUFFERS_MARKED_CHECKED);
}
} else if (subCommand.equalsIgnoreCase("settings")) {
if (!fme.getRole().isAtLeast(Role.COLEADER)) {
msg(TL.CHECK_MUST_BE_ATLEAST_COLEADER);
if (!context.fPlayer.getRole().isAtLeast(Role.COLEADER)) {
context.msg(TL.CHECK_MUST_BE_ATLEAST_COLEADER);
return;
}
CheckSettingsFrame checkGUI = new CheckSettingsFrame(p, fme);
CheckSettingsFrame checkGUI = new CheckSettingsFrame(FactionsPlugin.getInstance(), context.fPlayer);
checkGUI.build();
fme.getPlayer().openInventory(checkGUI.getInventory());
context.fPlayer.getPlayer().openInventory(checkGUI.getInventory());
}
}