Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chickenstyle.emptyblock;
- import java.util.HashMap;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.entity.ArmorStand;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockPlaceEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener{
- private Public_Number pl = new Public_Number();
- @Override
- public void onEnable(){
- Bukkit.getPluginManager().registerEvents(this, this);
- }
- HashMap<Player,Location> Entitylocation = new HashMap<>();
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onplace(BlockPlaceEvent e) {
- Player player = (Player) e.getPlayer();
- Block placedblock = e.getBlockPlaced();
- if (placedblock.getType() == Material.GLASS) {
- ItemMeta im = (ItemMeta) player.getItemInHand().getItemMeta();
- if (e.getItemInHand().hasItemMeta()){
- if (im.getDisplayName().equals("1")) {
- if (Entitylocation.containsKey(player)) {
- player.sendMessage(ChatColor.RED + "you cannot put 2 or more Block Containers!");
- player.sendMessage(ChatColor.RED + "please remove the other one!");
- e.setCancelled(true);
- } else {
- Entitylocation.put(player, placedblock.getLocation());
- ArmorStand holo = (ArmorStand) placedblock.getWorld().spawnEntity(placedblock.getLocation().add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
- holo.setVisible(false);
- holo.setInvulnerable(true);
- holo.setGravity(false);
- holo.setGliding(false);
- holo.setCustomNameVisible(true);
- holo.setCustomName("Test dudes");
- }
- } else {
- }
- } else {
- }
- } else if (placedblock.getType() == Material.DIAMOND_BLOCK) {
- if (e.getItemInHand().hasItemMeta()){
- if(e.getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.AQUA + "Diamond Blocks: ")) {
- }
- }
- }
- }
- @EventHandler
- public void onbreak(BlockBreakEvent e) {
- Player player = (Player) e.getPlayer();
- Location blocklocation = Entitylocation.get(player);
- Block block = e.getBlock();
- ItemStack dia = new ItemStack(Material.DIAMOND_BLOCK);
- ItemMeta diam = dia.getItemMeta();
- diam.setDisplayName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
- dia.setItemMeta(diam);
- if (block.getType() == Material.GLASS) {
- for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
- en.remove();
- Entitylocation.remove(player);
- }
- } else if (block.getType() == Material.DIAMOND_BLOCK) {
- for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
- if (en.getCustomName().equals(ChatColor.AQUA + "Diamond Blocks: " + pl.number)) {
- player.getInventory().addItem(dia);
- en.remove();
- e.setDropItems(false);
- Entitylocation.remove(player);
- }
- }
- }
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onclick(PlayerInteractEvent e) {
- if (e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
- Player player = (Player) e.getPlayer();
- Block block = e.getClickedBlock();
- Material blockinhand = player.getItemInHand().getType();
- Location blocklocation = block.getLocation();
- if (e.getClickedBlock().getType().equals(Material.GLASS)) {
- for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
- if (en.getType().equals(EntityType.ARMOR_STAND)) {
- if (blockinhand.equals(Material.DIAMOND_BLOCK)) {
- block.setType(Material.DIAMOND_BLOCK);
- player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
- en.remove();
- ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
- stand.setVisible(false);
- stand.setGravity(false);
- stand.setGliding(false);
- stand.setInvulnerable(true);
- pl.number++;
- stand.setCustomName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
- stand.setCustomNameVisible(true);
- } else if (blockinhand.equals(Material.EMERALD_BLOCK)) {
- block.setType(Material.EMERALD_BLOCK);
- player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
- en.remove();
- ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
- stand.setVisible(false);
- stand.setGravity(false);
- stand.setGliding(false);
- stand.setInvulnerable(true);
- pl.number++;
- stand.setCustomName(ChatColor.GREEN + "Emerald Blocks: " + pl.number);
- stand.setCustomNameVisible(true);
- } else if (blockinhand.equals(Material.GOLD_BLOCK)) {
- block.setType(Material.GOLD_BLOCK);
- player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
- en.remove();
- ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
- stand.setVisible(false);
- stand.setGravity(false);
- stand.setGliding(false);
- stand.setInvulnerable(true);
- pl.number++;
- stand.setCustomName(ChatColor.GOLD + "Gold Blocks: " + pl.number);
- stand.setCustomNameVisible(true);
- } else if (blockinhand.equals(Material.IRON_BLOCK)) {
- block.setType(Material.IRON_BLOCK);
- player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
- en.remove();
- ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
- stand.setVisible(false);
- stand.setGravity(false);
- stand.setGliding(false);
- stand.setInvulnerable(true);
- pl.number++;
- stand.setCustomName(ChatColor.GRAY + "Iron Blocks: " + pl.number);
- stand.setCustomNameVisible(true);
- } else {
- }
- }
- }
- } else if (e.getClickedBlock().getType().equals(Material.DIAMOND_BLOCK)) {
- if (blockinhand.equals(Material.DIAMOND_BLOCK)) {
- for (Entity en: blocklocation.getWorld().getNearbyEntities(blocklocation, 1, 1, 1)) {
- if (en.getType().equals(EntityType.ARMOR_STAND)) {
- if (en.getCustomName().equals(ChatColor.AQUA + "Diamond Blocks: " + pl.number)) {
- player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);
- en.remove();
- ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(blocklocation.add(0.5,-0.7,0.5), EntityType.ARMOR_STAND);
- stand.setVisible(false);
- stand.setGravity(false);
- stand.setGliding(false);
- stand.setInvulnerable(true);
- pl.number++;
- stand.setCustomName(ChatColor.AQUA + "Diamond Blocks: " + pl.number);
- stand.setCustomNameVisible(true);
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement