From 0f06b5ff20bfe4f429e2301dc9cfb8b0e39df0e6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 3 Apr 2021 20:30:05 +0200 Subject: [PATCH] Fixing Rabbits --- .../lobby/listener/PlayerSeatListener.java | 2 +- .../lobby/listener/RabbitListener.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java index c59a54f..025e316 100644 --- a/src/de/steamwar/lobby/listener/PlayerSeatListener.java +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -111,7 +111,7 @@ public class PlayerSeatListener implements Listener { public void onEntityDismount(EntityDismountEvent event) { seats.remove(getSeatLocation(event.getDismounted().getLocation())); - if (event.getEntityType() == EntityType.ARROW) + if (event.getEntityType() != EntityType.ARROW) return; event.getDismounted().remove(); diff --git a/src/de/steamwar/lobby/listener/RabbitListener.java b/src/de/steamwar/lobby/listener/RabbitListener.java index 5031913..2a420a2 100644 --- a/src/de/steamwar/lobby/listener/RabbitListener.java +++ b/src/de/steamwar/lobby/listener/RabbitListener.java @@ -12,20 +12,18 @@ import org.bukkit.entity.Rabbit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.SkullMeta; import java.lang.reflect.Field; -import java.util.HashSet; -import java.util.Random; -import java.util.UUID; +import java.time.Instant; +import java.util.*; public class RabbitListener implements Listener { - private static final HashSet EGGS = new HashSet<>(); + private static final List EGGS = new ArrayList<>(); static { EGGS.add("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjkxYzQyYjE3MWZlZDZiZWE2ZmRmNGQ4NzJkNThiZDMzZDdjZTA5ZWVlZGRhMzZlNTQxNTFmODg5MDY2YmU0ZSJ9fX0="); @@ -42,7 +40,7 @@ public class RabbitListener implements Listener { public RabbitListener() { Bukkit.getPluginManager().registerEvents(this, LobbySystem.getInstance()); World world = Bukkit.getWorlds().get(0); - spreadRabbits(125, world); + spreadRabbits(250, world); Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> { Rabbit rabbit = world.getEntitiesByClass(Rabbit.class).iterator().next(); world.spawn(rabbit.getLocation(), Firework.class, firework -> { @@ -56,17 +54,21 @@ public class RabbitListener implements Listener { } public static void spreadRabbits(int count, World world) { + world.setAmbientSpawnLimit(count); + world.setAnimalSpawnLimit(count); + world.setMonsterSpawnLimit(count); Random rand = new Random(); int boundX = Config.BorderMaxX - Config.BorderMinX; int boundZ = Config.BorderMaxZ - Config.BorderMinZ; for (int i = 0; i < count; i++) { int relX = rand.nextInt(boundX); int relZ = rand.nextInt(boundZ); - Location loc = new Location(world, relX, 255, relZ); + Location loc = new Location(world, relX + Config.BorderMinX, 255, relZ + Config.BorderMinZ); world.spawn(loc, Rabbit.class, rabbit -> { rabbit.setRabbitType(Rabbit.Type.WHITE); rabbit.setInvulnerable(true); rabbit.setCustomName("§fOsterhase"); + rabbit.setPersistent(true); }); } } @@ -82,14 +84,14 @@ public class RabbitListener implements Listener { public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if(event.getRightClicked().getType() == EntityType.RABBIT) { Player p = event.getPlayer(); - event.getRightClicked().addPassenger(p); event.setCancelled(true); + event.getRightClicked().addPassenger(p); } } public static ItemStack getEggHead() { return getCustomTextureHead(new ItemStack(Material.PLAYER_HEAD), - EGGS.iterator().next()); + EGGS.get(Math.toIntExact(Instant.now().getEpochSecond() % EGGS.size()))); } private static ItemStack getCustomTextureHead(ItemStack head, String value) {