Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.81 KB | None | 0 0
  1. package fr.mrstandu33.printocraft;
  2.  
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.ObjectOutputStream;
  7. import java.sql.ResultSet;
  8. import java.io.FileInputStream;
  9. import java.util.Arrays;
  10.  
  11. import org.apache.logging.log4j.core.config.plugins.Plugin;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. import fr.Rbmc.Pintocraft.main.ITOA;
  15. import fr.mrstandu33.printocraft.SqlConnection;
  16.  
  17. import org.bukkit.Location;
  18. import org.bukkit.block.Block;
  19.  
  20. public class utils extends JavaPlugin
  21. {
  22.     Plugin plugin;
  23.      
  24.     public void StructureAPI(Plugin pl)
  25.     {
  26.         this.plugin = pl;
  27.     }
  28.     public SqlConnection sql;
  29.     public static int ID;
  30.    
  31.     public void onEnable()
  32.     {
  33.         sql = new SqlConnection("jdbc:mysql://","149.202.36.43:3306","TestPluginImpr3D","printschem","schempass");
  34.         sql.connection();
  35.     }
  36.    
  37.     public void onDisable()
  38.     {
  39.         sql.disconnect();
  40.     }
  41.  
  42.     public static class ITOA
  43.     {
  44.         public static String convert(int value, int base)
  45.         {
  46.             boolean negative = false;
  47.             String s = "";
  48.             if (value == 0)
  49.                 return "0";
  50.             negative = (value < 0);
  51.             if (negative)
  52.                 value = -1 * value;
  53.             while (value != 0)
  54.             {
  55.                 s = (value % base) + s;
  56.                 value = value / base;
  57.             }
  58.             if (negative)
  59.                 s = "-" + s;
  60.             return s;
  61.         }
  62.     }
  63.  
  64.     public int[][][] getStructure(Block block, Block block2)
  65.     {
  66.         int minX, minZ, minY;
  67.         int maxX, maxZ, maxY;
  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 <= 255; 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.         return blocks;
  91.     }    
  92.    
  93.     public void save(int ID, int[][][] b)
  94.     {
  95.         ObjectOutputStream oos = null;
  96.         FileOutputStream fout = null;
  97.  
  98.         File f = new File(((JavaPlugin) plugin).getDataFolder() + "/schematics/"+ ITOA.convert(ID, 10) + ".schem");
  99.         File dir = new File(((JavaPlugin) plugin).getDataFolder() + "/schematics");
  100.        
  101.         try
  102.         {
  103.                 dir.mkdirs();
  104.                 f.createNewFile();
  105.         }
  106.         catch (IOException e1)
  107.         {
  108.                 e1.printStackTrace();
  109.         }
  110.         try
  111.         {
  112.                fout = new FileOutputStream(f);
  113.                oos = new ObjectOutputStream(fout);
  114.                oos.writeObject(b);
  115.         }
  116.         catch (Exception e)
  117.         {
  118.                e.printStackTrace();
  119.         }
  120.         finally
  121.         {
  122.                if(oos  != null)
  123.                {
  124.                    try
  125.                    {
  126.                         oos.close();
  127.                    }
  128.                    catch (IOException e)
  129.                    {
  130.                         e.printStackTrace();
  131.                    }
  132.                }
  133.         }
  134.     }
  135. }
  136.  
  137. public class main extends JavaPlugin
  138. {
  139.     public void main()
  140.     {
  141.         if (utils.ID == 0)
  142.         {
  143.             utils.save();
  144.         }
  145.     }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement