Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.54 KB | None | 0 0
  1. package fr.Rbmc.Pintocraft;
  2.  
  3.  
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.ObjectOutputStream;
  8. import java.sql.ResultSet;
  9.  
  10. import org.apache.logging.log4j.core.config.plugins.Plugin;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12.  
  13.  
  14.  
  15. public class main extends JavaPlugin
  16. {
  17.    
  18.     Plugin plugin;
  19.      
  20.     public void StructureAPI(Plugin pl)
  21.     {
  22.         this.plugin = pl;
  23.     }
  24.     public SqlConnection sql;
  25.     public ResultSet ID;
  26.    
  27.     public void onEnable()
  28.     {
  29.         sql = new SqlConnection("jdbc:mysql://","149.202.36.43:3306","TestPluginImpr3D","printschem","schempass");
  30.         sql.connection();
  31.     }
  32.    
  33.     public void onDisable()
  34.     {
  35.         sql.disconnect();
  36.     }
  37.  
  38.     public static class ITOA
  39.     {
  40.         public static String convert(int value, int base)
  41.         {
  42.             boolean negative = false;
  43.             String s = "";
  44.             if (value == 0)
  45.                 return "0";
  46.             negative = (value < 0);
  47.             if (negative)
  48.                 value = -1 * value;
  49.             while (value != 0)
  50.             {
  51.                 s = (value % base) + s;
  52.                 value = value / base;
  53.             }
  54.             if (negative)
  55.                 s = "-" + s;
  56.             return s;
  57.         }
  58.     }
  59.     /**
  60.     * Get all blocks between two points and return a 3d array
  61.     */
  62.  
  63.     public int[][][] getStructure(Block block, Block block2){
  64.         int minX, minZ, minY;
  65.         int maxX, maxZ, maxY;
  66.  
  67.  
  68.         //Couldv'e used Math.min()/Math.max(), but that didn't occur to me until after I finished this :D
  69.         minX = block.getX() < block2.getX() ? block.getX() : block2.getX();
  70.         minZ = block.getZ() < block2.getZ() ? block.getZ() : block2.getZ();
  71.         minY = block.getY() < block2.getY() ? block.getY() : block2.getY();
  72.  
  73.         maxX = block.getX() > block2.getX() ? block.getX() : block2.getX();
  74.         maxZ = block.getZ() > block2.getZ() ? block.getZ() : block2.getZ();
  75.         maxY = block.getY() > block2.getY() ? block.getY() : block2.getY();
  76.  
  77.         int[][][] blocks = new int[maxX-minX+1][maxY-minY+1][maxZ-minZ+1];
  78.  
  79.         for(int x = minX; x <= maxX; x++){
  80.  
  81.             for(int y = minY; y <= maxY; y++){
  82.  
  83.                 for(int z = minZ; z <= maxZ; z++){
  84.  
  85.                     Block b = block.getWorld().getBlockAt(x, y, z);
  86.                     blocks[x-minX][y-minY][z-minZ] = b.getTypeId();
  87.                 }
  88.             }
  89.         }
  90.  
  91.         return blocks;
  92.  
  93.     }
  94.    
  95.    
  96.    
  97.     public void save(int ID, int[][][] b)
  98.     {
  99.         ObjectOutputStream oos = null;
  100.         FileOutputStream fout = null;
  101.  
  102.         File f = new File(((JavaPlugin) plugin).getDataFolder() + "/schematics/"+ ITOA.convert(ID, 10) + ".schem");
  103.         File dir = new File(((JavaPlugin) plugin).getDataFolder() + "/schematics");
  104.        
  105.         try
  106.         {
  107.                 dir.mkdirs();
  108.                 f.createNewFile();
  109.         }
  110.         catch (IOException e1)
  111.         {
  112.                 e1.printStackTrace();
  113.         }
  114.         try
  115.         {
  116.                fout = new FileOutputStream(f);
  117.                oos = new ObjectOutputStream(fout);
  118.                oos.writeObject(b);
  119.         }
  120.         catch (Exception e)
  121.         {
  122.                e.printStackTrace();
  123.         }
  124.         finally
  125.         {
  126.                if(oos  != null)
  127.                {
  128.                    try
  129.                    {
  130.                         oos.close();
  131.                    }
  132.                    catch (IOException e)
  133.                    {
  134.                         e.printStackTrace();
  135.                    }
  136.                }
  137.         }
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement