From 38f826dede81d28c6e5d5e7f23808f17013ea4a6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 2 Apr 2021 18:24:30 +0200 Subject: [PATCH 1/3] Kapito? Rabbito! --- src/de/steamwar/lobby/LobbySystem.java | 2 + .../listener/PlayerConnectionListener.java | 1 + .../lobby/listener/PlayerSeatListener.java | 6 +- .../lobby/listener/RabbitListener.java | 98 +++++++++++++++++++ 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/de/steamwar/lobby/listener/RabbitListener.java diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 1bdab28..736fb9f 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -44,6 +44,8 @@ public class LobbySystem extends JavaPlugin { pm.registerEvents(new EnderPearlListener(), instance); getCommand("fly").setExecutor(new FlyCommand()); + + new RabbitListener(); } diff --git a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java index ab66243..57d1abe 100644 --- a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java +++ b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java @@ -46,6 +46,7 @@ public class PlayerConnectionListener implements Listener { player.teleport(new Location(Bukkit.getWorlds().get(0), Config.SpawnX, Config.SpawnY, Config.SpawnZ, Config.Yaw, Config.Pitch)); player.getInventory().clear(); LobbyInventory.givePlayerLobbyItems(player); + player.getInventory().setHelmet(RabbitListener.EGG_HEAD); player.setGameMode(GameMode.ADVENTURE); player.setHealth(20); player.setFoodLevel(20); diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java index a0ac093..c59a54f 100644 --- a/src/de/steamwar/lobby/listener/PlayerSeatListener.java +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -88,7 +88,7 @@ public class PlayerSeatListener implements Listener { if (((Stairs) event.getClickedBlock().getBlockData()).getShape() != Stairs.Shape.STRAIGHT) return; - if (event.getPlayer().isInsideVehicle()) + if (event.getPlayer().isInsideVehicle() && event.getPlayer().getVehicle().getType() == EntityType.ARROW) event.getPlayer().getVehicle().remove(); if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR) @@ -111,7 +111,7 @@ public class PlayerSeatListener implements Listener { public void onEntityDismount(EntityDismountEvent event) { seats.remove(getSeatLocation(event.getDismounted().getLocation())); - if (event.getEntityType() != EntityType.PLAYER) + if (event.getEntityType() == EntityType.ARROW) return; event.getDismounted().remove(); @@ -119,7 +119,7 @@ public class PlayerSeatListener implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - if (event.getPlayer().isInsideVehicle()) + if (event.getPlayer().isInsideVehicle() && event.getPlayer().getVehicle().getType() == EntityType.ARROW) event.getPlayer().getVehicle().remove(); } diff --git a/src/de/steamwar/lobby/listener/RabbitListener.java b/src/de/steamwar/lobby/listener/RabbitListener.java new file mode 100644 index 0000000..2ddf99a --- /dev/null +++ b/src/de/steamwar/lobby/listener/RabbitListener.java @@ -0,0 +1,98 @@ +package de.steamwar.lobby.listener; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.utils.Config; +import org.bukkit.*; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; +import org.bukkit.entity.Player; +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.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerJoinEvent; +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.Random; +import java.util.UUID; + +public class RabbitListener implements Listener { + + public static final ItemStack EGG_HEAD; + + static { + EGG_HEAD = getCustomTextureHead(new ItemStack(Material.PLAYER_HEAD), + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjkxYzQyYjE3MWZlZDZiZWE2ZmRmNGQ4NzJkNThiZDMzZDdjZTA5ZWVlZGRhMzZlNTQxNTFmODg5MDY2YmU0ZSJ9fX0="); + } + + public RabbitListener() { + Bukkit.getPluginManager().registerEvents(this, LobbySystem.getInstance()); + World world = Bukkit.getWorlds().get(0); + spreadRabbits(50, world); + Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> { + Rabbit rabbit = world.getEntitiesByClass(Rabbit.class).iterator().next(); + world.spawn(rabbit.getLocation(), Firework.class, firework -> { + FireworkMeta meta = firework.getFireworkMeta(); + meta.clearEffects(); + meta.addEffects(FireworkEffect.builder().with(FireworkEffect.Type.BURST).trail(true).withColor(Color.WHITE).build()); + meta.setPower(1); + firework.setFireworkMeta(meta); + }); + }, 60*20, 60*20); + } + + public static void spreadRabbits(int count, World world) { + 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); + world.spawn(loc, Rabbit.class, rabbit -> { + rabbit.setRabbitType(Rabbit.Type.WHITE); + rabbit.setInvulnerable(true); + rabbit.setCustomName("§fOsterhase"); + }); + } + } + + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + if(event.getEntityType() == EntityType.RABBIT) { + event.setCancelled(true); + } + } + + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if(event.getRightClicked().getType() == EntityType.RABBIT) { + Player p = event.getPlayer(); + event.getRightClicked().addPassenger(p); + event.setCancelled(true); + } + } + + public static ItemStack getCustomTextureHead(ItemStack head, String value) { + SkullMeta meta = (SkullMeta) head.getItemMeta(); + meta.setDisplayName("§eEierkopf"); + GameProfile profile = new GameProfile(UUID.randomUUID(), ""); + profile.getProperties().put("textures", new Property("textures", value)); + Field profileField = null; + try { + profileField = meta.getClass().getDeclaredField("profile"); + profileField.setAccessible(true); + profileField.set(meta, profile); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { + e.printStackTrace(); + } + head.setItemMeta(meta); + return head; + } +} -- 2.39.5 From a652a8f83ecbf2351e40419b4b543318dfb3ba04 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 3 Apr 2021 15:09:11 +0200 Subject: [PATCH 2/3] Adding more Eggs and more Rabbits --- .../listener/PlayerConnectionListener.java | 2 +- .../lobby/listener/RabbitListener.java | 25 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java index 57d1abe..9cbe282 100644 --- a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java +++ b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java @@ -46,7 +46,7 @@ public class PlayerConnectionListener implements Listener { player.teleport(new Location(Bukkit.getWorlds().get(0), Config.SpawnX, Config.SpawnY, Config.SpawnZ, Config.Yaw, Config.Pitch)); player.getInventory().clear(); LobbyInventory.givePlayerLobbyItems(player); - player.getInventory().setHelmet(RabbitListener.EGG_HEAD); + player.getInventory().setHelmet(RabbitListener.getEggHead()); player.setGameMode(GameMode.ADVENTURE); player.setHealth(20); player.setFoodLevel(20); diff --git a/src/de/steamwar/lobby/listener/RabbitListener.java b/src/de/steamwar/lobby/listener/RabbitListener.java index 2ddf99a..5031913 100644 --- a/src/de/steamwar/lobby/listener/RabbitListener.java +++ b/src/de/steamwar/lobby/listener/RabbitListener.java @@ -12,29 +12,37 @@ 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.event.player.PlayerJoinEvent; 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; public class RabbitListener implements Listener { - public static final ItemStack EGG_HEAD; + private static final HashSet EGGS = new HashSet<>(); static { - EGG_HEAD = getCustomTextureHead(new ItemStack(Material.PLAYER_HEAD), - "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjkxYzQyYjE3MWZlZDZiZWE2ZmRmNGQ4NzJkNThiZDMzZDdjZTA5ZWVlZGRhMzZlNTQxNTFmODg5MDY2YmU0ZSJ9fX0="); + EGGS.add("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjkxYzQyYjE3MWZlZDZiZWE2ZmRmNGQ4NzJkNThiZDMzZDdjZTA5ZWVlZGRhMzZlNTQxNTFmODg5MDY2YmU0ZSJ9fX0="); + EGGS.add("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTMwNGJkMzE2MTFmODYzYTZiMDFlNmUzZjVhN2MwOWQwYWU1YzA3YTA5NDEyZmNhYTMxYmM1Mzc2OGYzYjI4OSJ9fX0="); + EGGS.add("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWIyY2VkNGU1NjYwNWFiZDJhNjA4YjZkNzE1MDE2NzhjNjBjNTcyMjYwNGZlYWE3MjEwNjc2OWIwZDNhYzc1OSJ9fX0="); + EGGS.add("eyJ0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ZGRjZTJjNTU2ZjIyZmRhMzE3OTc4MzlmZmQxZDA0MjhhZmUxMmE0NWMwNzM1NTk1MWY0NDRjNzc0YWQifX19"); } public RabbitListener() { Bukkit.getPluginManager().registerEvents(this, LobbySystem.getInstance()); World world = Bukkit.getWorlds().get(0); - spreadRabbits(50, world); + spreadRabbits(125, world); Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> { Rabbit rabbit = world.getEntitiesByClass(Rabbit.class).iterator().next(); world.spawn(rabbit.getLocation(), Firework.class, firework -> { @@ -79,7 +87,12 @@ public class RabbitListener implements Listener { } } - public static ItemStack getCustomTextureHead(ItemStack head, String value) { + public static ItemStack getEggHead() { + return getCustomTextureHead(new ItemStack(Material.PLAYER_HEAD), + EGGS.iterator().next()); + } + + private static ItemStack getCustomTextureHead(ItemStack head, String value) { SkullMeta meta = (SkullMeta) head.getItemMeta(); meta.setDisplayName("§eEierkopf"); GameProfile profile = new GameProfile(UUID.randomUUID(), ""); -- 2.39.5 From 0f06b5ff20bfe4f429e2301dc9cfb8b0e39df0e6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 3 Apr 2021 20:30:05 +0200 Subject: [PATCH 3/3] 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) { -- 2.39.5