use of com.loohp.interactivechat.data.Database in project InteractiveChat by LOOHP.
the class InteractiveChat method onEnable.
@Override
public void onEnable() {
plugin = this;
externalProcessor = new ProcessExternalMessage();
getServer().getPluginManager().registerEvents(new Debug(), this);
Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
exactMinecraftVersion = Bukkit.getVersion().substring(Bukkit.getVersion().indexOf("(") + 5, Bukkit.getVersion().indexOf(")"));
version = MCVersion.fromPackageName(getServer().getClass().getPackage().getName());
if (!version.isSupported()) {
getServer().getConsoleSender().sendMessage(ChatColor.RED + "[InteractiveChat] This version of minecraft is unsupported! (" + version.toString() + ")");
}
if (!getDataFolder().exists()) {
getDataFolder().mkdirs();
}
try {
ConfigManager.setup();
} catch (IOException e) {
e.printStackTrace();
getServer().getPluginManager().disablePlugin(this);
return;
}
protocolManager = ProtocolLibrary.getProtocolManager();
getCommand("interactivechat").setExecutor(new Commands());
bungeecordMode = ConfigManager.getConfig().getBoolean("Settings.Bungeecord");
if (bungeecordMode) {
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[InteractiveChat] Registering Plugin Messaging Channels for bungeecord...");
getServer().getMessenger().registerOutgoingPluginChannel(this, "interchat:main");
getServer().getMessenger().registerIncomingPluginChannel(this, "interchat:main", bungeeMessageListener = new BungeeMessageListener(this));
getServer().getPluginManager().registerEvents(new ServerPingListener(), this);
ServerPingListener.listen();
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
if (parsePAPIOnMainThread) {
Bukkit.getScheduler().runTask(plugin, () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
PlaceholderParser.parse(ICPlayerFactory.getICPlayer(player), usePlayerNameHoverText);
PlaceholderParser.parse(ICPlayerFactory.getICPlayer(player), usePlayerNameClickValue);
}
});
} else {
for (Player player : Bukkit.getOnlinePlayers()) {
PlaceholderParser.parse(ICPlayerFactory.getICPlayer(player), usePlayerNameHoverText);
PlaceholderParser.parse(ICPlayerFactory.getICPlayer(player), usePlayerNameClickValue);
}
}
}, 0, 100);
}
BiConsumer<String, Inventory> inventoryRemovalListener = (hash, inv) -> {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> closeInventoryViews(inv));
};
itemDisplay.registerRemovalListener(inventoryRemovalListener);
inventoryDisplay.registerRemovalListener(inventoryRemovalListener);
inventoryDisplay1Upper.registerRemovalListener(inventoryRemovalListener);
inventoryDisplay1Lower.registerRemovalListener(inventoryRemovalListener);
enderDisplay.registerRemovalListener(inventoryRemovalListener);
mapDisplay.registerRemovalListener((hash, item) -> {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
boolean removed = MapViewer.MAP_VIEWERS.remove(player, item);
if (removed) {
// noinspection deprecation
player.getInventory().setItemInHand(player.getInventory().getItemInHand());
}
}
});
});
YamlConfiguration storage = ConfigManager.getStorageConfig();
database = new Database(false, getDataFolder(), storage.getString("StorageType"), storage.getString("MYSQL.Host"), storage.getString("MYSQL.Database"), storage.getString("MYSQL.Username"), storage.getString("MYSQL.Password"), storage.getInt("MYSQL.Port"));
database.setup();
placeholderCooldownManager = new PlaceholderCooldownManager();
getServer().getPluginManager().registerEvents(new ChatEvents(), this);
getServer().getPluginManager().registerEvents(new InventoryEvents(), this);
getServer().getPluginManager().registerEvents(new PlayerUtils(), this);
getServer().getPluginManager().registerEvents(new OutChatPacket(), this);
getServer().getPluginManager().registerEvents(new MapViewer(), this);
OutChatPacket.chatMessageListener();
if (!version.isLegacy()) {
OutTabCompletePacket.tabCompleteListener();
}
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
perms = rsp.getProvider();
if (isPluginEnabled("SuperVanish") || isPluginEnabled("PremiumVanish")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into SuperVanish/PremiumVanish!");
vanishHook = true;
}
if (isPluginEnabled("CMI", false)) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into CMI!");
cmiHook = true;
}
if (isPluginEnabled("Essentials")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into Essentials!");
essentialsHook = true;
getServer().getPluginManager().registerEvents(new EssentialsNicknames(), this);
EssentialsNicknames._init_();
}
if (isPluginEnabled("EssentialsDiscord")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into EssentialsDiscord!");
essentialsDiscordHook = true;
getServer().getPluginManager().registerEvents(new EssentialsDiscord(), this);
}
if (isPluginEnabled("DiscordSRV")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into DiscordSRV!");
DiscordSRV.api.subscribe(new DiscordSRVEvents());
discordSrvHook = true;
}
if (isPluginEnabled("ViaVersion")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into ViaVersion!");
viaVersionHook = true;
}
if (isPluginEnabled("ProtocolSupport")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into ProtocolSupport!");
protocolSupportHook = true;
}
if (isPluginEnabled("eco")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into Eco (Core)!");
ecoHook = true;
}
if (isPluginEnabled("LuckPerms")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into LuckPerms!");
new LuckPermsEvents(this);
luckPermsHook = true;
}
if (isPluginEnabled("MysqlPlayerDataBridge")) {
getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat has hooked into MysqlPlayerDataBridge!");
mysqlPDBHook = true;
}
if (isPluginEnabled("VentureChat")) {
VentureChatInjection._init_();
getServer().getConsoleSender().sendMessage(ChatColor.LIGHT_PURPLE + "[InteractiveChat] InteractiveChat has injected into VentureChat!");
ventureChatHook = true;
}
if (isPluginEnabled("dynmap")) {
getServer().getConsoleSender().sendMessage(ChatColor.LIGHT_PURPLE + "[InteractiveChat] InteractiveChat has injected into Dynmap!");
DynmapListener._init_();
dynmapHook = true;
}
PlayernameDisplay.setup();
MentionDisplay.setup();
Charts.setup(metrics);
if (updaterEnabled) {
getServer().getPluginManager().registerEvents(new Updater(), this);
}
ClientSettingPacket.clientSettingsListener();
playerDataManager = new PlayerDataManager(this, database);
nicknameManager = new NicknameManager(uuid -> InteractiveChatAPI.getNicknames(uuid), () -> InteractiveChatAPI.getOnlineICPlayers().stream().filter(each -> each.isLocal()).map(each -> each.getUniqueId()).collect(Collectors.toSet()), 5000, (uuid, nicknames) -> {
if (InteractiveChat.bungeecordMode) {
Player bukkitPlayer = Bukkit.getPlayer(uuid);
if (bukkitPlayer != null) {
Set<String> nicks = new HashSet<>(nicknames);
if (InteractiveChat.useBukkitDisplayName) {
nicks.add(bukkitPlayer.getDisplayName());
}
try {
BungeeMessageSender.forwardNicknames(System.currentTimeMillis(), uuid, nicks);
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
new Placeholders().register();
}
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[InteractiveChat] InteractiveChat has been Enabled!");
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
if (queueRemoteUpdate && Bukkit.getOnlinePlayers().size() > 0) {
try {
if (BungeeMessageSender.resetAndForwardPlaceholderList(System.currentTimeMillis(), InteractiveChat.placeholderList.values())) {
queueRemoteUpdate = false;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, 0, 100);
try {
Logger logger = LogManager.getRootLogger();
LogFilter filter = new LogFilter();
Method method = logger.getClass().getMethod("addFilter", Filter.class);
method.invoke(logger, filter);
} catch (Exception e) {
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[InteractiveChat] Unable to add filter to logger, safely skipping...");
}
gc();
}
Aggregations