Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.com.devlucas.stackmobs;
- import org.bukkit.Material;
- import org.bukkit.block.CreatureSpawner;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.CreatureSpawnEvent;
- import org.bukkit.event.entity.EntityDeathEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.ItemStack;
- public class Stackar implements Listener {
- @EventHandler(priority = EventPriority.HIGHEST)
- public void aoNascer(CreatureSpawnEvent e) {
- if (e.getSpawnReason() != CreatureSpawnEvent.SpawnReason.SPAWNER) {
- e.setCancelled(false);
- return;
- }
- for (Entity en : e.getEntity().getNearbyEntities(10, 10, 10)) {
- if (en.getType() == e.getEntityType()) {
- e.getEntity().remove();
- int atual = 1;
- if (en.isCustomNameVisible()) {
- atual = Integer.parseInt(en.getCustomName().split(" ")[1].substring(1)) + 1;
- }
- en.setCustomName("§c" + en.getType() + " x" + atual);
- en.setCustomNameVisible(true);
- return;
- }
- }
- e.getEntity().setCustomName("§c" + e.getEntity().getType() + " x1");
- e.getEntity().setCustomNameVisible(true);
- }
- @EventHandler(priority = EventPriority.HIGHEST)
- public void aoMatar(EntityDeathEvent e) {
- LivingEntity en = e.getEntity();
- if (en.isCustomNameVisible()) {
- if (en.getCustomName().startsWith("§c" + e.getEntity().getType() + "§c x")) {
- int x = Integer.parseInt(en.getCustomName().split(" ")[1].substring(1));
- if (en.getKiller() instanceof Player) {
- Player p = en.getKiller();
- int plus = 1;
- if (p.getItemInHand().getEnchantments().containsKey(Enchantment.LOOT_BONUS_MOBS)) {
- plus = p.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS);
- }
- for (ItemStack is : e.getDrops()) {
- is.setAmount(is.getAmount() * plus * x);
- }
- } else {
- for (ItemStack is : e.getDrops()) {
- is.setAmount((is.getAmount()) * x);
- }
- }
- }
- }
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void aoInteragir(PlayerInteractEvent e) {
- if (e.getClickedBlock() == null) return;
- if (e.getItem() == null) return;
- if (e.getClickedBlock().getState() instanceof CreatureSpawner) {
- e.setCancelled(true);
- final CreatureSpawner cs = (CreatureSpawner) e.getClickedBlock().getState();
- if (e.getItem().getType() == Material.MONSTER_EGG) {
- cs.setSpawnedType(EntityType.fromId(e.getItem().getDurability()));
- cs.update(true);
- e.getPlayer().sendMessage("§cVocê alterou o spawner para " + cs.getSpawnedType());
- } else if (e.getItem().getType() == Material.DRAGON_EGG) {
- e.getPlayer().sendMessage("§aVelocidade atual: " + cs.getDelay());
- e.getItem().setAmount(e.getItem().getAmount() - 1);
- if (e.getItem().getAmount() == 0) {
- e.getPlayer().setItemInHand(null);
- }
- e.getPlayer().updateInventory();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement