Advertisement
danik159

Untitled

Aug 1st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.05 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("1")) {
  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("Test dudes");
  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. Location blocklocation = Entitylocation.get(player);
  76. Block block = e.getBlock();
  77.  
  78. ItemStack dia = new ItemStack(Material.DIAMOND_BLOCK);
  79. ItemMeta diam = dia.getItemMeta();
  80. diam.setDisplayName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
  81. dia.setItemMeta(diam);
  82.  
  83. if (block.getType() == Material.GLASS) {
  84. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  85. en.remove();
  86. Entitylocation.remove(player);
  87. }
  88.  
  89. } else if (block.getType() == Material.DIAMOND_BLOCK) {
  90. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  91. if (en.getCustomName().equals(ChatColor.AQUA + "Diamond Blocks: " + pl.number)) {
  92. player.getInventory().addItem(dia);
  93. en.remove();
  94. e.setDropItems(false);
  95. Entitylocation.remove(player);
  96. }
  97.  
  98. }
  99.  
  100. }
  101.  
  102. }
  103. @SuppressWarnings("deprecation")
  104. @EventHandler
  105. public void onclick(PlayerInteractEvent e) {
  106. if (e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
  107. Player player = (Player) e.getPlayer();
  108. Block block = e.getClickedBlock();
  109. Material blockinhand = player.getItemInHand().getType();
  110. Location blocklocation = block.getLocation();
  111. if (e.getClickedBlock().getType().equals(Material.GLASS)) {
  112. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  113. if (en.getType().equals(EntityType.ARMOR_STAND)) {
  114. if (blockinhand.equals(Material.DIAMOND_BLOCK)) {
  115. block.setType(Material.DIAMOND_BLOCK);
  116. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  117. en.remove();
  118. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  119. stand.setVisible(false);
  120. stand.setGravity(false);
  121. stand.setGliding(false);
  122. stand.setInvulnerable(true);
  123. pl.number++;
  124. stand.setCustomName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
  125. stand.setCustomNameVisible(true);
  126. } else if (blockinhand.equals(Material.EMERALD_BLOCK)) {
  127. block.setType(Material.EMERALD_BLOCK);
  128. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  129. en.remove();
  130. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  131. stand.setVisible(false);
  132. stand.setGravity(false);
  133. stand.setGliding(false);
  134. stand.setInvulnerable(true);
  135. pl.number++;
  136. stand.setCustomName(ChatColor.GREEN + "Emerald Blocks: " + pl.number);
  137. stand.setCustomNameVisible(true);
  138. } else if (blockinhand.equals(Material.GOLD_BLOCK)) {
  139. block.setType(Material.GOLD_BLOCK);
  140. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  141. en.remove();
  142. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  143. stand.setVisible(false);
  144. stand.setGravity(false);
  145. stand.setGliding(false);
  146. stand.setInvulnerable(true);
  147. pl.number++;
  148. stand.setCustomName(ChatColor.GOLD + "Gold Blocks: " + pl.number);
  149. stand.setCustomNameVisible(true);
  150. } else if (blockinhand.equals(Material.IRON_BLOCK)) {
  151. block.setType(Material.IRON_BLOCK);
  152. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  153. en.remove();
  154. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  155. stand.setVisible(false);
  156. stand.setGravity(false);
  157. stand.setGliding(false);
  158. stand.setInvulnerable(true);
  159. pl.number++;
  160. stand.setCustomName(ChatColor.GRAY + "Iron Blocks: " + pl.number);
  161. stand.setCustomNameVisible(true);
  162. } else {
  163.  
  164. }
  165.  
  166. }
  167. }
  168. } else if (e.getClickedBlock().getType().equals(Material.DIAMOND_BLOCK)) {
  169. if (blockinhand.equals(Material.DIAMOND_BLOCK)) {
  170. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  171. if (en.getType().equals(EntityType.ARMOR_STAND)) {
  172. if (en.getCustomName().equals(ChatColor.AQUA + "Diamond Blocks: " + pl.number)) {
  173. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
  174. en.remove();
  175. ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  176. stand.setVisible(false);
  177. stand.setGravity(false);
  178. stand.setGliding(false);
  179. stand.setInvulnerable(true);
  180. pl.number++;
  181. stand.setCustomName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
  182. stand.setCustomNameVisible(true);
  183. }
  184. }
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement