Update from Git Manager GUI
This commit is contained in:
77
src/main/java/de/nexuslobby/modules/gadgets/Balloon.java
Normal file
77
src/main/java/de/nexuslobby/modules/gadgets/Balloon.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package de.nexuslobby.modules.gadgets;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Balloon {
|
||||
|
||||
private final UUID playerUUID;
|
||||
private final LivingEntity balloonEntity;
|
||||
private final ArmorStand headStand;
|
||||
|
||||
public Balloon(Player player, Material balloonMaterial) {
|
||||
this.playerUUID = player.getUniqueId();
|
||||
Location loc = player.getLocation().add(0, 2, 0);
|
||||
|
||||
// Das unsichtbare Träger-Entity
|
||||
this.balloonEntity = (LivingEntity) loc.getWorld().spawnEntity(loc, EntityType.PIG);
|
||||
this.balloonEntity.setInvisible(true);
|
||||
this.balloonEntity.setSilent(true);
|
||||
this.balloonEntity.setInvulnerable(true);
|
||||
this.balloonEntity.setGravity(false);
|
||||
this.balloonEntity.setLeashHolder(player);
|
||||
|
||||
// Der ArmorStand, der den farbigen Block trägt
|
||||
this.headStand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
|
||||
this.headStand.setVisible(false);
|
||||
this.headStand.setGravity(false);
|
||||
this.headStand.setMarker(true);
|
||||
|
||||
// Hier wird das übergebene Material gesetzt (z.B. RED_WOOL, BLUE_WOOL etc.)
|
||||
this.headStand.setHelmet(new ItemStack(balloonMaterial));
|
||||
}
|
||||
|
||||
public void update() {
|
||||
Player player = org.bukkit.Bukkit.getPlayer(playerUUID);
|
||||
|
||||
if (player == null || !player.isOnline() || balloonEntity == null || !balloonEntity.isValid()) {
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!balloonEntity.isLeashed()) {
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
|
||||
Location targetLoc = player.getLocation().clone().add(0, 2.5, 0);
|
||||
Vector direction = targetLoc.toVector().subtract(balloonEntity.getLocation().toVector());
|
||||
double distance = direction.length();
|
||||
|
||||
if (distance > 5) {
|
||||
balloonEntity.teleport(targetLoc);
|
||||
} else if (distance > 0.1) {
|
||||
balloonEntity.setVelocity(direction.multiply(0.4));
|
||||
}
|
||||
|
||||
headStand.teleport(balloonEntity.getLocation().clone().subtract(0, 1.5, 0));
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if (balloonEntity != null) {
|
||||
balloonEntity.setLeashHolder(null);
|
||||
balloonEntity.remove();
|
||||
}
|
||||
if (headStand != null) {
|
||||
headStand.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user