ChestShop-3/src/main/java/com/Acrobot/ChestShop/ChestShop.java

592 lines
22 KiB
Java
Raw Normal View History

2011-05-15 19:33:03 +02:00
package com.Acrobot.ChestShop;
import com.Acrobot.Breeze.Configuration.Configuration;
2013-10-27 16:49:14 +01:00
import com.Acrobot.ChestShop.Commands.Give;
2011-05-29 13:25:25 +02:00
import com.Acrobot.ChestShop.Commands.ItemInfo;
import com.Acrobot.ChestShop.Commands.ShopInfo;
import com.Acrobot.ChestShop.Commands.Toggle;
2011-05-29 13:25:25 +02:00
import com.Acrobot.ChestShop.Commands.Version;
import com.Acrobot.ChestShop.Commands.AccessToggle;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Configuration.Properties;
2015-05-22 13:25:32 +02:00
import com.Acrobot.ChestShop.Database.Migrations;
import com.Acrobot.ChestShop.Listeners.Block.BlockPlace;
2012-09-12 12:35:48 +02:00
import com.Acrobot.ChestShop.Listeners.Block.Break.ChestBreak;
import com.Acrobot.ChestShop.Listeners.Block.Break.SignBreak;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.Block.SignCreate;
import com.Acrobot.ChestShop.Listeners.Economy.ServerAccountCorrector;
import com.Acrobot.ChestShop.Listeners.Economy.TaxModule;
import com.Acrobot.ChestShop.Listeners.AuthMeChestShopListener;
2015-05-22 13:25:32 +02:00
import com.Acrobot.ChestShop.Listeners.GarbageTextListener;
2013-03-24 20:57:54 +01:00
import com.Acrobot.ChestShop.Listeners.Item.ItemMoveListener;
import com.Acrobot.ChestShop.Listeners.Item.ItemStringListener;
import com.Acrobot.ChestShop.Listeners.ItemInfoListener;
import com.Acrobot.ChestShop.Listeners.Modules.ItemAliasModule;
import com.Acrobot.ChestShop.Listeners.Modules.MetricsModule;
2020-10-30 22:45:16 +01:00
import com.Acrobot.ChestShop.Listeners.Modules.StockCounterModule;
import com.Acrobot.ChestShop.Listeners.ShopInfoListener;
2019-01-17 19:50:47 +01:00
import com.Acrobot.ChestShop.Listeners.SignParseListener;
2013-04-23 21:04:59 +02:00
import com.Acrobot.ChestShop.Listeners.Modules.DiscountModule;
import com.Acrobot.ChestShop.Listeners.Modules.PriceRestrictionModule;
import com.Acrobot.ChestShop.Listeners.Player.*;
import com.Acrobot.ChestShop.Listeners.PreShopCreation.CreationFeeGetter;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.PostShopCreation.MessageSender;
2013-08-07 02:03:09 +02:00
import com.Acrobot.ChestShop.Listeners.PostShopCreation.ShopCreationLogger;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.PostShopCreation.SignSticker;
import com.Acrobot.ChestShop.Listeners.PostTransaction.*;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.PreShopCreation.*;
import com.Acrobot.ChestShop.Listeners.PreTransaction.*;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Listeners.PreTransaction.ErrorMessageSender;
import com.Acrobot.ChestShop.Listeners.PreTransaction.PermissionChecker;
2013-08-07 02:03:09 +02:00
import com.Acrobot.ChestShop.Listeners.ShopRemoval.ShopRefundListener;
import com.Acrobot.ChestShop.Listeners.ShopRemoval.ShopRemovalLogger;
import com.Acrobot.ChestShop.Logging.FileFormatter;
2013-01-24 22:35:28 +01:00
import com.Acrobot.ChestShop.Metadata.ItemDatabase;
2012-08-10 19:00:20 +02:00
import com.Acrobot.ChestShop.Signs.RestrictedSign;
2014-04-12 13:57:39 +02:00
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.Acrobot.ChestShop.Updater.JenkinsBuildsNotifier;
import com.Acrobot.ChestShop.Updater.Updater;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.message.Message;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
2016-08-20 22:17:10 +02:00
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
2011-05-29 13:25:25 +02:00
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
2011-05-29 13:25:25 +02:00
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.jar.JarFile;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.stream.Collectors;
2011-05-29 13:25:25 +02:00
/**
* Main file of the plugin
2011-05-29 13:25:25 +02:00
*
* @author Acrobot
*/
2011-05-15 19:33:03 +02:00
public class ChestShop extends JavaPlugin {
2013-01-24 22:35:28 +01:00
private static ChestShop plugin;
private static Server server;
private static PluginDescriptionFile description;
private static BukkitAudiences audiences;
2013-01-24 22:35:28 +01:00
private static File dataFolder;
private static ItemDatabase itemDatabase;
2013-01-24 22:35:28 +01:00
private static Logger logger;
private FileHandler handler;
private List<PluginCommand> commands = new ArrayList<>();
2015-05-22 13:25:32 +02:00
public ChestShop() {
dataFolder = getDataFolder();
2015-05-22 13:25:32 +02:00
logger = getLogger();
description = getDescription();
server = getServer();
2015-05-22 13:25:32 +02:00
plugin = this;
}
2018-08-29 21:32:27 +02:00
@Override
public void onLoad() {
Dependencies.initializePlugins();
}
@Override
2015-05-22 13:25:32 +02:00
public void onEnable() {
audiences = BukkitAudiences.create(this);
turnOffDatabaseLogging();
if (!handleMigrations()) {
return;
}
2014-04-12 17:37:23 +02:00
registerCommand("iteminfo", new ItemInfo(), Permission.ITEMINFO);
registerCommand("shopinfo", new ShopInfo(), Permission.SHOPINFO);
registerCommand("csVersion", new Version(), Permission.ADMIN);
registerCommand("csMetrics", new com.Acrobot.ChestShop.Commands.Metrics(), Permission.ADMIN);
registerCommand("csGive", new Give(), Permission.ADMIN);
registerCommand("cstoggle", new Toggle(), Permission.NOTIFY_TOGGLE);
registerCommand("csaccess", new AccessToggle(), Permission.ACCESS_TOGGLE);
loadConfig();
itemDatabase = new ItemDatabase();
if (!Dependencies.loadPlugins()) {
getServer().getPluginManager().disablePlugin(this);
return;
}
2011-05-29 13:25:25 +02:00
registerEvents();
registerPluginMessagingChannels();
if (Properties.LOG_TO_FILE) {
File log = loadFile("ChestShop.log");
FileHandler handler = loadHandler(log.getAbsolutePath());
handler.setFormatter(new FileFormatter());
this.handler = handler;
logger.addHandler(handler);
}
2012-12-19 18:54:23 +01:00
if (!Properties.LOG_TO_CONSOLE) {
logger.setUseParentHandlers(false);
}
2011-05-29 13:25:25 +02:00
startStatistics();
startBuildNotificatier();
2014-03-20 16:57:19 +01:00
startUpdater();
}
private void registerCommand(String name, CommandExecutor executor, Permission permission) {
PluginCommand command = getCommand(name);
command.setExecutor(executor);
command.setPermission(permission.toString());
commands.add(command);
}
public void loadConfig() {
Configuration.pairFileAndClass(loadFile("config.yml"), Properties.class, getBukkitLogger());
Messages.load();
NameManager.load();
commands.forEach(c -> c.setPermissionMessage(Messages.ACCESS_DENIED.getTextWithPrefix(null)));
}
private void turnOffDatabaseLogging() {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
org.apache.logging.log4j.core.config.Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig("");
loggerConfig.addFilter(new AbstractFilter() {
@Override
public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, String msg, Object... params) {
return filter(logger.getName(), level);
}
@Override
public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, Object msg, Throwable t) {
return filter(logger.getName(), level);
}
@Override
public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, Message msg, Throwable t) {
return filter(logger.getName(), level);
}
@Override
public Result filter(LogEvent event) {
return filter(event.getLoggerName(), event.getLevel());
}
private Result filter(String classname, Level level) {
if (level.intLevel() <= Level.ERROR.intLevel() && !classname.contains("SqliteDatabaseType")) {
return Result.NEUTRAL;
}
if (classname.contains("SqliteDatabaseType") || classname.contains("TableUtils")) {
return Result.DENY;
} else {
return Result.NEUTRAL;
}
}
});
}
private boolean handleMigrations() {
2014-04-21 17:08:20 +02:00
File versionFile = loadFile("version");
YamlConfiguration previousVersion = YamlConfiguration.loadConfiguration(versionFile);
2014-04-12 17:37:23 +02:00
if (previousVersion.get("version") == null) {
2015-05-22 13:25:32 +02:00
previousVersion.set("version", Migrations.CURRENT_DATABASE_VERSION);
2014-04-21 17:08:20 +02:00
try {
previousVersion.save(versionFile);
} catch (IOException e) {
e.printStackTrace();
}
2014-04-12 17:37:23 +02:00
}
int lastVersion = previousVersion.getInt("version");
2015-05-22 13:25:32 +02:00
int newVersion = Migrations.migrate(lastVersion);
2014-04-12 17:37:23 +02:00
if (newVersion == -1) {
plugin.getLogger().log(java.util.logging.Level.SEVERE, "Error while migrating! ChestShop can not run with a broken/outdated database...");
plugin.getServer().getPluginManager().disablePlugin(this);
return false;
} else if (lastVersion != newVersion) {
2015-05-22 13:25:32 +02:00
previousVersion.set("version", newVersion);
2015-03-11 18:01:50 +01:00
2015-05-22 13:25:32 +02:00
try {
previousVersion.save(versionFile);
} catch (IOException e) {
e.printStackTrace();
}
2014-04-12 17:37:23 +02:00
}
return true;
2014-04-12 17:37:23 +02:00
}
public static File loadFile(String string) {
File file = new File(dataFolder, string);
return loadFile(file);
}
private static File loadFile(File file) {
if (!file.exists()) {
try {
2013-04-05 13:11:06 +02:00
if (file.getParent() != null) {
file.getParentFile().mkdirs();
}
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
private static FileHandler loadHandler(String path) {
FileHandler handler = null;
try {
handler = new FileHandler(path, true);
} catch (IOException ex) {
ex.printStackTrace();
}
return handler;
}
public void onDisable() {
getServer().getScheduler().cancelTasks(this);
Toggle.clearToggledPlayers();
if (handler != null) {
handler.close();
getLogger().removeHandler(handler);
}
}
////////////////// REGISTER EVENTS, SCHEDULER & STATS ///////////////////////////
private void registerEvents() {
2012-06-25 17:15:32 +02:00
registerEvent(new com.Acrobot.ChestShop.Plugins.ChestShop()); //Chest protection
registerEvent(new Dependencies());
registerEvent(new NameManager());
2013-01-24 22:35:28 +01:00
registerPreShopCreationEvents();
registerPreTransactionEvents();
registerPostShopCreationEvents();
registerPostTransactionEvents();
2013-08-07 02:03:09 +02:00
registerShopRemovalEvents();
2013-01-24 22:35:28 +01:00
2013-04-23 21:04:59 +02:00
registerModules();
registerEvent(new SignBreak());
2013-01-24 22:35:28 +01:00
registerEvent(new SignCreate());
2012-09-12 12:35:48 +02:00
registerEvent(new ChestBreak());
registerEvent(new BlockPlace());
registerEvent(new PlayerConnect());
registerEvent(new PlayerInteract());
2012-09-12 12:35:48 +02:00
registerEvent(new PlayerInventory());
registerEvent(new PlayerLeave());
2013-07-28 16:59:44 +02:00
registerEvent(new PlayerTeleport());
2019-01-17 19:50:47 +01:00
registerEvent(new SignParseListener());
registerEvent(new ItemStringListener());
registerEvent(new ItemInfoListener());
registerEvent(new ShopInfoListener());
2015-05-22 13:25:32 +02:00
registerEvent(new GarbageTextListener());
2016-08-20 22:17:10 +02:00
Plugin authMe = getServer().getPluginManager().getPlugin("AuthMe");
2017-01-16 19:53:21 +01:00
if (authMe != null && authMe.isEnabled()) {
registerEvent(new AuthMeChestShopListener());
}
2013-01-24 22:35:28 +01:00
registerEvent(new RestrictedSign());
if (!Properties.TURN_OFF_HOPPER_PROTECTION) {
registerEvent(new ItemMoveListener());
}
2013-01-24 22:35:28 +01:00
}
2013-08-07 02:03:09 +02:00
private void registerShopRemovalEvents() {
registerEvent(new ShopRefundListener());
registerEvent(new ShopRemovalLogger());
}
2013-01-24 22:35:28 +01:00
private void registerPreShopCreationEvents() {
if (Properties.BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE) {
registerEvent(new PriceRatioChecker());
}
2013-01-24 22:35:28 +01:00
registerEvent(new ChestChecker());
registerEvent(new ItemChecker());
registerEvent(new MoneyChecker());
registerEvent(new NameChecker());
registerEvent(new com.Acrobot.ChestShop.Listeners.PreShopCreation.PermissionChecker());
registerEvent(new com.Acrobot.ChestShop.Listeners.PreShopCreation.ErrorMessageSender());
registerEvent(new PriceChecker());
registerEvent(new QuantityChecker());
registerEvent(new TerrainChecker());
}
2012-08-10 19:00:20 +02:00
2013-01-24 22:35:28 +01:00
private void registerPostShopCreationEvents() {
registerEvent(new CreationFeeGetter());
registerEvent(new MessageSender());
registerEvent(new SignSticker());
2013-08-07 02:03:09 +02:00
registerEvent(new ShopCreationLogger());
2013-01-24 22:35:28 +01:00
}
private void registerPreTransactionEvents() {
if (Properties.ALLOW_PARTIAL_TRANSACTIONS) {
registerEvent(new PartialTransactionModule());
} else {
registerEvent(new AmountAndPriceChecker());
}
registerEvent(new InvalidNameIgnorer());
2013-01-24 22:35:28 +01:00
registerEvent(new CreativeModeIgnorer());
registerEvent(new ErrorMessageSender());
registerEvent(new PermissionChecker());
registerEvent(new PriceValidator());
registerEvent(new ShopValidator());
registerEvent(new SpamClickProtector());
registerEvent(new StockFittingChecker());
}
private void registerPostTransactionEvents() {
registerEvent(new EconomicModule());
registerEvent(new EmptyShopDeleter());
registerEvent(new ItemManager());
registerEvent(new TransactionLogger());
registerEvent(new TransactionMessageSender());
}
2013-04-23 21:04:59 +02:00
private void registerModules() {
registerEvent(new ItemAliasModule());
2013-04-23 21:04:59 +02:00
registerEvent(new DiscountModule());
registerEvent(new MetricsModule());
2013-04-23 21:04:59 +02:00
registerEvent(new PriceRestrictionModule());
2020-10-30 22:45:16 +01:00
registerEvent(new StockCounterModule());
registerEconomicalModules();
}
private void registerEconomicalModules() {
registerEvent(new ServerAccountCorrector());
registerEvent(new TaxModule());
2013-04-23 21:04:59 +02:00
}
private void registerPluginMessagingChannels() {
if (Properties.BUNGEECORD_MESSAGES) {
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
}
}
public void registerEvent(Listener listener) {
getServer().getPluginManager().registerEvents(listener, this);
}
private void startStatistics() {
Metrics bStats = new Metrics(this, 1109);
try {
String dist = new JarFile(this.getFile()).getManifest().getMainAttributes().getValue("Distribution-Type");
bStats.addCustomChart(new Metrics.SimplePie("distributionType", () -> dist));
} catch (IOException ignored) {}
String serverVersion = getServer().getBukkitVersion().split("-")[0];
bStats.addCustomChart(createStaticDrilldownStat("versionMcSelf", serverVersion, getDescription().getVersion()));
bStats.addCustomChart(createStaticDrilldownStat("versionSelfMc", getDescription().getVersion(), serverVersion));
String javaVersion = System.getProperty("java.version");
bStats.addCustomChart(createStaticDrilldownStat("versionJavaSelf", javaVersion, getDescription().getVersion()));
bStats.addCustomChart(createStaticDrilldownStat("versionSelfJava", getDescription().getVersion(), javaVersion));
bStats.addCustomChart(createStaticDrilldownStat("versionJavaMc", javaVersion, serverVersion));
bStats.addCustomChart(createStaticDrilldownStat("versionMcJava", serverVersion, javaVersion));
bStats.addCustomChart(new Metrics.SingleLineChart("shopAccounts", NameManager::getAccountCount));
bStats.addCustomChart(new Metrics.MultiLineChart("transactionCount", () -> ImmutableMap.of(
"total", MetricsModule.getTotalTransactions(),
"buy", MetricsModule.getBuyTransactions(),
"sell", MetricsModule.getSellTransactions()
)));
bStats.addCustomChart(new Metrics.MultiLineChart("itemCount", () -> ImmutableMap.of(
"total", MetricsModule.getTotalItemsCount(),
"buy", MetricsModule.getSoldItemsCount(),
"sell", MetricsModule.getBoughtItemsCount()
)));
bStats.addCustomChart(new Metrics.SimplePie("includeSettingsInMetrics", () -> Properties.INCLUDE_SETTINGS_IN_METRICS ? "enabled" : "disabled"));
if (!Properties.INCLUDE_SETTINGS_IN_METRICS) return;
bStats.addCustomChart(new Metrics.AdvancedBarChart("pluginProperties", () -> {
Map<String, int[]> map = new LinkedHashMap<>();
map.put("ensure-correct-playerid", getChartArray(Properties.ENSURE_CORRECT_PLAYERID));
map.put("reverse-buttons", getChartArray(Properties.REVERSE_BUTTONS));
map.put("shift-sells-in-stacks", getChartArray(Properties.SHIFT_SELLS_IN_STACKS));
map.put("shift-sells-everything", getChartArray(Properties.SHIFT_SELLS_EVERYTHING));
map.put("allow-sign-chest-open", getChartArray(!Properties.ALLOW_SIGN_CHEST_OPEN));
map.put("sign-dying", getChartArray(!Properties.SIGN_DYING));
map.put("remove-empty-shops", getChartArray(!Properties.REMOVE_EMPTY_SHOPS));
map.put("remove-empty-chests", getChartArray(!Properties.REMOVE_EMPTY_CHESTS));
map.put("uses-server-economy-account", getChartArray(!Properties.SERVER_ECONOMY_ACCOUNT.isEmpty()));
map.put("uses-server-economy-account-uuid", getChartArray(!Properties.SERVER_ECONOMY_ACCOUNT_UUID.equals(new UUID(0, 0))));
map.put("allow-multiple-shops-at-one-block", getChartArray(Properties.ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK));
map.put("allow-partial-transactions", getChartArray(Properties.ALLOW_PARTIAL_TRANSACTIONS));
map.put("bungeecord-messages", getChartArray(Properties.BUNGEECORD_MESSAGES));
map.put("log-to-console", getChartArray(Properties.LOG_TO_CONSOLE));
map.put("log-to-file", getChartArray(Properties.LOG_TO_FILE));
return map;
}));
bStats.addCustomChart(new Metrics.SimpleBarChart("shopContainers",
() -> Properties.SHOP_CONTAINERS.stream().map(Material::name).collect(Collectors.toMap(k -> k, k -> 1))));
}
private Metrics.DrilldownPie createStaticDrilldownStat(String statId, String value1, String value2) {
final Map<String, Map<String, Integer>> map = ImmutableMap.of(value1, ImmutableMap.of(value2, 1));
return new Metrics.DrilldownPie(statId, () -> map);
}
private int[] getChartArray(boolean value) {
2020-06-21 20:09:03 +02:00
return new int[]{!value ? 1 : 0, value ? 0 : 1};
}
2014-03-20 16:57:19 +01:00
private static final int PROJECT_BUKKITDEV_ID = 31263;
private void startUpdater() {
if (Properties.TURN_OFF_UPDATES) {
getLogger().info("Auto-updater is disabled. If you want the plugin to automatically download new releases then set 'TURN_OFF_UPDATES' to 'false' in your config.yml!");
2014-03-20 16:57:19 +01:00
return;
}
new Updater(this, PROJECT_BUKKITDEV_ID, this.getFile(), Updater.UpdateType.DEFAULT, true);
}
private static final String PROJECT_JENKINS_JOB_URL = "https://ci.minebench.de/job/ChestShop-3/";
private void startBuildNotificatier() {
if (Properties.TURN_OFF_DEV_UPDATE_NOTIFIER) {
return;
}
new JenkinsBuildsNotifier(this, PROJECT_JENKINS_JOB_URL);
}
2011-05-29 13:25:25 +02:00
///////////////////////////////////////////////////////////////////////////////
2013-01-24 22:35:28 +01:00
public static ItemDatabase getItemDatabase() {
return itemDatabase;
}
public static File getFolder() {
return dataFolder;
}
public static Logger getBukkitLogger() {
return logger;
}
2011-05-29 13:25:25 +02:00
public static Server getBukkitServer() {
return server;
}
2011-05-29 13:25:25 +02:00
public static String getVersion() {
return description.getVersion();
2011-05-29 13:25:25 +02:00
}
public static String getPluginName() {
return description.getName();
2011-05-29 13:25:25 +02:00
}
2012-11-04 21:09:38 +01:00
public static List<String> getDependencies() {
return description.getSoftDepend();
}
2013-01-24 22:35:28 +01:00
public static ChestShop getPlugin() {
return plugin;
}
public static BukkitAudiences getAudiences() {
return audiences;
}
public static void registerListener(Listener listener) {
plugin.registerEvent(listener);
}
public static <E extends Event> E callEvent(E event) {
Bukkit.getPluginManager().callEvent(event);
return event;
}
public static void sendBungeeMessage(String playerName, Messages.Message message, Map<String, String> replacementMap, String... replacements) {
sendBungeeMessage(playerName, message.getComponent(null, true, replacementMap, replacements));
}
public static void sendBungeeMessage(String playerName, String message) {
sendBungeeMessage(playerName, "Message", message);
}
public static void sendBungeeMessage(String playerName, BaseComponent[] message) {
sendBungeeMessage(playerName, "MessageRaw", ComponentSerializer.toString(message));
}
public static void sendBungeeMessage(String playerName, Component message) {
sendBungeeMessage(playerName, "MessageRaw", GsonComponentSerializer.gson().serialize(message));
}
private static void sendBungeeMessage(String playerName, String channel, String message) {
if (Properties.BUNGEECORD_MESSAGES && !Bukkit.getOnlinePlayers().isEmpty()) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(channel);
out.writeUTF(playerName);
out.writeUTF(message);
Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
}
}