Advertisement
Guest User

Untitled

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