Advertisement
danik159

Untitled

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