all the fillr stuff

By: Taylor Kelly <tkelly910@gmail.com>
This commit is contained in:
Bukkit/Spigot
2011-01-03 11:01:36 +08:00
parent d0a03cd4c4
commit 7f5bbdf764
9 changed files with 582 additions and 3 deletions

View File

@ -0,0 +1,82 @@
package org.bukkit.fillr;
import java.util.*;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/**
* Grabs the latest info for a given plugin from fill.bukkit.org
*/
public class FillReader {
//TODO change this to what it will actually be...
private static String baseUrl = "http://taylorkelly.me/pnfo.php";
private String currVersion;
private String file;
private String name;
private String notes;
private boolean stable;
public FillReader(String name) {
try {
String result = "";
try {
URL url = new URL(baseUrl + "?name=" + name);
System.out.println(baseUrl + "?name=" + name);
URLConnection conn = url.openConnection();
StringBuilder buf = new StringBuilder();
BufferedReader rd = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
buf.append(line);
}
result = buf.toString();
rd.close();
JSONParser parser = new JSONParser();
Object obj;
obj = parser.parse(result);
JSONObject jsonObj = (JSONObject) obj;
this.currVersion = (String)jsonObj.get("plugin_version");
this.name = (String)jsonObj.get("plugin_name");
this.file = (String)jsonObj.get("plugin_file");
this.stable = (Boolean)jsonObj.get("plugin_stable");
this.notes = (String)jsonObj.get("plugin_notes");
} catch (ParseException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String getCurrVersion() {
return currVersion;
}
public String getFile() {
return file;
}
public String getName() {
return name;
}
public String getNotes() {
return notes;
}
public void setStable(boolean stable) {
this.stable = stable;
}
public boolean isStable() {
return stable;
}
}