Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. package pl.chaotiic.heads.inventories.listeners;
  2.  
  3. import java.util.Arrays;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Random;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.Location;
  10. import org.bukkit.Material;
  11. import org.bukkit.World;
  12. import org.bukkit.entity.ArmorStand;
  13. import org.bukkit.entity.EntityType;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.event.EventHandler;
  16. import org.bukkit.event.Listener;
  17. import org.bukkit.event.block.Action;
  18. import org.bukkit.event.player.PlayerInteractEvent;
  19. import org.bukkit.inventory.ItemStack;
  20. import org.bukkit.inventory.meta.ItemMeta;
  21. import org.bukkit.scheduler.BukkitRunnable;
  22.  
  23. import pl.chaotiic.heads.Main;
  24. import pl.chaotiic.heads.utils.ColorUtil;
  25.  
  26. public class HeadsListener implements Listener {
  27. Main plugin;
  28.  
  29. @EventHandler
  30. public void onPlayerInteract(PlayerInteractEvent event, World world, Location loc) {
  31. Player p = event.getPlayer();
  32. boolean czyGlowa = event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial() == (Material.SKULL);
  33. this.create(e.getEntity().getWorld(), e.getLocation());
  34. if (czyGlowa) {
  35.  
  36. List<Material> przedmioty = Arrays.asList(Material.POTION, Material.POTION, Material.POTION,
  37. Material.POTION, Material.POTION, Material.POTION, Material.POTION, Material.POTION,
  38. Material.POTION, Material.POTION);
  39. Random rand = new Random();
  40. Material wylosowany = przedmioty.get(rand.nextInt(przedmioty.size()));
  41. ItemStack itemka = new ItemStack(wylosowany);
  42. ItemMeta itemMeta = itemka.getItemMeta();
  43. Material wylosowanyDWA = przedmioty.get(rand.nextInt(przedmioty.size()));
  44. ItemStack itemka2 = new ItemStack(wylosowanyDWA);
  45. ItemMeta itemMeta2 = itemka2.getItemMeta();
  46. itemka2.setItemMeta(itemMeta);
  47. String itemkaDisplayName2 = itemka2.getItemMeta().getDisplayName();
  48.  
  49. if (wylosowany == Material.POTION) {
  50. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  51. itemMeta2.setDisplayName(ColorUtil.fixColor("SILKA I"));
  52. } else if (wylosowany == Material.POTION) {
  53. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  54. itemMeta2.setDisplayName(ColorUtil.fixColor("SILKA II"));
  55. } else if (wylosowany == Material.POTION) {
  56. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  57. itemMeta2.setDisplayName(ColorUtil.fixColor("SZYBKOSC I"));
  58. } else if (wylosowany == Material.POTION) {
  59. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  60. itemMeta2.setDisplayName(ColorUtil.fixColor("SZYBKOSC II"));
  61. } else if (wylosowany == Material.POTION) {
  62. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  63. itemMeta2.setDisplayName(ColorUtil.fixColor("WYSOKIE SKAKANIE I"));
  64. } else if (wylosowany == Material.POTION) {
  65. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  66. itemMeta2.setDisplayName(ColorUtil.fixColor("WYSOKIE SKAKANIE II"));
  67. } else if (wylosowany == Material.POTION) {
  68. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  69. itemMeta2.setDisplayName(ColorUtil.fixColor("REGENERACJA I"));
  70. } else if (wylosowany == Material.POTION) {
  71. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  72. itemMeta2.setDisplayName(ColorUtil.fixColor("REGENERACJA II"));
  73. } else if (wylosowany == Material.POTION) {
  74. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  75. itemMeta2.setDisplayName(ColorUtil.fixColor("OCHRONA PRZED OGNIEM I"));
  76. } else if (wylosowany == Material.POTION) {
  77. itemMeta.setDisplayName(ColorUtil.fixColor(""));
  78. itemMeta2.setDisplayName(ColorUtil.fixColor("OCHRONA PRZED OGNIEM II"));
  79. }
  80. event.setCancelled(true);
  81.  
  82. itemka.setItemMeta(itemMeta);
  83.  
  84. String itemkaDisplayName = itemka.getItemMeta().getDisplayName();
  85. String playerDisplayName = p.getDisplayName();
  86.  
  87. ItemStack doUsuniecia = new ItemStack(Material.SKULL, 1);
  88.  
  89. ItemMeta GlowaMeta = doUsuniecia.getItemMeta();
  90. GlowaMeta.setDisplayName("");
  91. doUsuniecia.setItemMeta(GlowaMeta);
  92.  
  93. p.getInventory().removeItem(doUsuniecia);
  94. this.addOrDrop(p, itemka);
  95. ArmorStand ent = (ArmorStand) p.getWorld().spawnEntity(p.getLocation().add(1, 2.5, 0),EntityType.ARMOR_STAND);
  96. Bukkit.broadcastMessage("&8ยป &7Gracz &5&n" + playerDisplayName + "&r &7glowe &e" + itemkaDisplayName2 + "");
  97. ent.setCustomName(ColorUtil.fixColor("&8ยป &7Wylosowano: &c&n" + itemkaDisplayName2 + ""));
  98. ent.setCustomNameVisible(true);
  99. ent.setVisible(true);
  100. ent.setGravity(false);
  101. ent.setHelmet(new ItemStack(Material.POTION));
  102.  
  103. new BukkitRunnable() {
  104. @Override
  105. public void run() {
  106. ent.remove();
  107. }
  108. }.runTaskLater(this.plugin, 3 * 20);
  109. }
  110. }
  111.  
  112. private void addOrDrop(Player p, ItemStack przedmiot) {
  113. HashMap<Integer, ItemStack> brakloMiejsca = p.getInventory().addItem(przedmiot);
  114.  
  115. World w = p.getWorld();
  116. Location loc = p.getLocation();
  117. for (ItemStack zostalo : brakloMiejsca.values()) {
  118. w.dropItem(loc, zostalo);
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement