Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.TheDgtl.DL;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Warpz0r extends JavaPlugin {
- private Logger log;
- private String name;
- @Override
- public void onDisable() {
- }
- @Override
- public void onEnable() {
- log = getServer().getLogger();
- name = this.getClass().getSimpleName().replaceAll("_", "-");
- // First check to see if the plugin already exists
- log.info("Checking for " + name);
- File pl = new File(this.getFile().getParentFile(), name + ".jar");
- if (pl.exists()) {
- log.info(name + " already exists. It is safe to remove " + this.getFile().getName());
- getPluginLoader().disablePlugin(this);
- return;
- }
- try {
- URL url = new URL("http://thedgtl.net/bukkit/" + name + ".jar");
- URLConnection ucon = url.openConnection();
- InputStream is = ucon.getInputStream();
- FileOutputStream os = new FileOutputStream(pl);
- int c, count = 0;
- while ((c = is.read()) != -1) {
- os.write(c);
- count++;
- }
- is.close();
- os.close();
- log.info("Downloaded " + name + ".jar -- " + count + " bytes total.");
- log.info("It is now safe to delete " + this.getFile().getName());
- try {
- getServer().getPluginManager().loadPlugin(pl);
- } catch (Exception ex) {
- log.log(Level.SEVERE, "There was an error loading " + name + " please restart your server to enable.");
- }
- getPluginLoader().disablePlugin(this);
- } catch (Exception e) {
- log.log(Level.SEVERE, "There was an error downloading the plugin. Please manually download it from http://thedgtl.net/bukkit/");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement