SHARE
TWEET

Untitled

a guest Mar 23rd, 2014 33 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.jamco.minecraft.plugins.jamos;
  2.  
  3. import java.awt.Graphics2D;
  4. import java.awt.Image;
  5. import java.awt.image.BufferedImage;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import me.bigteddy98.mapart.ArtRenderer;
  10.  
  11. import org.bukkit.Location;
  12. import org.bukkit.command.Command;
  13. import org.bukkit.command.CommandSender;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class JamOS extends JavaPlugin implements Listener {
  18.    
  19.     private ArtRenderer artRenderer;
  20.        
  21.         @Override
  22.         public void onEnable() {
  23.                 getServer().getPluginManager().registerEvents(this, this);
  24.                
  25.                 artRenderer = new ArtRenderer(this);
  26.                 Location loc = new Location(getServer().getWorld("world"), 27, 74, -60);
  27.                 BufferedImage image = toBufferedImage(artRenderer.getImageFromURL("http://i.imgur.com/uOAsa4x.png"));
  28.                 List<BufferedImage> images = split(image, 5, 3);
  29.                 int imageNum = 1;
  30.                
  31.                 int start_x = 27;
  32.         int start_y = 74;
  33.         int start_z = -60;
  34.         int end_x = 31;
  35.         int end_y = 76;
  36.         int end_z = -60;
  37.         for (int x = start_x; x <= end_x; x++) {
  38.             for (int y = start_y; y <= end_y; y++) {
  39.                 for (int z = start_z; z <= end_z; z++) {
  40.                         loc = new Location(getServer().getWorld("world"), x, y, z);
  41.                         artRenderer.makeArt(loc, images.get(imageNum));
  42.                         imageNum++;
  43.                 }
  44.             }
  45.         }
  46.         }
  47.        
  48.         public static BufferedImage toBufferedImage(Image img)
  49.         {
  50.             if (img instanceof BufferedImage)
  51.             {
  52.                 return (BufferedImage) img;
  53.             }
  54.  
  55.             // Create a buffered image with transparency
  56.             BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
  57.  
  58.             // Draw the image on to the buffered image
  59.             Graphics2D bGr = bimage.createGraphics();
  60.             bGr.drawImage(img, 0, 0, null);
  61.             bGr.dispose();
  62.  
  63.             // Return the buffered image
  64.             return bimage;
  65.         }
  66.        
  67.         @Override
  68.         public void onDisable() {
  69.                 artRenderer.reloadAll();
  70.         }
  71.        
  72.         public void log(String msg) {
  73.                 getLogger().info(msg);
  74.         }
  75.        
  76.         public List<BufferedImage> split(BufferedImage image, int width, int height) {
  77.         int type = image.getType();
  78.         int imageWidth = image.getWidth();
  79.         int imageHeight = image.getHeight();
  80.         int rows = imageWidth / width;
  81.         if (imageWidth % width != 0)
  82.             rows++;
  83.         int columns = imageHeight / height;
  84.         if (imageHeight % height != 0)
  85.             columns++;
  86.         List<BufferedImage> images = new ArrayList<BufferedImage>();
  87.         for (int x = 0; x < rows; x++) {
  88.             for (int y = 0; y < columns; y++) {
  89.                 int positionX = width * x;
  90.                 int positionY = width * y;
  91.                 int splitWidth = positionX + width > imageWidth ? imageWidth - positionX : width;
  92.                 int splitHeight = positionY + height > imageHeight ? imageHeight - positionY : height;
  93.                 BufferedImage split = new BufferedImage(splitWidth, splitHeight, type);
  94.                 Graphics2D graphics = split.createGraphics();
  95.                 graphics.drawImage(image, 0, 0, splitWidth, splitHeight, positionX, positionY, positionX + splitWidth, positionY + splitHeight, null);
  96.                 graphics.dispose();
  97.                 images.add(split);
  98.             }
  99.         }
  100.         return images;
  101.     }
  102.        
  103.         public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
  104.                 if(cmd.getName().equalsIgnoreCase("jamos")){
  105.                         //Do some stuff
  106.                         /**if(args[1] == "login") {
  107.                                
  108.                         }*/
  109.                        
  110.                        
  111.                         return true;
  112.                 } //If this has happened the function will return true.
  113.               // If this hasn't happened the a value of false will be returned.
  114.                 return false;
  115.         }
  116.        
  117. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top