danik159

Untitled

Jul 28th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 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.BlockBreakEvent;
  17. import org.bukkit.event.block.BlockPlaceEvent;
  18. import org.bukkit.inventory.meta.ItemMeta;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20.  
  21. public class Main extends JavaPlugin implements Listener{
  22. public void onEnable(){
  23. Bukkit.getPluginManager().registerEvents(this, this);
  24. }
  25. HashMap<Player,Location> Entitylocation = new HashMap<>();
  26. @SuppressWarnings("deprecation")
  27. @EventHandler
  28. public void onplace(BlockPlaceEvent e) {
  29. Player player = (Player) e.getPlayer();
  30. Block placedblock = e.getBlockPlaced();
  31. if (placedblock.getType() == Material.GLASS) {
  32. ItemMeta im = (ItemMeta) player.getItemInHand().getItemMeta();
  33. if (e.getItemInHand().hasItemMeta()){
  34. if (im.getDisplayName().equals("1")) {
  35. if (Entitylocation.containsKey(player)) {
  36. player.sendMessage(ChatColor.RED + "you cannot put 2 or more Block Containers!");
  37. player.sendMessage(ChatColor.RED + "please remove the other 1 at: X: " + placedblock.getLocation().getBlockX() + " Y: " + placedblock.getLocation().getBlockY() + " Z: " + placedblock.getLocation().getBlockZ());
  38. e.setCancelled(true);
  39. } else {
  40. ArmorStand holo = (ArmorStand) placedblock.getWorld().spawnEntity(placedblock.getLocation().add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
  41. Entitylocation.put(player, placedblock.getLocation());
  42. holo.setVisible(false);
  43. holo.setInvulnerable(true);
  44. holo.setGravity(false);
  45. holo.setGliding(false);
  46. holo.setCustomNameVisible(true);
  47. holo.setCustomName("Test dudes");
  48.  
  49. }
  50. } else {
  51.  
  52. }
  53. }
  54. }
  55. }
  56. @EventHandler
  57. public void onplace(BlockBreakEvent e) {
  58. Player player = (Player) e.getPlayer();
  59. Location blocklocation = Entitylocation.get(player);
  60. Block block = e.getBlock();
  61. if (block.getType() == Material.GLASS) {
  62. for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
  63. en.remove();
  64. Entitylocation.remove(player);
  65. }
  66.  
  67. } else {
  68.  
  69. }
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment