Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.chaotiic.heads.inventories.listeners;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.entity.ArmorStand;
- 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.player.PlayerInteractEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.scheduler.BukkitRunnable;
- import pl.chaotiic.heads.Main;
- import pl.chaotiic.heads.utils.ColorUtil;
- public class HeadsListener implements Listener {
- Main plugin;
- @EventHandler
- public void onPlayerInteract(PlayerInteractEvent event, World world, Location loc) {
- Player p = event.getPlayer();
- boolean czyGlowa = event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial() == (Material.SKULL);
- this.create(e.getEntity().getWorld(), e.getLocation());
- if (czyGlowa) {
- List<Material> przedmioty = Arrays.asList(Material.POTION, Material.POTION, Material.POTION,
- Material.POTION, Material.POTION, Material.POTION, Material.POTION, Material.POTION,
- Material.POTION, Material.POTION);
- Random rand = new Random();
- Material wylosowany = przedmioty.get(rand.nextInt(przedmioty.size()));
- ItemStack itemka = new ItemStack(wylosowany);
- ItemMeta itemMeta = itemka.getItemMeta();
- Material wylosowanyDWA = przedmioty.get(rand.nextInt(przedmioty.size()));
- ItemStack itemka2 = new ItemStack(wylosowanyDWA);
- ItemMeta itemMeta2 = itemka2.getItemMeta();
- itemka2.setItemMeta(itemMeta);
- String itemkaDisplayName2 = itemka2.getItemMeta().getDisplayName();
- if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("SILKA I"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("SILKA II"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("SZYBKOSC I"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("SZYBKOSC II"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("WYSOKIE SKAKANIE I"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("WYSOKIE SKAKANIE II"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("REGENERACJA I"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("REGENERACJA II"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("OCHRONA PRZED OGNIEM I"));
- } else if (wylosowany == Material.POTION) {
- itemMeta.setDisplayName(ColorUtil.fixColor(""));
- itemMeta2.setDisplayName(ColorUtil.fixColor("OCHRONA PRZED OGNIEM II"));
- }
- event.setCancelled(true);
- itemka.setItemMeta(itemMeta);
- String itemkaDisplayName = itemka.getItemMeta().getDisplayName();
- String playerDisplayName = p.getDisplayName();
- ItemStack doUsuniecia = new ItemStack(Material.SKULL, 1);
- ItemMeta GlowaMeta = doUsuniecia.getItemMeta();
- GlowaMeta.setDisplayName("");
- doUsuniecia.setItemMeta(GlowaMeta);
- p.getInventory().removeItem(doUsuniecia);
- this.addOrDrop(p, itemka);
- ArmorStand ent = (ArmorStand) p.getWorld().spawnEntity(p.getLocation().add(1, 2.5, 0),EntityType.ARMOR_STAND);
- Bukkit.broadcastMessage("&8ยป &7Gracz &5&n" + playerDisplayName + "&r &7glowe &e" + itemkaDisplayName2 + "");
- ent.setCustomName(ColorUtil.fixColor("&8ยป &7Wylosowano: &c&n" + itemkaDisplayName2 + ""));
- ent.setCustomNameVisible(true);
- ent.setVisible(true);
- ent.setGravity(false);
- ent.setHelmet(new ItemStack(Material.POTION));
- new BukkitRunnable() {
- @Override
- public void run() {
- ent.remove();
- }
- }.runTaskLater(this.plugin, 3 * 20);
- }
- }
- private void addOrDrop(Player p, ItemStack przedmiot) {
- HashMap<Integer, ItemStack> brakloMiejsca = p.getInventory().addItem(przedmiot);
- World w = p.getWorld();
- Location loc = p.getLocation();
- for (ItemStack zostalo : brakloMiejsca.values()) {
- w.dropItem(loc, zostalo);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement