forked from ChomeNS/chomens-bot-java
use enums for TrustLevel instead of an int
This commit is contained in:
parent
0c81b515e5
commit
50ca355c32
40 changed files with 141 additions and 99 deletions
|
@ -9,7 +9,7 @@ public interface Command {
|
|||
String description();
|
||||
List<String> usage();
|
||||
List<String> alias();
|
||||
int trustLevel();
|
||||
TrustLevel trustLevel();
|
||||
|
||||
Component execute(CommandContext context, String[] args, String[] fullArgs) throws Exception;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.command;
|
||||
|
||||
public enum TrustLevel {
|
||||
PUBLIC,
|
||||
TRUSTED,
|
||||
ADMIN
|
||||
}
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
|
@ -33,8 +34,8 @@ public class BotUserCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -35,8 +36,8 @@ public class BotVisibilityCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.TRUSTED;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -29,8 +30,8 @@ public class BruhifyCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
|
@ -32,8 +33,8 @@ public class ClearChatCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -29,8 +30,8 @@ public class ClearChatQueueCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.CommandLoop;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -37,8 +38,8 @@ public class CloopCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.TRUSTED;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
@ -37,8 +38,8 @@ public class CommandBlockCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) throws ExecutionException, InterruptedException {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import com.github.ricksbrown.cowsay.plugin.CowExecutor;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -30,8 +31,8 @@ public class CowsayCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -31,8 +32,8 @@ public class CreatorCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
|
@ -32,8 +33,8 @@ public class DiscordCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -29,9 +30,7 @@ public class EchoCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
}
|
||||
public TrustLevel trustLevel() { return TrustLevel.PUBLIC; }
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
final Bot bot = context.bot();
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -29,8 +30,8 @@ public class EndCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.TRUSTED;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.FilteredPlayer;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -40,8 +41,8 @@ public class FilterCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.TRUSTED;
|
||||
}
|
||||
|
||||
// most of these codes are from cloop and greplog
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.MazeGenerator;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -32,8 +33,8 @@ public class GenerateMazeCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
|
@ -36,8 +37,8 @@ public class GrepLogCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] _args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
|
@ -36,8 +37,8 @@ public class HelpCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
private Bot bot;
|
||||
|
@ -56,9 +57,9 @@ public class HelpCommand implements Command {
|
|||
|
||||
public Component sendCommandList () {
|
||||
final List<Component> list = new ArrayList<>();
|
||||
list.addAll(getCommandListByTrustLevel(0));
|
||||
list.addAll(getCommandListByTrustLevel(1));
|
||||
list.addAll(getCommandListByTrustLevel(2));
|
||||
list.addAll(getCommandListByTrustLevel(TrustLevel.PUBLIC));
|
||||
list.addAll(getCommandListByTrustLevel(TrustLevel.TRUSTED));
|
||||
list.addAll(getCommandListByTrustLevel(TrustLevel.ADMIN));
|
||||
|
||||
return Component.empty()
|
||||
.append(Component.text("Commands ").color(NamedTextColor.GRAY))
|
||||
|
@ -74,7 +75,7 @@ public class HelpCommand implements Command {
|
|||
.append(Component.join(JoinConfiguration.separator(Component.space()), list));
|
||||
}
|
||||
|
||||
public List<Component> getCommandListByTrustLevel(int trustLevel) {
|
||||
public List<Component> getCommandListByTrustLevel(TrustLevel trustLevel) {
|
||||
final List<Component> list = new ArrayList<>();
|
||||
|
||||
List<String> commandNames = new ArrayList<>();
|
||||
|
@ -103,12 +104,11 @@ public class HelpCommand implements Command {
|
|||
return list;
|
||||
}
|
||||
|
||||
public NamedTextColor getColorByTrustLevel (int trustLevel) {
|
||||
public NamedTextColor getColorByTrustLevel (TrustLevel trustLevel) {
|
||||
return switch (trustLevel) {
|
||||
case 0 -> NamedTextColor.GREEN;
|
||||
case 1 -> NamedTextColor.RED;
|
||||
case 2 -> NamedTextColor.DARK_RED;
|
||||
default -> NamedTextColor.WHITE; // hm?
|
||||
case PUBLIC -> NamedTextColor.GREEN;
|
||||
case TRUSTED -> NamedTextColor.RED;
|
||||
case ADMIN -> NamedTextColor.DARK_RED;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ public class HelpCommand implements Command {
|
|||
usages.add(
|
||||
Component.empty()
|
||||
.append(Component.text("Trust level: ").color(NamedTextColor.GREEN))
|
||||
.append(Component.text(command.trustLevel()).color(NamedTextColor.YELLOW))
|
||||
.append(Component.text(command.trustLevel().name()).color(NamedTextColor.YELLOW))
|
||||
);
|
||||
|
||||
for (String usage : command.usage()) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
|
@ -33,8 +34,8 @@ public class KickCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.TRUSTED;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
|
@ -35,8 +36,8 @@ public class ListCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.Mail;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.plugins.MailPlugin;
|
||||
|
@ -49,8 +50,8 @@ public class MailCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.plugins.MusicPlayerPlugin;
|
||||
import land.chipmunk.chayapak.chomens_bot.song.Loop;
|
||||
import land.chipmunk.chayapak.chomens_bot.song.Song;
|
||||
|
@ -56,8 +57,8 @@ public class MusicCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
|
@ -33,8 +34,8 @@ public class NetMessageCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
|
@ -33,8 +34,8 @@ public class RandomTeleportCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -29,8 +30,8 @@ public class RefillCoreCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
@ -32,8 +33,8 @@ public class ServerEvalCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 2;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.ADMIN;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -43,8 +44,8 @@ public class ServerInfoCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) throws UnknownHostException {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
|
@ -31,8 +32,8 @@ public class SudoAllCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.TRUSTED;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -31,8 +32,8 @@ public class TPSBarCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
|
@ -29,8 +30,8 @@ public class TestCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -28,8 +29,8 @@ public class ThrowCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) throws Exception {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -36,8 +37,8 @@ public class TimeCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.google.gson.JsonObject;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.HttpUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -39,8 +40,8 @@ public class TranslateCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
|
@ -34,8 +35,8 @@ public class UUIDCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -33,8 +34,8 @@ public class UptimeCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.google.gson.JsonObject;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.HttpUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
|
@ -41,8 +42,8 @@ public class UrbanCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute (CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
|
@ -29,8 +30,8 @@ public class ValidateCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.TRUSTED;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.HttpUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -41,8 +42,8 @@ public class WeatherCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute (CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.HttpUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -37,8 +38,8 @@ public class WikipediaCommand implements Command {
|
|||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
public TrustLevel trustLevel() {
|
||||
return TrustLevel.PUBLIC;
|
||||
}
|
||||
|
||||
public Component execute (CommandContext context, String[] args, String[] fullArgs) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.commands.*;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ExceptionUtilities;
|
||||
import lombok.Getter;
|
||||
|
@ -93,7 +94,7 @@ public class CommandHandlerPlugin {
|
|||
if (command == null && !inGame) return Component.text("Unknown command: " + commandName).color(NamedTextColor.RED);
|
||||
else if (command == null) return null;
|
||||
|
||||
final int trustLevel = command.trustLevel();
|
||||
final TrustLevel trustLevel = command.trustLevel();
|
||||
|
||||
final String[] fullArgs = Arrays.copyOfRange(splitInput, 1, splitInput.length);
|
||||
|
||||
|
@ -108,14 +109,14 @@ public class CommandHandlerPlugin {
|
|||
if (fullArgs.length < minimumArgs) return Component.text("Excepted minimum of " + minimumArgs + " argument(s), got " + fullArgs.length).color(NamedTextColor.RED);
|
||||
if (fullArgs.length > maximumArgs && !longestUsage.contains("{")) return Component.text("Too much arguments, expected " + maximumArgs + " max").color(NamedTextColor.RED);
|
||||
|
||||
if (trustLevel > 0 && splitInput.length < 2 && inGame) return Component.text("Please provide a hash").color(NamedTextColor.RED);
|
||||
if (trustLevel != TrustLevel.PUBLIC && splitInput.length < 2 && inGame) return Component.text("Please provide a hash").color(NamedTextColor.RED);
|
||||
|
||||
String userHash = "";
|
||||
if (trustLevel > 0 && inGame) userHash = splitInput[1];
|
||||
if (trustLevel != TrustLevel.PUBLIC && inGame) userHash = splitInput[1];
|
||||
|
||||
final String[] args = Arrays.copyOfRange(splitInput, (trustLevel > 0 && inGame) ? 2 : 1, splitInput.length);
|
||||
final String[] args = Arrays.copyOfRange(splitInput, (trustLevel != TrustLevel.PUBLIC && inGame) ? 2 : 1, splitInput.length);
|
||||
|
||||
if (command.trustLevel() > 0 && !console) {
|
||||
if (command.trustLevel() != TrustLevel.PUBLIC && !console) {
|
||||
if (discord) {
|
||||
final List<Role> roles = event.getMember().getRoles();
|
||||
|
||||
|
@ -123,24 +124,24 @@ public class CommandHandlerPlugin {
|
|||
final String adminRoleName = bot.config().discord().adminRoleName();
|
||||
|
||||
if (
|
||||
command.trustLevel() == 1 &&
|
||||
command.trustLevel() == TrustLevel.TRUSTED &&
|
||||
roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(trustedRoleName)) &&
|
||||
roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(adminRoleName))
|
||||
) return Component.text("You're not in the trusted role!").color(NamedTextColor.RED);
|
||||
|
||||
if (
|
||||
command.trustLevel() == 2 &&
|
||||
command.trustLevel() == TrustLevel.ADMIN &&
|
||||
roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(adminRoleName))
|
||||
) return Component.text("You're not in the admin role!").color(NamedTextColor.RED);
|
||||
} else {
|
||||
if (
|
||||
command.trustLevel() == 1 &&
|
||||
command.trustLevel() == TrustLevel.TRUSTED &&
|
||||
!userHash.equals(bot.hashing().hash()) &&
|
||||
!userHash.equals(bot.hashing().ownerHash())
|
||||
) return Component.text("Invalid hash").color(NamedTextColor.RED);
|
||||
|
||||
if (
|
||||
command.trustLevel() == 2 &&
|
||||
command.trustLevel() == TrustLevel.ADMIN &&
|
||||
!userHash.equals(bot.hashing().ownerHash())
|
||||
) return Component.text("Invalid OwnerHash").color(NamedTextColor.RED);
|
||||
}
|
||||
|
@ -210,7 +211,7 @@ public class CommandHandlerPlugin {
|
|||
return shortestIndex;
|
||||
}
|
||||
|
||||
private int getMinimumArgs(String usage, boolean inGame, int trustLevel) {
|
||||
private int getMinimumArgs(String usage, boolean inGame, TrustLevel trustLevel) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < usage.length(); i++) {
|
||||
if (usage.charAt(i) == '<') {
|
||||
|
@ -218,18 +219,18 @@ public class CommandHandlerPlugin {
|
|||
}
|
||||
}
|
||||
if (usage.contains("<hash>")) count--; // bad fix?
|
||||
if ((!inGame && trustLevel > 0)) count--;
|
||||
if ((!inGame && trustLevel != TrustLevel.PUBLIC)) count--;
|
||||
return count;
|
||||
}
|
||||
|
||||
private int getMaximumArgs(String usage, boolean inGame, int trustLevel) {
|
||||
private int getMaximumArgs(String usage, boolean inGame, TrustLevel trustLevel) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < usage.length(); i++) {
|
||||
if (usage.charAt(i) == '<' || usage.charAt(i) == '[') {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (!inGame && trustLevel > 0) count++;
|
||||
if (!inGame && trustLevel != TrustLevel.PUBLIC) count++;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue