Archiviert
13
0

Kapito? Rabbito!

Dieser Commit ist enthalten in:
Chaoscaot 2021-04-02 18:24:30 +02:00
Ursprung 0ddb33b06b
Commit 38f826dede
4 geänderte Dateien mit 104 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -44,6 +44,8 @@ public class LobbySystem extends JavaPlugin {
pm.registerEvents(new EnderPearlListener(), instance); pm.registerEvents(new EnderPearlListener(), instance);
getCommand("fly").setExecutor(new FlyCommand()); getCommand("fly").setExecutor(new FlyCommand());
new RabbitListener();
} }

Datei anzeigen

@ -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.teleport(new Location(Bukkit.getWorlds().get(0), Config.SpawnX, Config.SpawnY, Config.SpawnZ, Config.Yaw, Config.Pitch));
player.getInventory().clear(); player.getInventory().clear();
LobbyInventory.givePlayerLobbyItems(player); LobbyInventory.givePlayerLobbyItems(player);
player.getInventory().setHelmet(RabbitListener.EGG_HEAD);
player.setGameMode(GameMode.ADVENTURE); player.setGameMode(GameMode.ADVENTURE);
player.setHealth(20); player.setHealth(20);
player.setFoodLevel(20); player.setFoodLevel(20);

Datei anzeigen

@ -88,7 +88,7 @@ public class PlayerSeatListener implements Listener {
if (((Stairs) event.getClickedBlock().getBlockData()).getShape() != Stairs.Shape.STRAIGHT) if (((Stairs) event.getClickedBlock().getBlockData()).getShape() != Stairs.Shape.STRAIGHT)
return; return;
if (event.getPlayer().isInsideVehicle()) if (event.getPlayer().isInsideVehicle() && event.getPlayer().getVehicle().getType() == EntityType.ARROW)
event.getPlayer().getVehicle().remove(); event.getPlayer().getVehicle().remove();
if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR) if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR)
@ -111,7 +111,7 @@ public class PlayerSeatListener implements Listener {
public void onEntityDismount(EntityDismountEvent event) { public void onEntityDismount(EntityDismountEvent event) {
seats.remove(getSeatLocation(event.getDismounted().getLocation())); seats.remove(getSeatLocation(event.getDismounted().getLocation()));
if (event.getEntityType() != EntityType.PLAYER) if (event.getEntityType() == EntityType.ARROW)
return; return;
event.getDismounted().remove(); event.getDismounted().remove();
@ -119,7 +119,7 @@ public class PlayerSeatListener implements Listener {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
if (event.getPlayer().isInsideVehicle()) if (event.getPlayer().isInsideVehicle() && event.getPlayer().getVehicle().getType() == EntityType.ARROW)
event.getPlayer().getVehicle().remove(); event.getPlayer().getVehicle().remove();
} }

Datei anzeigen

@ -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;
}
}