danik159

Untitled

Aug 1st, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.50 KB | None | 0 0
  1. package com.chickenstyle.emptyblock;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.block.Block;
  10. import org.bukkit.entity.ArmorStand;
  11. import org.bukkit.entity.Entity;
  12. import org.bukkit.entity.EntityType;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.Action;
  17. import org.bukkit.event.block.BlockBreakEvent;
  18. import org.bukkit.event.block.BlockPlaceEvent;
  19. import org.bukkit.event.player.PlayerInteractEvent;
  20. import org.bukkit.inventory.ItemStack;
  21. import org.bukkit.inventory.ShapedRecipe;
  22. import org.bukkit.inventory.meta.ItemMeta;
  23. import org.bukkit.plugin.java.JavaPlugin;
  24.  
  25.  
  26. public class Main extends JavaPlugin implements Listener{
  27. private Public_Number pl = new Public_Number();
  28. @SuppressWarnings("deprecation")
  29. @Override
  30. public void onEnable(){
  31. Bukkit.getPluginManager().registerEvents(this, this);
  32.  
  33.  
  34. ItemStack container = new ItemStack(Material.GLASS);
  35. ItemMeta meta = container.getItemMeta();
  36. meta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Block Container");
  37. container.setItemMeta(meta);
  38.  
  39.  
  40. ShapedRecipe c = new ShapedRecipe(container);
  41. c.shape("$$$", "$@$", "$$$");
  42. c.setIngredient('@', Material.BEACON);
  43. c.setIngredient('$', Material.GLASS);
  44. getServer().addRecipe(c);
  45.  
  46.  
  47.  
  48.  
  49. }
  50. HashMap<Player,Location> Entitylocation = new HashMap<>();
  51. @SuppressWarnings("deprecation")
  52. @EventHandler
  53. public void onplace(BlockPlaceEvent e) {
  54. Player player = (Player) e.getPlayer();
  55. Block placedblock = e.getBlockPlaced();
  56. if (placedblock.getType() == Material.GLASS) {
  57. ItemMeta im = (ItemMeta) player.getItemInHand().getItemMeta();
  58. if (e.getItemInHand().hasItemMeta()){
  59. if (im.getDisplayName().equals(ChatColor.GOLD + "" + ChatColor.BOLD + "Block Container")) {
  60. if (Entitylocation.containsKey(player)) {
  61. player.sendMessage(ChatColor.RED + "you cannot put 2 or more Block Containers!");
  62. player.sendMessage(ChatColor.RED + "please remove the other one!");
  63. e.setCancelled(true);
  64. } else {
  65. Entitylocation.put(player, placedblock.getLocation());
  66. ArmorStand holo = (ArmorStand) placedblock.getWorld().spawnEntity(placedblock.getLocation().add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  67. holo.setVisible(false);
  68. holo.setInvulnerable(true);
  69. holo.setGravity(false);
  70. holo.setGliding(false);
  71. holo.setCustomNameVisible(true);
  72. holo.setCustomName(ChatColor.GOLD + "" + ChatColor.BOLD + "Block Container");
  73.  
  74. }
  75. } else {
  76.  
  77. }
  78. } else {
  79.  
  80. }
  81. } else if (placedblock.getType() == Material.DIAMOND_BLOCK) {
  82. if (e.getItemInHand().hasItemMeta()){
  83. if(e.getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.AQUA + "Diamond Blocks: ")) {
  84.  
  85. }
  86.  
  87. }
  88. }
  89. }
  90.  
  91. @EventHandler
  92. public void onbreak(BlockBreakEvent e) {
  93. Player player = (Player) e.getPlayer();
  94. Block block = e.getBlock();
  95. Location blocklocation = Entitylocation.get(player);
  96. Location blockl = block.getLocation();
  97.  
  98. ItemStack dia = new ItemStack(Material.DIAMOND_BLOCK);
  99. ItemStack diaall = new ItemStack(Material.DIAMOND_BLOCK, pl.number - 1);
  100.  
  101. ItemStack eme = new ItemStack(Material.EMERALD_BLOCK);
  102. ItemStack emeall = new ItemStack(Material.EMERALD_BLOCK, pl.number - 1);
  103.  
  104. ItemStack iro = new ItemStack(Material.IRON_BLOCK);
  105. ItemStack iroall = new ItemStack(Material.IRON_BLOCK, pl.number - 1);
  106.  
  107. ItemStack gol = new ItemStack(Material.GOLD_BLOCK);
  108. ItemStack golall = new ItemStack(Material.GOLD_BLOCK, pl.number - 1);
  109.  
  110. ItemStack container = new ItemStack(Material.GLASS);
  111. ItemMeta meta = container.getItemMeta();
  112. meta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Block Container");
  113. container.setItemMeta(meta);
  114.  
  115. if (block.getType() == Material.GLASS) {
  116. if (block.getLocation().getBlock().getWorld().getNearbyEntities(blocklocation, 1, 1, 1).isEmpty()) {
  117.  
  118. } else {
  119. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  120. en.remove();
  121. Entitylocation.remove(player);
  122. player.getInventory().addItem(container);
  123. }
  124. }
  125.  
  126. } else if (block.getType() == Material.DIAMOND_BLOCK) {
  127. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  128. if (en.getCustomName().equals(ChatColor.AQUA + "Diamond Blocks: " + pl.number)) {
  129. if(player.isSneaking() == true) {
  130. player.getInventory().addItem(diaall);
  131. player.getInventory().addItem(container);
  132. en.remove();
  133. pl.number = 0;
  134. e.getBlock().getDrops().clear();
  135. Entitylocation.remove(player);
  136. } else {
  137. if (pl.number == 1) {
  138. pl.number--;
  139. en.remove();
  140. player.getInventory().addItem(container);
  141. Entitylocation.remove(player);
  142. } else {
  143. player.getInventory().addItem(dia);
  144. en.remove();
  145. e.setCancelled(true);
  146. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blockl.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  147. stand.setVisible(false);
  148. stand.setGravity(false);
  149. stand.setGliding(false);
  150. stand.setInvulnerable(true);
  151. pl.number--;
  152. stand.setCustomName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
  153. stand.setCustomNameVisible(true);
  154. }
  155. }
  156. }
  157.  
  158. }
  159.  
  160. } else if (block.getType() == Material.EMERALD_BLOCK) {
  161. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  162. if (en.getCustomName().equals(ChatColor.GREEN + "Emerald Blocks: " + pl.number)) {
  163. if(player.isSneaking() == true) {
  164. player.getInventory().addItem(emeall);
  165. en.remove();
  166. pl.number = 0;
  167. player.getInventory().addItem(container);
  168. e.getBlock().getDrops().clear();
  169. Entitylocation.remove(player);
  170. } else {
  171. if (pl.number == 1) {
  172. pl.number--;
  173. en.remove();
  174. Entitylocation.remove(player);
  175. player.getInventory().addItem(container);
  176. } else {
  177. player.getInventory().addItem(eme);
  178. en.remove();
  179. e.setCancelled(true);
  180. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blockl.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  181. stand.setVisible(false);
  182. stand.setGravity(false);
  183. stand.setGliding(false);
  184. stand.setInvulnerable(true);
  185. pl.number--;
  186. stand.setCustomName(ChatColor.GREEN + "Emerald Blocks: " + pl.number);
  187. stand.setCustomNameVisible(true);
  188. }
  189. }
  190. }
  191.  
  192. }
  193. } else if (block.getType() == Material.IRON_BLOCK) {
  194. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  195. if (en.getCustomName().equals(ChatColor.GRAY + "Iron Blocks: " + pl.number)) {
  196. if(player.isSneaking() == true) {
  197. player.getInventory().addItem(iroall);
  198. en.remove();
  199. player.getInventory().addItem(container);
  200. pl.number = 0;
  201. e.getBlock().getDrops().clear();
  202. Entitylocation.remove(player);
  203. } else {
  204. if (pl.number == 1) {
  205. pl.number--;
  206. en.remove();
  207. player.getInventory().addItem(container);
  208. Entitylocation.remove(player);
  209. } else {
  210. player.getInventory().addItem(iro);
  211. en.remove();
  212. e.setCancelled(true);
  213. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blockl.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  214. stand.setVisible(false);
  215. stand.setGravity(false);
  216. stand.setGliding(false);
  217. stand.setInvulnerable(true);
  218. pl.number--;
  219. stand.setCustomName(ChatColor.GRAY + "Iron Blocks: " + pl.number);
  220. stand.setCustomNameVisible(true);
  221. }
  222. }
  223. }
  224.  
  225. }
  226. } else if (block.getType() == Material.GOLD_BLOCK) {
  227. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  228. if (en.getCustomName().equals(ChatColor.GOLD + "Gold Blocks: " + pl.number)) {
  229. if(player.isSneaking() == true) {
  230. player.getInventory().addItem(golall);
  231. en.remove();
  232. pl.number = 0;
  233. player.getInventory().addItem(container);
  234. e.getBlock().getDrops().clear();
  235. Entitylocation.remove(player);
  236. } else {
  237. if (pl.number == 1) {
  238. pl.number--;
  239. en.remove();
  240. player.getInventory().addItem(container);
  241. Entitylocation.remove(player);
  242. } else {
  243. player.getInventory().addItem(gol);
  244. en.remove();
  245. e.setCancelled(true);
  246. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blockl.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  247. stand.setVisible(false);
  248. stand.setGravity(false);
  249. stand.setGliding(false);
  250. stand.setInvulnerable(true);
  251. pl.number--;
  252. stand.setCustomName(ChatColor.GOLD + "Gold Blocks: " + pl.number);
  253. stand.setCustomNameVisible(true);
  254. }
  255. }
  256. }
  257.  
  258. }
  259. }
  260.  
  261. }
  262. @SuppressWarnings("deprecation")
  263. @EventHandler
  264. public void onclick(PlayerInteractEvent e) {
  265. if (e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
  266. Player player = (Player) e.getPlayer();
  267. Block block = e.getClickedBlock();
  268. Material blockinhand = player.getItemInHand().getType();
  269. Location blocklocation = block.getLocation();
  270. if (e.getClickedBlock().getType().equals(Material.GLASS)) {
  271. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  272. if (en.getType().equals(EntityType.ARMOR_STAND)) {
  273. if (blockinhand.equals(Material.DIAMOND_BLOCK)) {
  274. block.setType(Material.DIAMOND_BLOCK);
  275. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  276. en.remove();
  277. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  278. stand.setVisible(false);
  279. stand.setGravity(false);
  280. stand.setGliding(false);
  281. stand.setInvulnerable(true);
  282. pl.number++;
  283. stand.setCustomName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
  284. stand.setCustomNameVisible(true);
  285. } else if (blockinhand.equals(Material.EMERALD_BLOCK)) {
  286. block.setType(Material.EMERALD_BLOCK);
  287. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  288. en.remove();
  289. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  290. stand.setVisible(false);
  291. stand.setGravity(false);
  292. stand.setGliding(false);
  293. stand.setInvulnerable(true);
  294. pl.number++;
  295. stand.setCustomName(ChatColor.GREEN + "Emerald Blocks: " + pl.number);
  296. stand.setCustomNameVisible(true);
  297. } else if (blockinhand.equals(Material.GOLD_BLOCK)) {
  298. block.setType(Material.GOLD_BLOCK);
  299. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  300. en.remove();
  301. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  302. stand.setVisible(false);
  303. stand.setGravity(false);
  304. stand.setGliding(false);
  305. stand.setInvulnerable(true);
  306. pl.number++;
  307. stand.setCustomName(ChatColor.GOLD + "Gold Blocks: " + pl.number);
  308. stand.setCustomNameVisible(true);
  309. } else if (blockinhand.equals(Material.IRON_BLOCK)) {
  310. block.setType(Material.IRON_BLOCK);
  311. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  312. en.remove();
  313. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  314. stand.setVisible(false);
  315. stand.setGravity(false);
  316. stand.setGliding(false);
  317. stand.setInvulnerable(true);
  318. pl.number++;
  319. stand.setCustomName(ChatColor.GRAY + "Iron Blocks: " + pl.number);
  320. stand.setCustomNameVisible(true);
  321. } else {
  322.  
  323. }
  324.  
  325. }
  326. }
  327. } else if (e.getClickedBlock().getType().equals(Material.DIAMOND_BLOCK)) {
  328. if (blockinhand.equals(Material.DIAMOND_BLOCK)) {
  329. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  330. if (en.getType().equals(EntityType.ARMOR_STAND)) {
  331. if (en.getCustomName().equals(ChatColor.AQUA + "Diamond Blocks: " + pl.number)) {
  332. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  333. en.remove();
  334. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  335. stand.setVisible(false);
  336. stand.setGravity(false);
  337. stand.setGliding(false);
  338. stand.setInvulnerable(true);
  339. pl.number++;
  340. stand.setCustomName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
  341. stand.setCustomNameVisible(true);
  342. }
  343. }
  344. }
  345. }
  346. } else if (e.getClickedBlock().getType().equals(Material.EMERALD_BLOCK)) {
  347. if (blockinhand.equals(Material.EMERALD_BLOCK)) {
  348. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  349. if (en.getType().equals(EntityType.ARMOR_STAND)) {
  350. if (en.getCustomName().equals(ChatColor.GREEN + "Emerald Blocks: " + pl.number)) {
  351. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  352. en.remove();
  353. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  354. stand.setVisible(false);
  355. stand.setGravity(false);
  356. stand.setGliding(false);
  357. stand.setInvulnerable(true);
  358. pl.number++;
  359. stand.setCustomName(ChatColor.GREEN + "Emerald Blocks: " + pl.number);
  360. stand.setCustomNameVisible(true);
  361. }
  362. }
  363. }
  364. }
  365. } else if (e.getClickedBlock().getType().equals(Material.GOLD_BLOCK)) {
  366. if (blockinhand.equals(Material.GOLD_BLOCK)) {
  367. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  368. if (en.getType().equals(EntityType.ARMOR_STAND)) {
  369. if (en.getCustomName().equals(ChatColor.GOLD + "Gold Blocks: " + pl.number)) {
  370. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  371. en.remove();
  372. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  373. stand.setVisible(false);
  374. stand.setGravity(false);
  375. stand.setGliding(false);
  376. stand.setInvulnerable(true);
  377. pl.number++;
  378. stand.setCustomName(ChatColor.GOLD + "Gold Blocks: " + pl.number);
  379. stand.setCustomNameVisible(true);
  380. }
  381. }
  382. }
  383. }
  384. } else if (e.getClickedBlock().getType().equals(Material.IRON_BLOCK)) {
  385. if (blockinhand.equals(Material.IRON_BLOCK)) {
  386. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  387. if (en.getType().equals(EntityType.ARMOR_STAND)) {
  388. if (en.getCustomName().equals(ChatColor.GRAY + "Iron Blocks: " + pl.number)) {
  389. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  390. en.remove();
  391. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  392. stand.setVisible(false);
  393. stand.setGravity(false);
  394. stand.setGliding(false);
  395. stand.setInvulnerable(true);
  396. pl.number++;
  397. stand.setCustomName(ChatColor.GRAY + "Iron Blocks: " + pl.number);
  398. stand.setCustomNameVisible(true);
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
Advertisement
Add Comment
Please, Sign In to add comment