Search in sources :

Example 1 with Metrics

use of com.loohp.interactivechatdiscordsrvaddon.metrics.Metrics in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class InteractiveChatDiscordSrvAddon method onEnable.

@Override
public void onEnable() {
    plugin = this;
    interactivechat = InteractiveChat.plugin;
    discordsrv = DiscordSRV.getPlugin();
    if (!getDataFolder().exists()) {
        getDataFolder().mkdirs();
    }
    AssetsDownloader.loadLibraries(getDataFolder());
    try {
        Config.loadConfig(CONFIG_ID, new File(getDataFolder(), "config.yml"), getClass().getClassLoader().getResourceAsStream("config.yml"), getClass().getClassLoader().getResourceAsStream("config.yml"), true);
    } catch (IOException e) {
        e.printStackTrace();
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    reloadConfig();
    metrics = new Metrics(this, BSTATS_PLUGIN_ID);
    Charts.setup(metrics);
    DiscordSRV.api.subscribe(new DiscordReadyEvents());
    DiscordSRV.api.subscribe(new OutboundToDiscordEvents());
    DiscordSRV.api.subscribe(new InboundToGameEvents());
    getServer().getPluginManager().registerEvents(this, this);
    getServer().getPluginManager().registerEvents(new InboundToGameEvents(), this);
    getServer().getPluginManager().registerEvents(new OutboundToDiscordEvents(), this);
    getServer().getPluginManager().registerEvents(new ICPlayerEvents(), this);
    getServer().getPluginManager().registerEvents(new Debug(), this);
    getServer().getPluginManager().registerEvents(new Updater(), this);
    getCommand("interactivechatdiscordsrv").setExecutor(new Commands());
    File resourcepacks = new File(getDataFolder(), "resourcepacks");
    if (!resourcepacks.exists()) {
        File resources = new File(getDataFolder(), "resources");
        if (resources.exists() && resources.isDirectory()) {
            try {
                Files.move(resources.toPath(), resourcepacks.toPath(), StandardCopyOption.ATOMIC_MOVE);
            } catch (IOException e) {
                getServer().getConsoleSender().sendMessage(ChatColor.RED + "[ICDiscordSrvAddon] Unable to move folder, are any files opened?");
                e.printStackTrace();
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
        } else {
            resourcepacks.mkdirs();
        }
    }
    if (!compatible()) {
        for (int i = 0; i < 10; i++) {
            getServer().getConsoleSender().sendMessage(ChatColor.RED + "[ICDiscordSrvAddon] VERSION NOT COMPATIBLE WITH INSTALLED INTERACTIVECHAT VERSION, PLEASE UPDATE BOTH TO LATEST!!!!");
        }
        getServer().getPluginManager().disablePlugin(this);
        return;
    } else {
        getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[ICDiscordSrvAddon] InteractiveChat DiscordSRV Addon has been Enabled!");
    }
    reloadTextures(false, false);
    modelRenderer = new ModelRenderer(str -> new ThreadFactoryBuilder().setNameFormat(str).build(), () -> InteractiveChatDiscordSrvAddon.plugin.cacheTimeout, image -> ImageGeneration.getEnchantedImage(image), image -> ImageGeneration.getRawEnchantedImage(image), () -> 8, () -> Runtime.getRuntime().availableProcessors());
    ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("InteractiveChatDiscordSRVAddon Async Media Reading Thread #%d").build();
    mediaReadingService = Executors.newFixedThreadPool(4, factory);
    Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
        for (ICPlayer player : ICPlayerFactory.getOnlineICPlayers()) {
            cachePlayerSkin(player);
        }
        AssetsDownloader.loadExtras();
    }, 600, 6000);
}
Also used : Color(java.awt.Color) Charts(com.loohp.interactivechatdiscordsrvaddon.metrics.Charts) Arrays(java.util.Arrays) FontTextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.fonts.FontTextureResource) ListIterator(java.util.ListIterator) ResourcePackInfo(com.loohp.interactivechatdiscordsrvaddon.resources.ResourcePackInfo) JSONParser(com.loohp.interactivechat.libs.org.json.simple.parser.JSONParser) EventHandler(org.bukkit.event.EventHandler) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) Map(java.util.Map) ThreadFactory(java.util.concurrent.ThreadFactory) PlaceholderCooldownManager(com.loohp.interactivechat.objectholders.PlaceholderCooldownManager) Debug(com.loohp.interactivechatdiscordsrvaddon.debug.Debug) Bukkit(org.bukkit.Bukkit) InboundToGameEvents(com.loohp.interactivechatdiscordsrvaddon.listeners.InboundToGameEvents) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) CommandSender(org.bukkit.command.CommandSender) BufferedImage(java.awt.image.BufferedImage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Executors(java.util.concurrent.Executors) InteractiveChat(com.loohp.interactivechat.InteractiveChat) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) ImageGeneration(com.loohp.interactivechatdiscordsrvaddon.graphics.ImageGeneration) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Queue(java.util.Queue) Permission(github.scarsz.discordsrv.dependencies.jda.api.Permission) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) DiscordReadyEvents(com.loohp.interactivechatdiscordsrvaddon.listeners.DiscordReadyEvents) ImageUtils(com.loohp.interactivechatdiscordsrvaddon.graphics.ImageUtils) ResourceManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceManager) Registry(com.loohp.interactivechat.registry.Registry) Config(com.loohp.interactivechat.config.Config) ModelRenderer(com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer) SkinUtils(com.loohp.interactivechat.utils.SkinUtils) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiscordSRV(github.scarsz.discordsrv.DiscordSRV) LanguageUtils(com.loohp.interactivechat.utils.LanguageUtils) InteractiveChatRegistry(com.loohp.interactivechatdiscordsrvaddon.registry.InteractiveChatRegistry) Metrics(com.loohp.interactivechatdiscordsrvaddon.metrics.Metrics) JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject) OutboundToDiscordEvents(com.loohp.interactivechatdiscordsrvaddon.listeners.OutboundToDiscordEvents) ExecutorService(java.util.concurrent.ExecutorService) ChatColor(net.md_5.bungee.api.ChatColor) Listener(org.bukkit.event.Listener) ColorUtils(com.loohp.interactivechat.utils.ColorUtils) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Files(java.nio.file.Files) IOException(java.io.IOException) ICPlayerEvents(com.loohp.interactivechatdiscordsrvaddon.listeners.ICPlayerEvents) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) ICPlayerFactory(com.loohp.interactivechat.objectholders.ICPlayerFactory) ChatColorUtils(com.loohp.interactivechat.utils.ChatColorUtils) Collections(java.util.Collections) Updater(com.loohp.interactivechatdiscordsrvaddon.updater.Updater) ThreadFactory(java.util.concurrent.ThreadFactory) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) DiscordReadyEvents(com.loohp.interactivechatdiscordsrvaddon.listeners.DiscordReadyEvents) OutboundToDiscordEvents(com.loohp.interactivechatdiscordsrvaddon.listeners.OutboundToDiscordEvents) ICPlayerEvents(com.loohp.interactivechatdiscordsrvaddon.listeners.ICPlayerEvents) IOException(java.io.IOException) InboundToGameEvents(com.loohp.interactivechatdiscordsrvaddon.listeners.InboundToGameEvents) Metrics(com.loohp.interactivechatdiscordsrvaddon.metrics.Metrics) ModelRenderer(com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer) Updater(com.loohp.interactivechatdiscordsrvaddon.updater.Updater) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) File(java.io.File) Debug(com.loohp.interactivechatdiscordsrvaddon.debug.Debug)

Aggregations

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 InteractiveChat (com.loohp.interactivechat.InteractiveChat)1 Config (com.loohp.interactivechat.config.Config)1 JSONObject (com.loohp.interactivechat.libs.org.json.simple.JSONObject)1 JSONParser (com.loohp.interactivechat.libs.org.json.simple.parser.JSONParser)1 ICPlayer (com.loohp.interactivechat.objectholders.ICPlayer)1 ICPlayerFactory (com.loohp.interactivechat.objectholders.ICPlayerFactory)1 PlaceholderCooldownManager (com.loohp.interactivechat.objectholders.PlaceholderCooldownManager)1 Registry (com.loohp.interactivechat.registry.Registry)1 ChatColorUtils (com.loohp.interactivechat.utils.ChatColorUtils)1 ColorUtils (com.loohp.interactivechat.utils.ColorUtils)1 LanguageUtils (com.loohp.interactivechat.utils.LanguageUtils)1 SkinUtils (com.loohp.interactivechat.utils.SkinUtils)1 Debug (com.loohp.interactivechatdiscordsrvaddon.debug.Debug)1 ImageGeneration (com.loohp.interactivechatdiscordsrvaddon.graphics.ImageGeneration)1 ImageUtils (com.loohp.interactivechatdiscordsrvaddon.graphics.ImageUtils)1 DiscordReadyEvents (com.loohp.interactivechatdiscordsrvaddon.listeners.DiscordReadyEvents)1 ICPlayerEvents (com.loohp.interactivechatdiscordsrvaddon.listeners.ICPlayerEvents)1 InboundToGameEvents (com.loohp.interactivechatdiscordsrvaddon.listeners.InboundToGameEvents)1 OutboundToDiscordEvents (com.loohp.interactivechatdiscordsrvaddon.listeners.OutboundToDiscordEvents)1