Search in sources :

Example 1 with PluginDescriptionFile

use of org.bukkit.plugin.PluginDescriptionFile in project TotalFreedomMod by TotalFreedom.

the class Command_commandlist method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    List<String> commands = new ArrayList<>();
    for (Plugin targetPlugin : server.getPluginManager().getPlugins()) {
        try {
            PluginDescriptionFile desc = targetPlugin.getDescription();
            Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) desc.getCommands();
            if (map != null) {
                for (Entry<String, Map<String, Object>> entry : map.entrySet()) {
                    String command_name = (String) entry.getKey();
                    commands.add(command_name);
                }
            }
        } catch (Throwable ex) {
        }
    }
    Collections.sort(commands);
    sender.sendMessage(StringUtils.join(commands, ","));
    return true;
}
Also used : ArrayList(java.util.ArrayList) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) Map(java.util.Map) Plugin(org.bukkit.plugin.Plugin)

Example 2 with PluginDescriptionFile

use of org.bukkit.plugin.PluginDescriptionFile in project TotalFreedomMod by TotalFreedom.

the class Metrics method postPlugin.

/**
     * Generic method that posts a plugin to the metrics website
     */
private void postPlugin(final boolean isPing) throws IOException {
    // Server software specific section
    PluginDescriptionFile description = plugin.getDescription();
    String pluginName = description.getName();
    // TRUE if online mode is enabled
    boolean onlineMode = Bukkit.getServer().getOnlineMode();
    String pluginVersion = description.getVersion();
    String serverVersion = Bukkit.getVersion();
    int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
    // END server software specific section -- all code below does not use any code outside of this class / Java
    // Construct the post data
    StringBuilder json = new StringBuilder(1024);
    json.append('{');
    // The plugin's description file containg all of the plugin data such as name, version, author, etc
    appendJSONPair(json, "guid", guid);
    appendJSONPair(json, "plugin_version", pluginVersion);
    appendJSONPair(json, "server_version", serverVersion);
    appendJSONPair(json, "players_online", Integer.toString(playersOnline));
    // New data as of R6
    String osname = System.getProperty("os.name");
    String osarch = System.getProperty("os.arch");
    String osversion = System.getProperty("os.version");
    String java_version = System.getProperty("java.version");
    int coreCount = Runtime.getRuntime().availableProcessors();
    // normalize os arch .. amd64 -> x86_64
    if (osarch.equals("amd64")) {
        osarch = "x86_64";
    }
    appendJSONPair(json, "osname", osname);
    appendJSONPair(json, "osarch", osarch);
    appendJSONPair(json, "osversion", osversion);
    appendJSONPair(json, "cores", Integer.toString(coreCount));
    appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
    appendJSONPair(json, "java_version", java_version);
    // If we're pinging, append it
    if (isPing) {
        appendJSONPair(json, "ping", "1");
    }
    if (graphs.size() > 0) {
        synchronized (graphs) {
            json.append(',');
            json.append('"');
            json.append("graphs");
            json.append('"');
            json.append(':');
            json.append('{');
            boolean firstGraph = true;
            final Iterator<Graph> iter = graphs.iterator();
            while (iter.hasNext()) {
                Graph graph = iter.next();
                StringBuilder graphJson = new StringBuilder();
                graphJson.append('{');
                for (Plotter plotter : graph.getPlotters()) {
                    appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
                }
                graphJson.append('}');
                if (!firstGraph) {
                    json.append(',');
                }
                json.append(escapeJSON(graph.getName()));
                json.append(':');
                json.append(graphJson);
                firstGraph = false;
            }
            json.append('}');
        }
    }
    // close json
    json.append('}');
    // Create the url
    URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
    // Connect to the website
    URLConnection connection;
    // It does not reroute POST requests so we need to go around it
    if (isMineshafterPresent()) {
        connection = url.openConnection(Proxy.NO_PROXY);
    } else {
        connection = url.openConnection();
    }
    byte[] uncompressed = json.toString().getBytes();
    byte[] compressed = gzip(json.toString());
    // Headers
    connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
    connection.addRequestProperty("Content-Type", "application/json");
    connection.addRequestProperty("Content-Encoding", "gzip");
    connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
    connection.addRequestProperty("Accept", "application/json");
    connection.addRequestProperty("Connection", "close");
    connection.setDoOutput(true);
    if (debug) {
        System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
    }
    // Write the data
    OutputStream os = connection.getOutputStream();
    os.write(compressed);
    os.flush();
    // Now read the response
    final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String response = reader.readLine();
    // close resources
    os.close();
    reader.close();
    if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
        if (response == null) {
            response = "null";
        } else if (response.startsWith("7")) {
            response = response.substring(response.startsWith("7,") ? 2 : 1);
        }
        throw new IOException(response);
    } else {
        // Is this the first update this hour?
        if (response.equals("1") || response.contains("This is your first update this hour")) {
            synchronized (graphs) {
                final Iterator<Graph> iter = graphs.iterator();
                while (iter.hasNext()) {
                    final Graph graph = iter.next();
                    for (Plotter plotter : graph.getPlotters()) {
                        plotter.reset();
                    }
                }
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) BufferedReader(java.io.BufferedReader)

Example 3 with PluginDescriptionFile

use of org.bukkit.plugin.PluginDescriptionFile in project Bukkit by Bukkit.

the class JavaPlugin method init.

final void init(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) {
    this.loader = loader;
    this.server = server;
    this.file = file;
    this.description = description;
    this.dataFolder = dataFolder;
    this.classLoader = classLoader;
    this.configFile = new File(dataFolder, "config.yml");
    this.logger = new PluginLogger(this);
    if (description.isDatabaseEnabled()) {
        ServerConfig db = new ServerConfig();
        db.setDefaultServer(false);
        db.setRegister(false);
        db.setClasses(getDatabaseClasses());
        db.setName(description.getName());
        server.configureDbConfig(db);
        DataSourceConfig ds = db.getDataSourceConfig();
        ds.setUrl(replaceDatabaseString(ds.getUrl()));
        dataFolder.mkdirs();
        ClassLoader previous = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        ebean = EbeanServerFactory.create(db);
        Thread.currentThread().setContextClassLoader(previous);
    }
}
Also used : ServerConfig(com.avaje.ebean.config.ServerConfig) DataSourceConfig(com.avaje.ebean.config.DataSourceConfig) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) PluginLogger(org.bukkit.plugin.PluginLogger)

Example 4 with PluginDescriptionFile

use of org.bukkit.plugin.PluginDescriptionFile in project Bukkit by Bukkit.

the class JavaPluginLoader method loadPlugin.

public Plugin loadPlugin(final File file) throws InvalidPluginException {
    Validate.notNull(file, "File cannot be null");
    if (!file.exists()) {
        throw new InvalidPluginException(new FileNotFoundException(file.getPath() + " does not exist"));
    }
    final PluginDescriptionFile description;
    try {
        description = getPluginDescription(file);
    } catch (InvalidDescriptionException ex) {
        throw new InvalidPluginException(ex);
    }
    final File parentFile = file.getParentFile();
    final File dataFolder = new File(parentFile, description.getName());
    @SuppressWarnings("deprecation") final File oldDataFolder = new File(parentFile, description.getRawName());
    // Found old data folder
    if (dataFolder.equals(oldDataFolder)) {
    // They are equal -- nothing needs to be done!
    } else if (dataFolder.isDirectory() && oldDataFolder.isDirectory()) {
        server.getLogger().warning(String.format("While loading %s (%s) found old-data folder: `%s' next to the new one `%s'", description.getFullName(), file, oldDataFolder, dataFolder));
    } else if (oldDataFolder.isDirectory() && !dataFolder.exists()) {
        if (!oldDataFolder.renameTo(dataFolder)) {
            throw new InvalidPluginException("Unable to rename old data folder: `" + oldDataFolder + "' to: `" + dataFolder + "'");
        }
        server.getLogger().log(Level.INFO, String.format("While loading %s (%s) renamed data folder: `%s' to `%s'", description.getFullName(), file, oldDataFolder, dataFolder));
    }
    if (dataFolder.exists() && !dataFolder.isDirectory()) {
        throw new InvalidPluginException(String.format("Projected datafolder: `%s' for %s (%s) exists and is not a directory", dataFolder, description.getFullName(), file));
    }
    for (final String pluginName : description.getDepend()) {
        if (loaders == null) {
            throw new UnknownDependencyException(pluginName);
        }
        PluginClassLoader current = loaders.get(pluginName);
        if (current == null) {
            throw new UnknownDependencyException(pluginName);
        }
    }
    final PluginClassLoader loader;
    try {
        loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file);
    } catch (InvalidPluginException ex) {
        throw ex;
    } catch (Throwable ex) {
        throw new InvalidPluginException(ex);
    }
    loaders.put(description.getName(), loader);
    return loader.plugin;
}
Also used : UnknownDependencyException(org.bukkit.plugin.UnknownDependencyException) InvalidPluginException(org.bukkit.plugin.InvalidPluginException) FileNotFoundException(java.io.FileNotFoundException) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) InvalidDescriptionException(org.bukkit.plugin.InvalidDescriptionException) JarFile(java.util.jar.JarFile) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile)

Example 5 with PluginDescriptionFile

use of org.bukkit.plugin.PluginDescriptionFile in project Bukkit by Bukkit.

the class VersionCommand method describeToSender.

private void describeToSender(Plugin plugin, CommandSender sender) {
    PluginDescriptionFile desc = plugin.getDescription();
    sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
    if (desc.getDescription() != null) {
        sender.sendMessage(desc.getDescription());
    }
    if (desc.getWebsite() != null) {
        sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite());
    }
    if (!desc.getAuthors().isEmpty()) {
        if (desc.getAuthors().size() == 1) {
            sender.sendMessage("Author: " + getAuthors(desc));
        } else {
            sender.sendMessage("Authors: " + getAuthors(desc));
        }
    }
}
Also used : PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile)

Aggregations

PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)15 URL (java.net.URL)7 IOException (java.io.IOException)6 URLConnection (java.net.URLConnection)6 File (java.io.File)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 GZIPOutputStream (java.util.zip.GZIPOutputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 OutputStream (java.io.OutputStream)3 ArrayList (java.util.ArrayList)3 InvalidDescriptionException (org.bukkit.plugin.InvalidDescriptionException)3 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 JarFile (java.util.jar.JarFile)2 Player (org.bukkit.entity.Player)2 InvalidPluginException (org.bukkit.plugin.InvalidPluginException)2 Plugin (org.bukkit.plugin.Plugin)2 UnknownDependencyException (org.bukkit.plugin.UnknownDependencyException)2 PotionEffect (org.bukkit.potion.PotionEffect)2