Merge pull request #41 from Hexaoxide/refactor/commands

Refactor commands, ditches ACF for CommandAPI
This commit is contained in:
Josh (Vicarious) authored and GitHub committed 2020-09-03 00:06:13 -07:00
commit 409842a109
29 files changed
+1843 -474

No files matched your search

+22 -4
View File
@@ -9,6 +9,7 @@ apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'maven'
// Gets the git commit hash of the latest commit, used for version string
ext.projectVersion = '1.0'
def gitHash = versionDetails().gitHash
@@ -20,9 +21,9 @@ repositories {
mavenLocal()
mavenCentral()
maven {url = "https://maven.enginehub.org/repo/"}
maven {url = 'https://maven.enginehub.org/repo/'}
maven {url = 'https://repo.maven.apache.org/maven2'}
maven {url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'}
maven {url = 'https://papermc.io/repo/repository/maven-public/'}
maven {url = 'https://oss.sonatype.org/content/groups/public/'}
maven {url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'}
maven {url = 'https://jitpack.io'}
@@ -30,34 +31,46 @@ repositories {
maven {url = 'https://repo.codemc.org/repository/maven-public/'}
maven {url = 'https://repo.minebench.de/'}
maven {url = "https://repo.aikar.co/content/groups/aikar/"}
maven {url = 'https://raw.githubusercontent.com/JorelAli/CommandAPI/mvn-repo/'}
}
dependencies {
compile 'co.aikar:acf-bukkit:0.5.0-SNAPSHOT'
// Components
compile 'net.kyori:adventure-api:4.0.0-SNAPSHOT'
compile 'net.kyori:adventure-nbt:4.0.0-SNAPSHOT'
compile 'net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT'
compile 'net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT'
compile 'de.themoep:minedown-adventure:1.6.1-SNAPSHOT'
// Databases
compile 'co.aikar:idb-bukkit:1.0.0-SNAPSHOT'
compile 'com.zaxxer:HikariCP:2.4.1'
// Messaging
compile 'io.github.leonardosnt:bungeechannelapi:1.0.0-SNAPSHOT'
compile 'io.lettuce:lettuce-core:6.0.0.M1'
// Commands
compile "dev.jorel:commandapi-shade:4.1"
// Plugins
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.143'
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
compileOnly 'me.clip:placeholderapi:2.10.9'
compileOnly 'com.github.TownyAdvanced:Towny:0.96.1.11'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
compileOnly 'com.vexsoftware:nuvotifier-universal:2.6.0'
compileOnly 'net.luckperms:api:5.1'
// Util
compileOnly 'org.jetbrains:annotations:16.0.1'
// Server
compileOnly 'com.destroystokyo.paper:paper-api:1.16.2-R0.1-SNAPSHOT'
}
// Generates plugin.yml automatically
bukkit {
name = project.description
version = project.version
@@ -80,6 +93,7 @@ bukkit {
sourceCompatibility = '1.8'
// Set output directory and encoding
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
@@ -88,8 +102,10 @@ tasks.withType(Jar) {
getDestinationDirectory().set(file("$rootDir/build"))
}
// Automatically shadowJar when building
tasks.build.dependsOn tasks.shadowJar
// Output a single jar
shadowJar {
minimize()
archiveFileName.set(project.description + "-" + project.property('projectVersion') + ".jar")
@@ -99,6 +115,7 @@ jar {
archiveFileName.set(project.description + "-" + project.property('projectVersion') + ".jar")
}
// Automatically relocate all shaded dependencies
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
task relocateShadowJar(type: ConfigureShadowRelocation) {
@@ -108,6 +125,7 @@ task relocateShadowJar(type: ConfigureShadowRelocation) {
tasks.shadowJar.dependsOn tasks.relocateShadowJar
// Cleanup custom output directory on clean task
clean.doFirst {
delete "$rootDir/build/bundled"
}
@@ -1,5 +1,6 @@
package net.draycia.carbon;
import dev.jorel.commandapi.CommandAPI;
import net.draycia.carbon.channels.contexts.impl.EconomyContext;
import net.draycia.carbon.channels.contexts.impl.DistanceContext;
import net.draycia.carbon.channels.contexts.impl.TownyContext;
@@ -12,7 +13,7 @@ import net.draycia.carbon.storage.UserService;
import net.draycia.carbon.storage.impl.JSONUserService;
import net.draycia.carbon.storage.impl.MySQLUserService;
import net.draycia.carbon.util.CarbonPlaceholders;
import net.draycia.carbon.util.CarbonUtils;
import net.draycia.carbon.util.Metrics;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
@@ -25,6 +26,8 @@ import java.io.File;
public final class CarbonChat extends JavaPlugin {
private static final int BSTATS_PLUGIN_ID = 8720;
private Permission permission;
private CommandManager commandManager;
@@ -35,10 +38,11 @@ public final class CarbonChat extends JavaPlugin {
private UserService userService;
private MessageManager messageManager;
private CarbonUtils itemStackUtils;
private YamlConfiguration modConfig;
private YamlConfiguration languageConfig;
private YamlConfiguration commandsConfig;
private FilterHandler filterHandler;
public static final LegacyComponentSerializer LEGACY =
LegacyComponentSerializer.builder()
@@ -48,8 +52,16 @@ public final class CarbonChat extends JavaPlugin {
.useUnusualXRepeatedCharacterHexFormat()
.build();
@Override
public void onLoad() {
CommandAPI.onLoad(false);
}
@Override
public void onEnable() {
CommandAPI.onEnable(this);
Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
// Ensure config is present to be modified by the user
if (!(new File(getDataFolder(), "config.yml").exists())) {
saveDefaultConfig();
@@ -63,26 +75,24 @@ public final class CarbonChat extends JavaPlugin {
saveResource("language.yml", false);
}
if (!(new File(getDataFolder(), "commands.yml").exists())) {
saveResource("commands.yml", false);
}
loadModConfig();
loadLanguage();
// Setup Adventure
adventureManager = new AdventureManager(this);
try {
itemStackUtils = new CarbonUtils();
} catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
// Setup vault and permissions
permission = getServer().getServicesManager().getRegistration(Permission.class).getProvider();
// Initialize managers
commandManager = new CommandManager(this);
channelManager = new ChannelManager(this);
contextManager = new ContextManager();
messageManager = new MessageManager(this);
commandManager = new CommandManager(this);
String storageType = getConfig().getString("storage.type");
@@ -142,7 +152,10 @@ public final class CarbonChat extends JavaPlugin {
pluginManager.registerEvents(new WhisperPingHandler(this), this);
pluginManager.registerEvents(new CapsHandler(this), this);
pluginManager.registerEvents(new FilterHandler(this), this);
filterHandler = new FilterHandler(this);
pluginManager.registerEvents(filterHandler, this);
pluginManager.registerEvents(new MuteHandler(), this);
pluginManager.registerEvents(new ShadowMuteHandler(this), this);
}
@@ -153,6 +166,11 @@ public final class CarbonChat extends JavaPlugin {
loadModConfig();
loadLanguage();
loadCommandsConfig();
}
public void reloadFilters() {
filterHandler.reloadFilters();
}
private void loadModConfig() {
@@ -163,6 +181,10 @@ public final class CarbonChat extends JavaPlugin {
languageConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "language.yml"));
}
private void loadCommandsConfig() {
commandsConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "commands.yml"));
}
private void registerContexts() {
getContextManager().register("distance", new DistanceContext());
}
@@ -171,6 +193,10 @@ public final class CarbonChat extends JavaPlugin {
return modConfig;
}
public YamlConfiguration getCommandsConfig() {
return commandsConfig;
}
public YamlConfiguration getLanguage() {
return languageConfig;
}
@@ -195,10 +221,6 @@ public final class CarbonChat extends JavaPlugin {
return userService;
}
public CarbonUtils getItemStackUtils() {
return itemStackUtils;
}
public AdventureManager getAdventureManager() {
return adventureManager;
}
@@ -1,6 +1,6 @@
package net.draycia.carbon.channels;
import co.aikar.commands.BukkitCommandManager;
import dev.jorel.commandapi.CommandAPI;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.commands.AliasedChannelCommand;
import net.draycia.carbon.util.Registry;
@@ -27,12 +27,8 @@ public class ChannelRegistry implements Registry<ChatChannel> {
boolean registerSuccessful = registry.putIfAbsent(key, value) == null;
if (registerSuccessful) {
BukkitCommandManager commandManager = carbonChat.getCommandManager().getCommandManager();
commandManager.getCommandReplacements().addReplacement("channelName", value.getAliases());
AliasedChannelCommand command = new AliasedChannelCommand(carbonChat, value);
AliasedChannelCommand command = new AliasedChannelCommand(value);
commandManager.registerCommand(command);
channelCommands.add(command);
if (value instanceof Listener) {
@@ -61,7 +57,7 @@ public class ChannelRegistry implements Registry<ChatChannel> {
for (AliasedChannelCommand command : channelCommands) {
carbonChat.getLogger().info("Unregistering command for channel: " + command.getChatChannel().getName());
carbonChat.getCommandManager().getCommandManager().unregisterCommand(command);
CommandAPI.unregister(command.getCommandName());
}
}
@@ -1,58 +1,82 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.ConditionFailedException;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@CommandAlias("%channelName")
@CommandPermission("carbonchat.switch")
public class AliasedChannelCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class AliasedChannelCommand {
private final CarbonChat carbonChat;
private final ChatChannel chatChannel;
private final String commandName;
public AliasedChannelCommand(ChatChannel chatChannel) {
public AliasedChannelCommand(CarbonChat carbonChat, ChatChannel chatChannel) {
this.carbonChat = carbonChat;
this.chatChannel = chatChannel;
this.commandName = chatChannel.getKey();
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
new CommandAPICommand(commandName)
.withArguments(setChannelArguments)
.withPermission(CommandPermission.fromString("carbonchat.channel"))
.executesPlayer(this::setChannel)
.register();
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
sendMessageArguments.put("message", new GreedyStringArgument());
new CommandAPICommand(commandName)
.withArguments(sendMessageArguments)
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
.executesPlayer(this::sendMessage)
.register();
}
@Default
@Syntax("[message]")
public void baseCommand(Player player, @Optional String[] args) {
private void setChannel(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
if (!chatChannel.canPlayerUse(user)) {
throw new ConditionFailedException(chatChannel.getCannotUseMessage());
}
if (user.getChannelSettings(chatChannel).isIgnored()) {
throw new ConditionFailedException(chatChannel.getCannotUseMessage());
}
if (args == null || args.length == 0) {
user.setSelectedChannel(getChatChannel());
user.sendMessage(carbonChat.getAdventureManager().processMessage(getChatChannel().getSwitchMessage(),
if (user.getChannelSettings(getChatChannel()).isIgnored()) {
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, getChatChannel().getCannotUseMessage(),
"br", "\n",
"color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
"channel", getChatChannel().getName()));
} else {
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
Component component = getChatChannel().sendMessage(user, String.join(" ", args), false);
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
});
return;
}
user.setSelectedChannel(getChatChannel());
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, getChatChannel().getSwitchMessage(),
"br", "\n",
"color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
"channel", getChatChannel().getName()));
}
private void sendMessage(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
String message = (String) args[0];
Component component = getChatChannel().sendMessage(user, message, false);
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
public ChatChannel getChatChannel() {
return chatChannel;
}
public String getCommandName() {
return commandName;
}
}
@@ -1,66 +1,82 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.ConditionFailedException;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandAlias("ch|channel|switch")
@CommandPermission("carbonchat.switch")
public class ChannelCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class ChannelCommand {
@Default
@CommandCompletion("@chatchannel @nothing")
@Syntax("<channel> [message]")
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel, @Optional String[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
private final CarbonChat carbonChat;
if (user.getChannelSettings(channel).isIgnored()) {
throw new ConditionFailedException(channel.getCannotUseMessage());
public ChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
if (args == null || args.length == 0) {
user.setSelectedChannel(channel);
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
setChannelArguments.put("channel", CarbonUtils.channelArgument());
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
new CommandAPICommand(commandSettings.getName())
.withArguments(setChannelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.channel"))
.executesPlayer(this::setChannel)
.register();
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
sendMessageArguments.put("channel", CarbonUtils.channelArgument());
sendMessageArguments.put("message", new GreedyStringArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(sendMessageArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
.executesPlayer(this::sendMessage)
.register();
}
private void setChannel(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
ChatChannel channel = (ChatChannel) args[0];
if (user.getChannelSettings(channel).isIgnored()) {
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getCannotUseMessage(),
"br", "\n",
"color", "<" + channel.getChannelColor(user).toString() + ">",
"channel", channel.getName()));
} else {
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
Component component = channel.sendMessage(user, String.join(" ", args), false);
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
});
return;
}
}
@CommandPermission("carbonchat.switch.others")
@Subcommand("other")
@CommandCompletion("@chatchannel @players")
@Syntax("<channel> <user>")
public void baseCommand(CommandSender sender, @Conditions("exists:true") ChatChannel channel, ChatUser user) {
user.setSelectedChannel(channel);
String message = channel.getSwitchMessage();
String otherMessage = channel.getSwitchOtherMessage();
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
"br", "\n",
"color", "<" + channel.getChannelColor(user).toString() + ">",
"channel", channel.getName()));
}
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
private void sendMessage(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
ChatChannel channel = (ChatChannel) args[0];
String message = (String) args[1];
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName(),
"player", user.asOfflinePlayer().getName()));
Component component = channel.sendMessage(user, message, false);
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
}
@@ -1,50 +1,78 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.regex.Pattern;
@CommandAlias("chlist|channellist")
@CommandPermission("carbonchat.channellist")
public class ChannelListCommand extends BaseCommand {
public class ChannelListCommand {
@Dependency
private CarbonChat carbonChat;
private final CarbonChat carbonChat;
@Default
@Syntax("[player]")
public void baseCommand(Player player) {
public ChannelListCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
new CommandAPICommand(commandSettings.getName())
.withArguments(channelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.channellist"))
.executesPlayer(this::executeSelf)
.register();
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
argumentsOther.put("player", CarbonUtils.onlineChatUserArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(argumentsOther)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.channellist.other"))
.executes(this::executeOther)
.register();
}
public void executeSelf(Player player, Object[] args) {
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
ChatUser user = carbonChat.getUserService().wrap(player);
getListAndSend(player, user, allChannels);
}
@CommandPermission("carbonchat.channellist.others")
@Subcommand("user")
@CommandCompletion("@players @nothing")
@Syntax("<player>")
public void baseCommand(Player player, ChatUser user) {
ChatUser cmdSender = carbonChat.getUserService().wrap(player);
if (!user.isOnline()) {
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
cmdSender.sendMessage(carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.asOfflinePlayer().getName()));
return;
}
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
getListAndSend(player, user, allChannels);
public void executeOther(CommandSender sender, Object[] args) {
Audience cmdSender = carbonChat.getAdventureManager().getAudiences().audience(sender);
ChatUser user = (ChatUser) args[0];
if (!user.isOnline()) {
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
cmdSender.sendMessage(carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.asOfflinePlayer().getName()));
return;
}
private void getListAndSend(Player player, ChatUser user, Iterator<ChatChannel> allChannels) {
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
getListAndSend(sender, user, allChannels);
}
private void getListAndSend(CommandSender sender, ChatUser user, Iterator<ChatChannel> allChannels) {
ChatChannel channel;
List<ChatChannel> canSee = new ArrayList<>();
List<ChatChannel> cannotSee = new ArrayList<>();
@@ -68,9 +96,11 @@ public class ChannelListCommand extends BaseCommand {
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
carbonChat.getUserService().wrap(player).sendMessage(availableComponent);
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
if (player.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
audience.sendMessage(availableComponent);
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
TextComponent.Builder unavailableList = TextComponent.builder("");
@@ -81,13 +111,14 @@ public class ChannelListCommand extends BaseCommand {
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
carbonChat.getUserService().wrap(player).sendMessage(unavailableComponent);
audience.sendMessage(unavailableComponent);
}
}
private void makeList(Iterator<ChatChannel> iterator, TextComponent.Builder list) {
String listSeparator = carbonChat.getLanguage().getString("channel-list-separator", ", ");
Component listSeparatorComponent = listSeparatorComponent = TextComponent.of(listSeparator);
// TODO: Larry, why did you double assign the listSeparatorComponent?
Component listSeparatorComponent = TextComponent.of(listSeparator);
while (iterator.hasNext()) {
ChatChannel channel = iterator.next();
@@ -1,34 +1,46 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Dependency;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
@CommandAlias("chatreload|creload")
@CommandPermission("carbonchat.reload")
public class ChatReloadCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class ChatReloadCommand {
@Default
public void baseCommand(CommandSender sender) {
private final CarbonChat carbonChat;
public ChatReloadCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
channelArguments.put("channel", CarbonUtils.channelArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(channelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.reload"))
.executes(this::execute)
.register();
}
private void execute(CommandSender sender, Object[] args) {
carbonChat.reloadConfig();
carbonChat.getChannelManager().reload();
carbonChat.reloadFilters();
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("reloaded"),
"br", "\n");
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(message);
// TODO: Ensure the command list is updated when reloading.
// If new channels are added, their commands should appear to players.
}
}
@@ -1,26 +1,35 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Dependency;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandAlias("clearchat|cc")
@CommandPermission("carbonchat.clearchat.clear")
public class ClearChatCommand extends BaseCommand {
public class ClearChatCommand {
@Dependency
private CarbonChat carbonChat;
private final CarbonChat carbonChat;
@Default
public void baseCommand(CommandSender issuer) {
public ClearChatCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
new CommandAPICommand(commandSettings.getName())
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.clearchat.clear"))
.executes(this::execute)
.register();
}
private void execute(CommandSender sender, Object[] args) {
String format = carbonChat.getModConfig().getString("clear-chat.message", "");
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n");
@@ -37,12 +46,12 @@ public class ClearChatCommand extends BaseCommand {
if (player.hasPermission("carbonchat.clearchat.notify")) {
String message = carbonChat.getLanguage().getString("clear-notify");
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", issuer.getName()));
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
}
if (player.hasPermission("carbonchat.clearchat.exempt")) {
String message = carbonChat.getLanguage().getString("clear-exempt");
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", issuer.getName()));
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
}
}
}
@@ -1,30 +1,49 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@CommandAlias("ignore")
@CommandPermission("carbonchat.ignore")
public class IgnoreCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class IgnoreCommand {
@Default
@CommandCompletion("@players @nothing")
@Syntax("<player>")
public void baseCommand(Player player, ChatUser targetUser) {
private final CarbonChat carbonChat;
public IgnoreCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
channelArguments.put("player", CarbonUtils.chatUserArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(channelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.ignore"))
.executesPlayer(this::execute)
.register();
}
private void execute(Player player, Object[] args) {
ChatUser targetUser = (ChatUser) args[0];
ChatUser user = carbonChat.getUserService().wrap(player);
if (user.isIgnoringUser(targetUser)) {
user.setIgnoringUser(targetUser, false);
user.sendMessage(processMessage(player, carbonChat.getLanguage().getString("not-ignoring-user"),
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
carbonChat.getLanguage().getString("not-ignoring-user"),
"br", "\n", "player", targetUser.asOfflinePlayer().getName()));
} else {
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
@@ -38,8 +57,9 @@ public class IgnoreCommand extends BaseCommand {
format = carbonChat.getLanguage().getString("ignoring-user");
}
Component message = processMessage(player, format, "br", "\n",
"sender", player.getDisplayName(), "player", targetUser.asOfflinePlayer().getName());
Component message = carbonChat.getAdventureManager().processMessageWithPapi(player, format,
"br", "\n", "sender", player.getDisplayName(), "player",
targetUser.asOfflinePlayer().getName());
user.sendMessage(message);
});
@@ -47,8 +67,4 @@ public class IgnoreCommand extends BaseCommand {
}
}
private Component processMessage(Player player, String message, String... args) {
return carbonChat.getAdventureManager().processMessageWithPapi(player, message, args);
}
}
@@ -1,29 +1,43 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@CommandAlias("me|rp")
@CommandPermission("carbonchat.me")
public class MeCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class MeCommand {
@Default
@Syntax("<message>")
public void baseCommand(Player player, String... args) {
if (args == null || args.length == 0) {
private final CarbonChat carbonChat;
public MeCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
String message = String.join(" ", args).replace("</pre>", "");
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
channelArguments.put("message", new GreedyStringArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(channelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.me"))
.executesPlayer(this::execute)
.register();
}
private void execute(Player player, Object[] args) {
String message = ((String) args[0]).replace("</pre>", "");
String format = PlaceholderAPI.setPlaceholders(player, carbonChat.getLanguage().getString("me"));
if (!player.hasPermission("carbonchat.me.formatting")) {
@@ -1,28 +1,45 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import org.bukkit.entity.Player;
@CommandAlias("msg|whisper|message|w")
@CommandPermission("carbonchat.message")
public class MessageCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class MessageCommand {
@Default
@CommandCompletion("@players @nothing")
@Syntax("<player> <message>")
public void baseCommand(Player player, ChatUser targetUser, String... args) {
if (args.length == 0) {
private final CarbonChat carbonChat;
public MessageCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
channelArguments.put("player", CarbonUtils.chatUserArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(channelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.message"))
.executesPlayer(this::execute)
.register();
}
private void execute(Player player, Object[] args) {
ChatUser targetUser = (ChatUser) args[0];
String message = (String) args[1];
ChatUser sender = carbonChat.getUserService().wrap(player);
targetUser.sendMessage(sender, String.join(" ", args));
targetUser.sendMessage(sender, message);
}
}
@@ -1,34 +1,52 @@
package net.draycia.carbon.commands;
import co.aikar.commands.annotation.*;
import co.aikar.commands.BaseCommand;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@CommandAlias("mute")
@CommandPermission("carbonchat.mute")
public class MuteCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class MuteCommand {
@Default
@CommandCompletion("@players @nothing")
@Syntax("<player>")
public void baseCommand(CommandSender sender, ChatUser targetUser) {
private final CarbonChat carbonChat;
public MuteCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
arguments.put("player", CarbonUtils.chatUserArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(arguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.mute"))
.executes(this::execute)
.register();
}
private void execute(CommandSender sender, Object[] args) {
ChatUser user = (ChatUser) args[0];
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
if (targetUser.isMuted()) {
targetUser.setMuted(false);
if (user.isShadowMuted()) {
user.setMuted(false);
String format = carbonChat.getLanguage().getString("no-longer-muted");
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
"player", targetUser.asOfflinePlayer().getName());
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
"player", user.asOfflinePlayer().getName());
audience.sendMessage(message);
} else {
@@ -36,19 +54,18 @@ public class MuteCommand extends BaseCommand {
Permission permission = carbonChat.getPermission();
String format;
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.mute.exempt")) {
if (permission.playerHas(null, user.asOfflinePlayer(), "carbonchat.mute.exempt")) {
format = carbonChat.getLanguage().getString("mute-exempt");
} else {
targetUser.setMuted(true);
user.setMuted(true);
format = carbonChat.getLanguage().getString("is-now-muted");
}
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
"player", targetUser.asOfflinePlayer().getName());
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
"player", user.asOfflinePlayer().getName());
audience.sendMessage(message);
});
}
}
}
@@ -1,66 +1,98 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.StringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.audience.Audience;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandAlias("nick|nickname")
@CommandPermission("carbonchat.nickname")
public class NicknameCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class NicknameCommand {
@Default
@Syntax("<nickname> [player]")
public void baseCommand(Player player, String nickname, @Optional ChatUser target) {
private final CarbonChat carbonChat;
public NicknameCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> selfArguments = new LinkedHashMap<>();
selfArguments.put("nickname", new StringArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(selfArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.nickname"))
.executesPlayer(this::executeSelf)
.register();
LinkedHashMap<String, Argument> otherArguments = new LinkedHashMap<>();
otherArguments.put("player", CarbonUtils.chatUserArgument());
otherArguments.put("nickname", new StringArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(otherArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.nickname.others"))
.executes(this::executeOther)
.register();
}
private void executeSelf(Player player, Object[] args) {
String nickname = (String) args[0];
ChatUser sender = carbonChat.getUserService().wrap(player);
// Reset nickname
if (nickname.equalsIgnoreCase("off")) {
if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(player.getName())) {
nickname = null;
}
// Reset other player's nickname
if (target != null && nickname != null && nickname.equals(target.asOfflinePlayer().getName())) {
nickname = null;
}
sender.setNickname(nickname);
// Reset own nickname
if (target == null && nickname != null && nickname.equals(sender.asOfflinePlayer().getName())) {
nickname = null;
}
String message;
if (target != null) {
target.setNickname(nickname);
String message;
if (nickname == null) {
message = carbonChat.getLanguage().getString("other-nickname-reset");
} else {
message = carbonChat.getLanguage().getString("other-nickname-set");
}
sender.sendMessage(carbonChat.getAdventureManager().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", target.asOfflinePlayer().getName()));
if (nickname == null) {
message = carbonChat.getLanguage().getString("nickname-reset");
} else {
sender.setNickname(nickname);
String message;
if (nickname == null) {
message = carbonChat.getLanguage().getString("nickname-reset");
} else {
message = carbonChat.getLanguage().getString("nickname-set");
}
sender.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
message, "nickname", nickname == null ? "" : nickname));
message = carbonChat.getLanguage().getString("nickname-set");
}
sender.sendMessage(carbonChat.getAdventureManager().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", sender.asOfflinePlayer().getName()));
}
private void executeOther(CommandSender sender, Object[] args) {
Audience user = carbonChat.getAdventureManager().getAudiences().audience(sender);
ChatUser target = (ChatUser) args[0];
String nickname = (String) args[1];
if (nickname.equalsIgnoreCase("off") ||
nickname.equalsIgnoreCase(target.asOfflinePlayer().getName())) {
nickname = null;
}
target.setNickname(nickname);
String message;
if (nickname == null) {
message = carbonChat.getLanguage().getString("other-nickname-reset");
} else {
message = carbonChat.getLanguage().getString("other-nickname-set");
}
user.sendMessage(carbonChat.getAdventureManager().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", target.asOfflinePlayer().getName()));
}
}
@@ -1,39 +1,61 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
@CommandAlias("reply|r")
@CommandPermission("carbonchat.reply")
public class ReplyCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class ReplyCommand {
@Default
@Syntax("<message>")
public void baseCommand(Player player, String... args) {
if (args.length == 0) {
private final CarbonChat carbonChat;
public ReplyCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
arguments.put("message", new GreedyStringArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(arguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.reply"))
.executesPlayer(this::execute)
.register();
}
private void execute(Player player, Object[] args) {
String input = (String) args[0];
ChatUser user = carbonChat.getUserService().wrap(player);
if (input == null || input.isEmpty()) {
String message = carbonChat.getLanguage().getString("reply-message-blank");
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
user.sendMessage(component);
return;
}
if (user.getReplyTarget() == null) {
String message = carbonChat.getLanguage().getString("no-reply-target");
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
user.sendMessage(component);
return;
}
ChatUser targetUser = carbonChat.getUserService().wrap(user.getReplyTarget());
targetUser.sendMessage(user, String.join(" ", args));
targetUser.sendMessage(user, input);
}
}
@@ -1,44 +1,62 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.ConditionFailedException;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.*;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.storage.UserChannelSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.entity.Player;
@CommandAlias("setcolor|setcolour")
@CommandPermission("carbonchat.setcolor")
public class SetColorCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class SetColorCommand {
@Default
@CommandCompletion("@chatchannel @nothing")
@Syntax("<channel> <color>")
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel, String input) {
if (channel == null || input == null) {
throw new ConditionFailedException("Channel or Color not supplied!");
private final CarbonChat carbonChat;
public SetColorCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
ChatUser user = carbonChat.getUserService().wrap(player);
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
arguments.put("channel", new LiteralArgument(channel.getKey()));
arguments.put("color", CarbonUtils.textColorArgument());
if (!player.hasPermission("carbonchat.setcolor." + channel.getKey())) {
throw new ConditionFailedException("You can't set colors for this channel!");
new CommandAPICommand(commandSettings.getName())
.withArguments(arguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.setcolor"))
.executesPlayer((player, args) -> {
TextColor color = (TextColor)args[1];
ChatUser user = carbonChat.getUserService().wrap(player);
if (!player.hasPermission("carbonchat.setcolor." + channel.getKey())) {
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
carbonChat.getLanguage().getString("cannot-set-color"),
"br", "\n", "input", color.asHexString(),
"channel", channel.getName()));
return;
}
UserChannelSettings settings = user.getChannelSettings(channel);
settings.setColor(color);
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
carbonChat.getLanguage().getString("channel-color-set"),
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel",
channel.getName(), "hex", color.asHexString()));
})
.register();
}
UserChannelSettings settings = user.getChannelSettings(channel);
TextColor color = CarbonUtils.parseColor(user, input);
settings.setColor(color);
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, carbonChat.getLanguage().getString("channel-color-set"),
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel", channel.getName(), "hex", color.asHexString()));
}
}
@@ -1,34 +1,52 @@
package net.draycia.carbon.commands;
import co.aikar.commands.annotation.*;
import co.aikar.commands.BaseCommand;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@CommandAlias("shadowmute|sm|smute")
@CommandPermission("carbonchat.shadowmute")
public class ShadowMuteCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class ShadowMuteCommand {
@Default
@CommandCompletion("@players @nothing")
@Syntax("<player>")
public void baseCommand(CommandSender sender, ChatUser targetUser) {
private final CarbonChat carbonChat;
public ShadowMuteCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
arguments.put("player", CarbonUtils.chatUserArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(arguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.shadowmute"))
.executes(this::execute)
.register();
}
private void execute(CommandSender sender, Object[] args) {
ChatUser user = (ChatUser) args[0];
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
if (targetUser.isShadowMuted()) {
targetUser.setShadowMuted(false);
if (user.isShadowMuted()) {
user.setShadowMuted(false);
String format = carbonChat.getLanguage().getString("no-longer-shadow-muted");
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
"player", targetUser.asOfflinePlayer().getName());
"player", user.asOfflinePlayer().getName());
audience.sendMessage(message);
} else {
@@ -36,15 +54,15 @@ public class ShadowMuteCommand extends BaseCommand {
Permission permission = carbonChat.getPermission();
String format;
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.shadowmute.exempt")) {
if (permission.playerHas(null, user.asOfflinePlayer(), "carbonchat.shadowmute.exempt")) {
format = carbonChat.getLanguage().getString("shadow-mute-exempt");
} else {
targetUser.setShadowMuted(true);
user.setShadowMuted(true);
format = carbonChat.getLanguage().getString("is-now-shadow-muted");
}
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
"player", targetUser.asOfflinePlayer().getName());
"player", user.asOfflinePlayer().getName());
audience.sendMessage(message);
});
@@ -1,29 +1,70 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.BooleanArgument;
import dev.jorel.commandapi.arguments.LiteralArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.storage.UserChannelSettings;
import net.draycia.carbon.util.CarbonUtils;
import org.bukkit.entity.Player;
@CommandAlias("spych|spychannel|spy")
@CommandPermission("carbonchat.spy")
public class SpyChannelCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class SpyChannelCommand {
@Default
@CommandCompletion("@channel @nothing")
@Syntax("<channel>")
public void baseCommand(Player player, @Conditions("exists:true") ChatChannel channel) {
private final CarbonChat carbonChat;
public SpyChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
channelArguments.put("channel", CarbonUtils.channelArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(channelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.spy"))
.executesPlayer(this::execute)
.register();
LinkedHashMap<String, Argument> whisperArguments = new LinkedHashMap<>();
whisperArguments.put("channel", new LiteralArgument("whispers"));
new CommandAPICommand(commandSettings.getName())
.withArguments(whisperArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.spy"))
.executesPlayer(this::executeWhispers)
.register();
LinkedHashMap<String, Argument> everythingArguments = new LinkedHashMap<>();
everythingArguments.put("channel", new LiteralArgument("*"));
everythingArguments.put("should-spy", new BooleanArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(everythingArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.spy"))
.executesPlayer(this::executeEverything) // lul
.register();
}
private void execute(Player player, Object[] args) {
ChatChannel chatChannel = (ChatChannel) args[0];
ChatUser user = carbonChat.getUserService().wrap(player);
String message;
UserChannelSettings settings = user.getChannelSettings(channel);
UserChannelSettings settings = user.getChannelSettings(chatChannel);
if (settings.isSpying()) {
settings.setSpying(false);
@@ -34,11 +75,10 @@ public class SpyChannelCommand extends BaseCommand {
}
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
"color", "<color:" + chatChannel.getChannelColor(user).toString() + ">", "channel", chatChannel.getName()));
}
@Subcommand("whispers")
public void whispersCommand(Player player) {
private void executeWhispers(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
String message;
@@ -54,4 +94,32 @@ public class SpyChannelCommand extends BaseCommand {
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
}
private void executeEverything(Player player, Object[] args) {
Boolean shouldSpy = (Boolean) args[0];
ChatUser user = carbonChat.getUserService().wrap(player);
String message;
if (shouldSpy) {
user.setSpyingWhispers(true);
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
user.getChannelSettings(channel).setSpying(true);
}
message = carbonChat.getLanguage().getString("spy-everything-off");
} else {
user.setSpyingWhispers(false);
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
user.getChannelSettings(channel).setSpying(false);
}
message = carbonChat.getLanguage().getString("spy-everything-on");
}
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
}
}
@@ -0,0 +1,73 @@
package net.draycia.carbon.commands;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import java.util.LinkedHashMap;
public class SudoChannelCommand {
private final CarbonChat carbonChat;
public SudoChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
setOtherChannelArguments.put("player", CarbonUtils.onlineChatUserArgument());
setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(setOtherChannelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.channel.others"))
.executes((sender, args) -> { this.setOtherChannel(sender, (ChatUser) args[0], (ChatChannel) args[1]); })
.register();
LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
sendMessageOtherArguments.put("player", CarbonUtils.onlineChatUserArgument());
sendMessageOtherArguments.put("channel", CarbonUtils.channelArgument());
sendMessageOtherArguments.put("message", new GreedyStringArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(sendMessageOtherArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.channel.others.message"))
.executes((sender, args) -> { this.sendMessageOther(sender, (ChatUser) args[0], (ChatChannel) args[1], (String) args[2]); })
.register();
}
private void setOtherChannel(CommandSender sender, ChatUser user, ChatChannel channel) {
user.setSelectedChannel(channel);
String message = channel.getSwitchMessage();
String otherMessage = channel.getSwitchOtherMessage();
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName(),
"player", user.asOfflinePlayer().getName()));
}
private void sendMessageOther(CommandSender sender, ChatUser user, ChatChannel channel, String message) {
Component component = channel.sendMessage(user, message, false);
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
}
@@ -1,26 +1,55 @@
package net.draycia.carbon.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.storage.CommandSettings;
import net.draycia.carbon.storage.UserChannelSettings;
import net.draycia.carbon.util.CarbonUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandAlias("tch|togglec|togglechannel|toggle")
@CommandPermission("carbonchat.toggle")
public class ToggleCommand extends BaseCommand {
import java.util.LinkedHashMap;
@Dependency
private CarbonChat carbonChat;
public class ToggleCommand {
@Default
@CommandCompletion("@chatchannel @players @nothing")
@Syntax("<channel>")
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel) {
private final CarbonChat carbonChat;
public ToggleCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.isEnabled()) {
return;
}
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
channelArguments.put("channel", CarbonUtils.channelArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(channelArguments)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
.executesPlayer(this::executeSelf)
.register();
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
argumentsOther.put("players", CarbonUtils.chatUserArgument());
argumentsOther.put("channel", CarbonUtils.channelArgument());
new CommandAPICommand(commandSettings.getName())
.withArguments(argumentsOther)
.withAliases(commandSettings.getAliasesArray())
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
.executes(this::executeOther)
.register();
}
private void executeSelf(Player player, Object[] args) {
ChatUser user = carbonChat.getUserService().wrap(player);
ChatChannel channel = (ChatChannel) args[0];
String message;
@@ -40,11 +69,10 @@ public class ToggleCommand extends BaseCommand {
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
}
@CommandPermission("carbonchat.toggle.others")
@Subcommand("other")
@CommandCompletion("@chatchannel @players")
@Syntax("<channel> <player>")
public void baseCommand(CommandSender sender, @Conditions("canuse:true") ChatChannel channel, ChatUser user) {
private void executeOther(CommandSender sender, Object[] args) {
ChatUser user = (ChatUser) args[0];
ChatChannel channel = (ChatChannel) args[1];
String message;
String otherMessage;
@@ -25,9 +25,14 @@ public class FilterHandler implements Listener {
public FilterHandler(CarbonChat carbonChat) {
this.carbonChat = carbonChat;
reloadFilters();
}
public void reloadFilters() {
patternReplacements.clear();
blockedWords.clear();
FileConfiguration config = carbonChat.getModConfig();
ConfigurationSection filters = config.getConfigurationSection("filters.filters");
for (String replacement : filters.getKeys(false)) {
@@ -2,7 +2,10 @@ package net.draycia.carbon.listeners;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.events.ChatComponentEvent;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -21,12 +24,24 @@ public class ItemLinkHandler implements Listener {
public void onItemLink(ChatComponentEvent event) {
// Handle item linking placeholders
if (event.getSender().isOnline()) {
Player player = event.getSender().asPlayer();
if (!player.hasPermission("carbonchat.itemlink")) {
return;
}
Component itemComponent = CarbonUtils.createComponent(player);
if (itemComponent.equals(TextComponent.empty())) {
return;
}
for (Pattern pattern : event.getChannel().getItemLinkPatterns()) {
String patternContent = pattern.toString().replace("\\Q", "").replace("\\E", "");
if (event.getOriginalMessage().contains(patternContent)) {
TextComponent component = (TextComponent)event.getComponent().replaceFirstText(pattern, (input) -> {
return TextComponent.builder().append(carbonChat.getItemStackUtils().createComponent(event.getSender().asPlayer()));
return TextComponent.builder().append(itemComponent);
});
event.setComponent(component);
@@ -79,7 +79,7 @@ public class ChannelManager {
return channel;
}
public void reload() {
private void reload() {
registry.clearAll();
for (String key : carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
@@ -1,105 +1,42 @@
package net.draycia.carbon.managers;
import co.aikar.commands.*;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.commands.*;
import net.draycia.carbon.storage.ChatUser;
import java.util.ArrayList;
import java.util.List;
import net.draycia.carbon.storage.CommandSettings;
import org.bukkit.configuration.ConfigurationSection;
public class CommandManager {
private final BukkitCommandManager commandManager;
private final CarbonChat carbonChat;
public CommandManager(CarbonChat carbonChat) {
commandManager = new BukkitCommandManager(carbonChat);
commandManager.enableUnstableAPI("help");
commandManager.getCommandCompletions().registerCompletion("chatchannel", (context) -> {
ChatUser user = carbonChat.getUserService().wrap(context.getPlayer());
List<String> completions = new ArrayList<>();
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
if (chatChannel.canPlayerUse(user)) {
completions.add(chatChannel.getKey());
}
}
return completions;
});
commandManager.getCommandCompletions().registerCompletion("channel", (context) -> {
List<String> completions = new ArrayList<>();
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
completions.add(chatChannel.getKey());
}
return completions;
});
commandManager.getCommandContexts().registerContext(ChatChannel.class, (context) -> {
String name = context.popFirstArg();
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
if (chatChannel.getKey().equalsIgnoreCase(name)) {
return chatChannel;
}
}
return null;
});
commandManager.getCommandContexts().registerContext(ChatUser.class, (context) -> {
return carbonChat.getUserService().wrap(context.popFirstArg());
});
commandManager.getCommandConditions().addCondition(ChatChannel.class,"canuse", (context, execution, value) -> {
if (value == null) {
throw new ConditionFailedException(carbonChat.getLanguage().getString("cannot-use-channel"));
}
ChatUser user = carbonChat.getUserService().wrap(context.getIssuer().getPlayer());
if (!value.canPlayerUse(user)) {
throw new ConditionFailedException(value.getCannotUseMessage());
}
});
commandManager.getCommandConditions().addCondition(ChatChannel.class,"exists", (context, execution, value) -> {
if (value == null) {
throw new ConditionFailedException(carbonChat.getLanguage().getString("cannot-use-channel"));
}
});
reloadCommands();
this.carbonChat = carbonChat;
reloadCommands(carbonChat);
}
public void reloadCommands() {
this.commandManager.registerCommand(new ToggleCommand());
this.commandManager.registerCommand(new ChannelCommand());
this.commandManager.registerCommand(new ChannelListCommand());
this.commandManager.registerCommand(new IgnoreCommand());
this.commandManager.registerCommand(new ChatReloadCommand());
this.commandManager.registerCommand(new MeCommand());
this.commandManager.registerCommand(new MessageCommand());
this.commandManager.registerCommand(new NicknameCommand());
this.commandManager.registerCommand(new ReplyCommand());
this.commandManager.registerCommand(new SetColorCommand());
this.commandManager.registerCommand(new SpyChannelCommand());
this.commandManager.registerCommand(new ClearChatCommand());
this.commandManager.registerCommand(new MuteCommand());
this.commandManager.registerCommand(new ShadowMuteCommand());
private void reloadCommands(CarbonChat carbonChat) {
new ChannelCommand(carbonChat, getCommandSettings("channel"));
new ChannelListCommand(carbonChat, getCommandSettings("channellist"));
new ChatReloadCommand(carbonChat, getCommandSettings("chatreload"));
new ClearChatCommand(carbonChat, getCommandSettings("clearchat"));
new IgnoreCommand(carbonChat, getCommandSettings("ignore"));
new MeCommand(carbonChat, getCommandSettings("me"));
new MessageCommand(carbonChat, getCommandSettings("message"));
new MuteCommand(carbonChat, getCommandSettings("mute"));
new NicknameCommand(carbonChat, getCommandSettings("nickname"));
new ReplyCommand(carbonChat, getCommandSettings("reply"));
new SetColorCommand(carbonChat, getCommandSettings("setcolor"));
new ShadowMuteCommand(carbonChat, getCommandSettings("shadowmute"));
new SpyChannelCommand(carbonChat, getCommandSettings("spy"));
new SudoChannelCommand(carbonChat, getCommandSettings("sudochannel"));
new ToggleCommand(carbonChat, getCommandSettings("toggle"));
}
public BukkitCommandManager getCommandManager() {
return commandManager;
private CommandSettings getCommandSettings(String command) {
ConfigurationSection section = carbonChat.getCommandsConfig().getConfigurationSection(command);
return new CommandSettings(section.getBoolean("enabled"), section.getString("name"),
section.getStringList("aliases"));
}
}
@@ -0,0 +1,32 @@
package net.draycia.carbon.storage;
import java.util.List;
public class CommandSettings {
private boolean enabled;
private String name;
private List<String> aliases;
public CommandSettings(boolean enabled, String name, List<String> aliases) {
this.enabled = enabled;
this.name = name;
this.aliases = aliases;
}
public String[] getAliasesArray() {
return aliases.toArray(new String[0]);
}
public List<String> getAliases() {
return aliases;
}
public String getName() {
return name;
}
public boolean isEnabled() {
return enabled;
}
}
@@ -20,53 +20,58 @@
*/
package net.draycia.carbon.util;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.CustomArgument;
import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.platform.bukkit.MinecraftComponentSerializer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.*;
import net.md_5.bungee.api.chat.hover.content.Content;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
public final class CarbonUtils {
private final Method asNMSCopyMethod;
private final Method cMethod;
public CarbonUtils() throws NoSuchMethodException, ClassNotFoundException {
final String version = Bukkit.getServer().getClass().getPackage().getName()
.substring("org.bukkit.craftbukkit.".length());
Class<?> craftItemStackClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
this.asNMSCopyMethod = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class);
Class<?> itemStackClass = Class.forName("net.minecraft.server." + version + ".ItemStack");
this.cMethod = itemStackClass.getMethod("C");
}
public Component createComponent(final Player player) {
final ItemStack itemStack = player.getInventory().getItemInMainHand();
if (itemStack == null || itemStack.getType() == Material.AIR) {
return TextComponent.empty();
}
public static Component createComponent(final Player player) {
try {
final Object cbItemStack = this.asNMSCopyMethod.invoke(null, itemStack);
final Object mojangComponent = this.cMethod.invoke(cbItemStack);
final ItemStack itemStack = player.getInventory().getItemInMainHand();
return MinecraftComponentSerializer.INSTANCE.deserialize(mojangComponent);
} catch (final IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return TextComponent.empty();
}
if (itemStack == null || itemStack.getType() == Material.AIR) {
return net.kyori.adventure.text.TextComponent.empty();
}
Content content = Bukkit.getItemFactory().hoverContentOf(itemStack);
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_ITEM, content);
ComponentBuilder component = new ComponentBuilder();
component.color(ChatColor.WHITE).append("[");
if (itemStack.getItemMeta().hasDisplayName()) {
component.append(TextComponent.fromLegacyText(itemStack.getItemMeta().getDisplayName()));
} else {
component.append(new TranslatableComponent(itemStack.getItemMeta().getLocalizedName()));
}
component.color(ChatColor.WHITE).append("]");
component.event(event);
return BungeeCordComponentSerializer.get().deserialize(component.create());
} catch (NoSuchMethodError ignored) {}
return net.kyori.adventure.text.TextComponent.empty();
}
public static TextColor parseColor(ChatUser user, String input) {
@@ -93,4 +98,114 @@ public final class CarbonUtils {
return TextColor.fromCSSHexString(input);
}
public static TextColor parseColor(String input) {
if (input == null) {
input = "white";
}
for (NamedTextColor namedColor : NamedTextColor.values()) {
if (namedColor.toString().equalsIgnoreCase(input)) {
return namedColor;
}
}
if (input.contains("&") || input.contains("§")) {
input = input.replace("&", "§");
return LegacyComponentSerializer.legacySection().deserialize(input).color();
}
return TextColor.fromCSSHexString(input);
}
public static Argument onlineChatUserArgument() {
return new CustomArgument<>((input) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
Player player = Bukkit.getPlayer(input);
if (player == null) {
throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")");
}
return carbonChat.getUserService().wrap(player);
}).overrideSuggestions((sender, args) -> {
ArrayList<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) {
players.add(player.getName());
}
return players.toArray(new String[0]);
});
}
public static Argument chatUserArgument() {
return new CustomArgument<>((input) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
return carbonChat.getUserService().wrap(input);
}).overrideSuggestions((sender, args) -> {
ArrayList<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) {
players.add(player.getName());
}
return players.toArray(new String[0]);
});
}
private static String[] colors;
static {
ArrayList<String> colorList = new ArrayList<>();
for (NamedTextColor color : NamedTextColor.values()) {
colorList.add(color.toString());
}
colors = colorList.toArray(new String[0]);
}
public static Argument textColorArgument() {
return new CustomArgument<>((input) -> {
TextColor color = parseColor(input);
if (color == null) {
throw new CustomArgument.CustomArgumentException("Invalid color for input (" + input + ")");
}
return color;
}).overrideSuggestions(colors);
}
public static Argument channelArgument() {
return new CustomArgument<>((input) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(input);
if (channel == null) {
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
}
return channel;
}).overrideSuggestions((sender, args) -> {
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
ArrayList<String> channels = new ArrayList<>();
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
channels.add(channel.getKey());
}
return channels.toArray(new String[0]);
});
}
public static Argument usableChannelArgument() {
throw new NotImplementedException("Not implemented yet.");
}
}
@@ -0,0 +1,720 @@
package net.draycia.carbon.util;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
/**
* bStats collects some data for plugin authors.
* <p>
* Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics {
static {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
final String defaultPackage = new String(
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure nobody just copy & pastes the example and use the wrong package names
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
}
// The version of this bStats class
public static final int B_STATS_VERSION = 1;
// The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit";
// Is bStats enabled on this server?
private boolean enabled;
// Should failed requests be logged?
private static boolean logFailedRequests;
// Should the sent data be logged?
private static boolean logSentData;
// Should the response text be logged?
private static boolean logResponseStatusText;
// The uuid of the server
private static String serverUUID;
// The plugin
private final Plugin plugin;
// The plugin id
private final int pluginId;
// A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>();
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
* @param pluginId The id of the plugin.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
public Metrics(Plugin plugin, int pluginId) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
this.pluginId = pluginId;
// Get the config file
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
File configFile = new File(bStatsFolder, "config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists
if (!config.isSet("serverUuid")) {
// Add default values
config.addDefault("enabled", true);
// Every server gets it's unique random id.
config.addDefault("serverUuid", UUID.randomUUID().toString());
// Should failed request be logged?
config.addDefault("logFailedRequests", false);
// Should the sent data be logged?
config.addDefault("logSentData", false);
// Should the response text be logged?
config.addDefault("logResponseStatusText", false);
// Inform the server owners about bStats
config.options().header(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
).copyDefaults(true);
try {
config.save(configFile);
} catch (IOException ignored) { }
}
// Load the data
enabled = config.getBoolean("enabled", true);
serverUUID = config.getString("serverUuid");
logFailedRequests = config.getBoolean("logFailedRequests", false);
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled) {
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException ignored) { }
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
if (!found) {
// We are the first!
startSubmitting();
}
}
}
/**
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
public boolean isEnabled() {
return enabled;
}
/**
* Adds a custom chart.
*
* @param chart The chart to add.
*/
public void addCustomChart(CustomChart chart) {
if (chart == null) {
throw new IllegalArgumentException("Chart cannot be null!");
}
charts.add(chart);
}
/**
* Starts the Scheduler which submits our data every 30 minutes.
*/
private void startSubmitting() {
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!plugin.isEnabled()) { // Plugin was disabled
timer.cancel();
return;
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!
}
/**
* Gets the plugin specific data.
* This method is called using Reflection.
*
* @return The plugin specific data.
*/
public JsonObject getPluginData() {
JsonObject data = new JsonObject();
String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion();
data.addProperty("pluginName", pluginName); // Append the name of the plugin
data.addProperty("id", pluginId); // Append the id of the plugin
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
JsonArray customCharts = new JsonArray();
for (CustomChart customChart : charts) {
// Add the data of the custom charts
JsonObject chart = customChart.getRequestJsonObject();
if (chart == null) { // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.add("customCharts", customCharts);
return data;
}
/**
* Gets the server specific data.
*
* @return The server specific data.
*/
private JsonObject getServerData() {
// Minecraft specific data
int playerAmount;
try {
// Around MC 1.8 the return type was changed to a collection from an array,
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
String bukkitVersion = Bukkit.getVersion();
String bukkitName = Bukkit.getName();
// OS/Java specific data
String javaVersion = System.getProperty("java.version");
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version");
int coreCount = Runtime.getRuntime().availableProcessors();
JsonObject data = new JsonObject();
data.addProperty("serverUUID", serverUUID);
data.addProperty("playerAmount", playerAmount);
data.addProperty("onlineMode", onlineMode);
data.addProperty("bukkitVersion", bukkitVersion);
data.addProperty("bukkitName", bukkitName);
data.addProperty("javaVersion", javaVersion);
data.addProperty("osName", osName);
data.addProperty("osArch", osArch);
data.addProperty("osVersion", osVersion);
data.addProperty("coreCount", coreCount);
return data;
}
/**
* Collects the data and sends it afterwards.
*/
private void submitData() {
final JsonObject data = getServerData();
JsonArray pluginData = new JsonArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
if (plugin instanceof JsonObject) {
pluginData.add((JsonObject) plugin);
} else { // old bstats version compatibility
try {
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
jsonStringGetter.setAccessible(true);
String jsonString = (String) jsonStringGetter.invoke(plugin);
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
pluginData.add(object);
}
} catch (ClassNotFoundException e) {
// minecraft version 1.14+
if (logFailedRequests) {
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
}
}
}
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
}
} catch (NoSuchFieldException ignored) { }
}
data.add("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(() -> {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}).start();
}
/**
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
if (data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData) {
plugin.getLogger().info("Sending data to bStats: " + data);
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.write(compressedData);
}
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
}
if (logResponseStatusText) {
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
}
}
/**
* Gzips the given String.
*
* @param str The string to gzip.
* @return The gzipped String.
* @throws IOException If the compression failed.
*/
private static byte[] compress(final String str) throws IOException {
if (str == null) {
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
gzip.write(str.getBytes(StandardCharsets.UTF_8));
}
return outputStream.toByteArray();
}
/**
* Represents a custom chart.
*/
public static abstract class CustomChart {
// The id of the chart
final String chartId;
/**
* Class constructor.
*
* @param chartId The id of the chart.
*/
CustomChart(String chartId) {
if (chartId == null || chartId.isEmpty()) {
throw new IllegalArgumentException("ChartId cannot be null or empty!");
}
this.chartId = chartId;
}
private JsonObject getRequestJsonObject() {
JsonObject chart = new JsonObject();
chart.addProperty("chartId", chartId);
try {
JsonObject data = getChartData();
if (data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.add("data", data);
} catch (Throwable t) {
if (logFailedRequests) {
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
}
return null;
}
return chart;
}
protected abstract JsonObject getChartData() throws Exception;
}
/**
* Represents a custom simple pie.
*/
public static class SimplePie extends CustomChart {
private final Callable<String> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
String value = callable.call();
if (value == null || value.isEmpty()) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom advanced pie.
*/
public static class AdvancedPie extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom drilldown pie.
*/
public static class DrilldownPie extends CustomChart {
private final Callable<Map<String, Map<String, Integer>>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
super(chartId);
this.callable = callable;
}
@Override
public JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
JsonObject value = new JsonObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped) {
reallyAllSkipped = false;
values.add(entryValues.getKey(), value);
}
}
if (reallyAllSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom single line chart.
*/
public static class SingleLineChart extends CustomChart {
private final Callable<Integer> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
int value = callable.call();
if (value == 0) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom multi line chart.
*/
public static class MultiLineChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom simple bar chart.
*/
public static class SimpleBarChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
JsonArray categoryValues = new JsonArray();
categoryValues.add(new JsonPrimitive(entry.getValue()));
values.add(entry.getKey(), categoryValues);
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom advanced bar chart.
*/
public static class AdvancedBarChart extends CustomChart {
private final Callable<Map<String, int[]>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
if (entry.getValue().length == 0) {
continue; // Skip this invalid
}
allSkipped = false;
JsonArray categoryValues = new JsonArray();
for (int categoryValue : entry.getValue()) {
categoryValues.add(new JsonPrimitive(categoryValue));
}
values.add(entry.getKey(), categoryValues);
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
}
@@ -0,0 +1,31 @@
package net.draycia.carbon.util;
import org.jetbrains.annotations.Nullable;
public class ThisOrThat<A, B> {
@Nullable A objectA;
@Nullable B objectB;
public ThisOrThat(@Nullable A objectA, @Nullable B objectB) {
this.objectA = objectA;
this.objectB = objectB;
}
public boolean isThis() {
return objectA != null;
}
public boolean isThat() {
return objectB != null;
}
public @Nullable A getThis() {
return objectA;
}
public @Nullable B getThat() {
return objectB;
}
}
+60
View File
@@ -0,0 +1,60 @@
channel:
enabled: true
name: 'channel'
aliases: ['ch', 'switch', 'join']
channellist:
enabled: true
name: 'channellist'
aliases: ['chlist']
chatreload:
enabled: true
name: 'chatreload'
aliases: ['creload', 'cr']
clearchat:
enabled: true
name: 'clearchat'
aliases: ['clear', 'cc']
ignore:
enabled: true
name: 'ignore'
aliases: ['block']
me:
enabled: true
name: 'me'
aliases: ['rp']
message:
enabled: true
name: ['message']
aliases: ['msg', 'whisper', 'w']
mute:
enabled: true
name: 'mute'
aliases: ['m']
nickname:
enabled: true
name: 'nickname'
aliases: ['nick']
reply:
enabled: true
name: 'reply'
aliases: ['r']
setcolor:
enabled: true
name: 'setcolor'
aliases: ['setcolor']
shadowmute:
enabled: true
name: 'shadowmute'
aliases: ['sm', 'smute']
spy:
enabled: true
name: 'spy'
aliases: ['spych', 'spychannel']
sudochannel:
enabled: true
name: 'sudochannel'
aliases: ['sch', 'sudoch', 'schannel', 'chsudo', 'channelsudo']
toggle:
enabled: true
name: 'toggle'
aliases: ['togglechannel', 'tch', 'togglech', 'tchannel', 'togglec']
+3
View File
@@ -21,6 +21,9 @@ available-channels-list: '<green>Available Channels:<reset> <list>.'
unavailable-channels-list: '<red>Unavailable Channels:<reset> <list>.'
channel-list-separator: ', '
user-must-be-online: '<red><player> must be online!'
reply-message-blank: '<red>Your reply message was blank!'
invalid-color: '<red>The input <input> is not a valid color!'
cannot-set-color: '<red>You do not have permission to set a color for this channel!'
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'