Advertisement
Drakia

Untitled

Oct 30th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package net.TheDgtl.DL;
  2.  
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.InputStream;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10.  
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13. public class Warpz0r extends JavaPlugin {
  14.     private Logger log;
  15.     private String name;
  16.     @Override
  17.     public void onDisable() {
  18.        
  19.     }
  20.  
  21.     @Override
  22.     public void onEnable() {
  23.         log = getServer().getLogger();
  24.         name = this.getClass().getSimpleName().replaceAll("_", "-");
  25.         // First check to see if the plugin already exists
  26.         log.info("Checking for " + name);
  27.         File pl = new File(this.getFile().getParentFile(), name + ".jar");
  28.         if (pl.exists()) {
  29.             log.info(name + " already exists. It is safe to remove " + this.getFile().getName());
  30.             getPluginLoader().disablePlugin(this);
  31.             return;
  32.         }
  33.         try {
  34.             URL url = new URL("http://thedgtl.net/bukkit/" + name + ".jar");
  35.             URLConnection ucon = url.openConnection();
  36.             InputStream is = ucon.getInputStream();
  37.             FileOutputStream os = new FileOutputStream(pl);
  38.             int c, count = 0;
  39.             while ((c = is.read()) != -1) {
  40.                 os.write(c);
  41.                 count++;
  42.             }
  43.             is.close();
  44.             os.close();
  45.             log.info("Downloaded " + name + ".jar -- " + count + " bytes total.");
  46.             log.info("It is now safe to delete " + this.getFile().getName());
  47.             try {
  48.                 getServer().getPluginManager().loadPlugin(pl);
  49.             } catch (Exception ex) {
  50.                 log.log(Level.SEVERE, "There was an error loading " + name + " please restart your server to enable.");
  51.             }
  52.             getPluginLoader().disablePlugin(this);
  53.         } catch (Exception e) {
  54.             log.log(Level.SEVERE, "There was an error downloading the plugin. Please manually download it from http://thedgtl.net/bukkit/");
  55.         }
  56.     }
  57. }
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement