Search in sources :

Example 1 with SimplePie

use of org.bstats.charts.SimplePie in project AuthMeReloaded by AuthMe.

the class OnStartupTasks method sendMetrics.

/**
 * Sends bstats metrics.
 *
 * @param plugin the plugin instance
 * @param settings the settings
 */
public static void sendMetrics(AuthMe plugin, Settings settings) {
    final Metrics metrics = new Metrics(plugin, 164);
    metrics.addCustomChart(new SimplePie("messages_language", () -> settings.getProperty(PluginSettings.MESSAGES_LANGUAGE)));
    metrics.addCustomChart(new SimplePie("database_backend", () -> settings.getProperty(DatabaseSettings.BACKEND).toString()));
}
Also used : Metrics(org.bstats.bukkit.Metrics) SimplePie(org.bstats.charts.SimplePie)

Example 2 with SimplePie

use of org.bstats.charts.SimplePie in project VotingPlugin by Ben12345rocks.

the class VotingPluginVelocity method onProxyInitialization.

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
    File configFile = new File(dataDirectory.toFile(), "bungeeconfig.yml");
    configFile.getParentFile().mkdirs();
    if (!configFile.exists()) {
        try {
            configFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        InputStream toCopyStream = VotingPluginVelocity.class.getClassLoader().getResourceAsStream("bungeeconfig.yml");
        try (FileOutputStream fos = new FileOutputStream(configFile)) {
            byte[] buf = new byte[2048];
            int r;
            while (-1 != (r = toCopyStream.read(buf))) {
                fos.write(buf, 0, r);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    config = new Config(configFile);
    server.getChannelRegistrar().register(CHANNEL);
    method = BungeeMethod.getByName(config.getBungeeMethod());
    boolean mysqlLoaded = true;
    try {
        if (!config.getString(config.getNode("Host"), "").isEmpty()) {
            loadMysql();
        } else {
            mysqlLoaded = false;
            logger.error("MySQL settings not set in bungeeconfig.yml");
        }
    } catch (Exception e) {
        mysqlLoaded = false;
        e.printStackTrace();
    }
    CommandMeta meta = server.getCommandManager().metaBuilder("votingpluginbungee").aliases("vpb").build();
    server.getCommandManager().register(meta, new VotingPluginVelocityCommand(this));
    if (mysqlLoaded) {
        uuidPlayerNameCache = mysql.getRowsUUIDNameQuery();
        voteCacheFile = new VoteCache(new File(dataDirectory.toFile(), "votecache.yml"));
        nonVotedPlayersCache = new NonVotedPlayersCache(new File(dataDirectory.toFile(), "nonvotedplayerscache.yml"), this);
        timeHandle = new TimeHandle(voteCacheFile.getNode("Time", "Month").getString(""), voteCacheFile.getNode("Time", "Day").getInt(), voteCacheFile.getNode("Time", "Week").getInt()) {

            @Override
            public void save() {
                voteCacheFile.getNode("Time", "Month").setValue(timeHandle.getMonth());
                voteCacheFile.getNode("Time", "Day").setValue(timeHandle.getDay());
                voteCacheFile.getNode("Time", "Week").setValue(timeHandle.getWeek());
            }
        };
        if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
            try {
                for (String serverToCheck : voteCacheFile.getServers()) {
                    ArrayList<OfflineBungeeVote> vote = new ArrayList<OfflineBungeeVote>();
                    for (String num : voteCacheFile.getServerVotes(serverToCheck)) {
                        ConfigurationNode data = voteCacheFile.getServerVotes(serverToCheck, num);
                        vote.add(new OfflineBungeeVote(data.getNode("Name").getString(), data.getNode("UUID").getString(), data.getNode("Service").getString(), data.getNode("Time").getLong(), data.getNode("Real").getBoolean(), data.getNode("TEXT").getString()));
                    }
                    cachedVotes.put(server.getServer(serverToCheck).get(), vote);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                for (String player : voteCacheFile.getPlayers()) {
                    ArrayList<OfflineBungeeVote> vote = new ArrayList<OfflineBungeeVote>();
                    for (String num : voteCacheFile.getOnlineVotes(player)) {
                        ConfigurationNode data = voteCacheFile.getOnlineVotes(player, num);
                        vote.add(new OfflineBungeeVote(data.getNode("Name").getString(), data.getNode("UUID").getString(), data.getNode("Service").getString(), data.getNode("Time").getLong(), data.getNode("Real").getBoolean(), data.getNode("TEXT").getString()));
                    }
                    cachedOnlineVotes.put(player, vote);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            voteCacheFile.clearData();
            server.getScheduler().buildTask(this, () -> {
                for (RegisteredServer server : cachedVotes.keySet()) {
                    checkCachedVotes(server);
                }
                for (String player : cachedOnlineVotes.keySet()) {
                    if (server.getPlayer(UUID.fromString(player)).isPresent()) {
                        checkOnlineVotes(server.getPlayer(UUID.fromString(player)).get(), player, null);
                    }
                }
            }).delay(15L, TimeUnit.SECONDS).repeat(30l, TimeUnit.SECONDS).schedule();
            server.getScheduler().buildTask(this, () -> {
                if (nonVotedPlayersCache != null) {
                    debug("Checking nonvotedplayerscache.yml...");
                    nonVotedPlayersCache.check();
                }
            }).delay(1L, TimeUnit.MINUTES).repeat(60l, TimeUnit.MINUTES).schedule();
        } else if (method.equals(BungeeMethod.SOCKETS)) {
            encryptionHandler = new EncryptionHandler(new File(dataDirectory.toFile(), "secretkey.key"));
            socketHandler = new SocketHandler(server.getPluginManager().getPlugin("votingplugin").get().getDescription().getVersion().get(), config.getBungeeHost(), config.getBungeePort(), encryptionHandler, config.getDebug());
            socketHandler.add(new SocketReceiver() {

                @Override
                public void onReceive(String[] data) {
                    if (data.length > 1) {
                        if (data.length > 2) {
                            if (data[0].equalsIgnoreCase("Broadcast")) {
                                sendServerMessage(data);
                            }
                        }
                    }
                }
            });
            socketHandler.add(new SocketReceiver() {

                @Override
                public void onReceive(String[] data) {
                    if (data.length > 1) {
                        if (data[0].equalsIgnoreCase("StatusOkay")) {
                            String server = data[1];
                            logger.info("Voting communicaton okay with " + server);
                        }
                    }
                }
            });
            clientHandles = new HashMap<String, ClientHandler>();
            List<String> l = config.getBlockedServers();
            for (ConfigurationNode d : config.getSpigotServers()) {
                String s = d.getKey().toString();
                if (!l.contains(s)) {
                    clientHandles.put(s, new ClientHandler(d.getNode("Host").getString("0.0.0.0"), d.getNode("Port").getInt(1298), encryptionHandler, config.getDebug()));
                }
            }
        }
    }
    currentVotePartyVotesRequired = getConfig().getVotePartyVotesRequired() + voteCacheFile.getVotePartyInreaseVotesRequired();
    votePartyVotes = voteCacheFile.getVotePartyCurrentVotes();
    try {
        getVersionFile();
        if (versionFile != null) {
            versionFile.delete();
            versionFile.getParentFile().delete();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    Metrics metrics = metricsFactory.make(this, 11547);
    metrics.addCustomChart(new SimplePie("bungee_method", () -> getConfig().getBungeeMethod().toString()));
    metrics.addCustomChart(new SimplePie("sendtoallservers", () -> "" + getConfig().getSendVotesToAllServers()));
    metrics.addCustomChart(new SimplePie("allowunjoined", () -> "" + getConfig().getAllowUnJoined()));
    metrics.addCustomChart(new SimplePie("pointsonvote", () -> "" + getConfig().getPointsOnVote()));
    metrics.addCustomChart(new SimplePie("bungeemanagetotals", () -> "" + getConfig().getBungeeManageTotals()));
    metrics.addCustomChart(new SimplePie("waitforuseronline", () -> "" + getConfig().getWaitForUserOnline()));
    metrics.addCustomChart(new SimplePie("plugin_version", () -> "" + version));
    if (!buildNumber.equals("NOTSET")) {
        metrics.addCustomChart(new SimplePie("dev_build_number", () -> "" + buildNumber));
    }
    logger.info("VotingPlugin velocity loaded, method: " + method.toString() + ", PluginMessagingVersion: " + BungeeVersion.getPluginMessageVersion() + ", Internal Jar Version: " + version);
    if (!buildNumber.equals("NOTSET")) {
        logger.info("Detected using dev build number: " + buildNumber);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SocketHandler(com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler) SocketReceiver(com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver) ArrayList(java.util.ArrayList) SimplePie(org.bstats.charts.SimplePie) DataValueString(com.bencodez.advancedcore.api.user.usercache.value.DataValueString) EncryptionHandler(com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler) Metrics(org.bstats.velocity.Metrics) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) List(java.util.List) ArrayList(java.util.ArrayList) CommandMeta(com.velocitypowered.api.command.CommandMeta) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) OfflineBungeeVote(com.bencodez.votingplugin.bungee.OfflineBungeeVote) ClientHandler(com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) TimeHandle(com.bencodez.votingplugin.bungee.TimeHandle) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

SimplePie (org.bstats.charts.SimplePie)2 EncryptionHandler (com.bencodez.advancedcore.api.misc.encryption.EncryptionHandler)1 DataValueString (com.bencodez.advancedcore.api.user.usercache.value.DataValueString)1 ClientHandler (com.bencodez.advancedcore.bungeeapi.sockets.ClientHandler)1 SocketHandler (com.bencodez.advancedcore.bungeeapi.sockets.SocketHandler)1 SocketReceiver (com.bencodez.advancedcore.bungeeapi.sockets.SocketReceiver)1 OfflineBungeeVote (com.bencodez.votingplugin.bungee.OfflineBungeeVote)1 TimeHandle (com.bencodez.votingplugin.bungee.TimeHandle)1 CommandMeta (com.velocitypowered.api.command.CommandMeta)1 Subscribe (com.velocitypowered.api.event.Subscribe)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1