Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.st_ddt.crazyplugin;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.net.URL;
- public final class Main
- implements Runnable
- {
- private String name = null;
- private String author = null;
- private String version = null;
- private String website = null;
- private String depend = null;
- private String softdepend = null;
- private String description = null;
- public static void main(String[] args)
- {
- new Main().run();
- }
- public void run()
- {
- try
- {
- InputStream stream = null;
- BufferedReader in = null;
- try
- {
- stream = getClass().getResourceAsStream("/plugin.yml");
- if (stream == null)
- return;
- in = new BufferedReader(new InputStreamReader(stream));
- boolean descr = false;
- String zeile;
- while ((zeile = in.readLine()) != null)
- {
- String zeile;
- if (zeile.matches("[a-z]+\\:.*"))
- {
- descr = false;
- if (zeile.startsWith("name:")) {
- this.name = zeile.substring(6);
- } else if (zeile.startsWith("author:")) {
- this.author = zeile.substring(8);
- } else if (zeile.startsWith("version:")) {
- this.version = zeile.substring(9);
- } else if (zeile.startsWith("website:")) {
- this.website = zeile.substring(9);
- } else if (zeile.startsWith("depend:")) {
- this.depend = zeile.substring(8);
- } else if (zeile.startsWith("softdepend:")) {
- this.softdepend = zeile.substring(12);
- } else if (zeile.startsWith("description:"))
- {
- descr = true;
- this.description = zeile.substring(13).trim();
- if (this.description.equals(">"))
- this.description = "";
- else
- this.description += "\n ";
- }
- }
- else if (descr) {
- this.description = (this.description + zeile.trim() + "\n "); }
- }if (this.description != null)
- this.description = this.description.trim();
- }
- finally
- {
- if (stream != null)
- stream.close();
- if (in != null)
- in.close();
- }
- if (stream != null)
- stream.close();
- if (in != null) {
- in.close();
- }
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- PrintStream out = System.out;
- out.println();
- out.println();
- out.println();
- out.println(" Sorry, this is a plugin and won't run without a compatible Bukkit server software.");
- out.println(" You can download it here:");
- out.println(" http://dl.bukkit.org/");
- out.println();
- out.println();
- out.println(" Pluginname: " + this.name);
- out.println(" Current Version: " + this.version);
- try
- {
- BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
- out.println(" Check for Updates ?");
- out.println(" - Type \"Yes\" or \"No\" ?");
- out.print(" > ");
- String zeile = console.readLine();
- if ((zeile != null) && (
- (zeile.equalsIgnoreCase("yes")) || (zeile.equalsIgnoreCase("y"))))
- {
- String latest = getLastestVersion();
- if (latest == null)
- out.println(" Latest official Version: none");
- else
- out.println(" Latest official Version: " + latest);
- }
- }
- catch (Exception localException) {
- }
- if (this.website != null)
- out.println(" Website: " + this.website);
- out.println(" Author: " + this.author);
- if (this.depend != null)
- out.println(" Required plugins: " + this.depend.replace(" ", "").replace("[", "").replace("]", "").replace(",", ", "));
- if (this.softdepend != null)
- out.println(" Optional plugins: " + this.softdepend.replace(" ", "").replace("[", "").replace("]", "").replace(",", ", "));
- if ((this.description != null) &&
- (this.description.length() > 1))
- {
- out.println();
- out.println();
- out.println(" Description:");
- out.println(" " + this.description);
- }
- out.println();
- try
- {
- Thread.sleep(5000L);
- }
- catch (InterruptedException localInterruptedException)
- {
- }
- }
- private String getLastestVersion()
- {
- try {
- BufferedReader bufreader = null;
- try
- {
- InputStream stream = new URL("http://dev.bukkit.org/server-mods/" + this.name.toLowerCase() + "/files.rss").openStream();
- if (stream == null)
- return null;
- bufreader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
- String zeile = null;
- boolean active = false;
- while ((zeile = bufreader.readLine()) != null)
- {
- zeile = zeile.trim();
- if ((active) && (zeile.startsWith("<title>")))
- return zeile.substring(7 + this.name.length() + 2).split("<")[0];
- if (zeile.equals("<item>")) {
- active = true;
- }
- }
- }
- finally
- {
- if (bufreader != null)
- bufreader.close();
- }
- if (bufreader != null) {
- bufreader.close();
- }
- }
- catch (Exception e)
- {
- return null;
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment