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();
|
||||
}
|
||||
}
|
||||
}
|
||||
54
src/main/java/de/nexuslobby/modules/gadgets/ChickenRain.java
Normal file
54
src/main/java/de/nexuslobby/modules/gadgets/ChickenRain.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package de.nexuslobby.modules.gadgets;
|
||||
|
||||
import de.nexuslobby.NexusLobby;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Chicken;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class ChickenRain {
|
||||
|
||||
public static void start(Player player) {
|
||||
new BukkitRunnable() {
|
||||
int ticks = 0;
|
||||
final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!player.isOnline() || ticks > 100) { // 100 Ticks = 5 Sekunden
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
// Alle 2 Ticks ein Huhn spawnen
|
||||
if (ticks % 2 == 0) {
|
||||
Location spawnLoc = player.getLocation().add(
|
||||
(random.nextDouble() - 0.5) * 4,
|
||||
4.0,
|
||||
(random.nextDouble() - 0.5) * 4
|
||||
);
|
||||
|
||||
Chicken chicken = (Chicken) spawnLoc.getWorld().spawnEntity(spawnLoc, EntityType.CHICKEN);
|
||||
chicken.setBaby();
|
||||
chicken.setInvulnerable(true);
|
||||
|
||||
// Nach 1.5 Sekunden "ploppt" das Huhn
|
||||
Bukkit.getScheduler().runTaskLater(NexusLobby.getInstance(), () -> {
|
||||
if (chicken.isValid()) {
|
||||
chicken.getWorld().spawnParticle(Particle.CLOUD, chicken.getLocation(), 5, 0.2, 0.2, 0.2, 0.1);
|
||||
chicken.getWorld().playSound(chicken.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1.0f, 1.5f);
|
||||
chicken.remove();
|
||||
}
|
||||
}, 30L);
|
||||
}
|
||||
ticks++;
|
||||
}
|
||||
}.runTaskTimer(NexusLobby.getInstance(), 0L, 1L);
|
||||
}
|
||||
}
|
||||
200
src/main/java/de/nexuslobby/modules/gadgets/GadgetModule.java
Normal file
200
src/main/java/de/nexuslobby/modules/gadgets/GadgetModule.java
Normal file
@@ -0,0 +1,200 @@
|
||||
package de.nexuslobby.modules.gadgets;
|
||||
|
||||
import de.nexuslobby.NexusLobby;
|
||||
import de.nexuslobby.api.Module;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GadgetModule implements Module, Listener {
|
||||
|
||||
private final Map<UUID, Balloon> activeBalloons = new HashMap<>();
|
||||
private final Map<UUID, ParticleEffect> activeEffects = new HashMap<>();
|
||||
|
||||
// Titel für die verschiedenen Inventare zur Identifikation
|
||||
private final String MAIN_TITLE = "§b§lGadgets §8- §7Menü";
|
||||
private final String BALLOON_TITLE = "§b§lGadgets §8- §eBallons";
|
||||
private final String PARTICLE_TITLE = "§b§lGadgets §8- §dPartikel";
|
||||
private final String FUN_TITLE = "§b§lGadgets §8- §6Lustiges";
|
||||
|
||||
@Override
|
||||
public String getName() { return "Gadgets"; }
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(this, NexusLobby.getInstance());
|
||||
Bukkit.getScheduler().runTaskTimer(NexusLobby.getInstance(), () -> {
|
||||
activeBalloons.values().forEach(Balloon::update);
|
||||
activeEffects.forEach((uuid, effect) -> {
|
||||
Player p = Bukkit.getPlayer(uuid);
|
||||
if (p != null && p.isOnline()) effect.update(p);
|
||||
});
|
||||
}, 1L, 1L);
|
||||
}
|
||||
|
||||
// --- GUI ÖFFNER ---
|
||||
|
||||
public void openGUI(Player player) {
|
||||
Inventory gui = Bukkit.createInventory(null, 27, MAIN_TITLE);
|
||||
fillEdges(gui);
|
||||
|
||||
gui.setItem(10, createItem(Material.LEAD, "§e§lBallons", "§7Wähle einen fliegenden Begleiter"));
|
||||
gui.setItem(13, createItem(Material.FIREWORK_ROCKET, "§6§lLustiges", "§7Witzige Effekte für zwischendurch"));
|
||||
gui.setItem(16, createItem(Material.NETHER_STAR, "§d§lPartikel", "§7Wähle magische Effekte"));
|
||||
|
||||
gui.setItem(22, createItem(Material.BARRIER, "§c§lStopp", "§7Alle Gadgets entfernen"));
|
||||
|
||||
player.openInventory(gui);
|
||||
}
|
||||
|
||||
private void openBalloonGUI(Player player) {
|
||||
Inventory gui = Bukkit.createInventory(null, 36, BALLOON_TITLE);
|
||||
fillEdges(gui);
|
||||
|
||||
Material[] wools = {Material.WHITE_WOOL, Material.ORANGE_WOOL, Material.MAGENTA_WOOL, Material.LIGHT_BLUE_WOOL,
|
||||
Material.YELLOW_WOOL, Material.LIME_WOOL, Material.PINK_WOOL, Material.GRAY_WOOL,
|
||||
Material.CYAN_WOOL, Material.PURPLE_WOOL, Material.BLUE_WOOL, Material.BROWN_WOOL,
|
||||
Material.GREEN_WOOL, Material.RED_WOOL};
|
||||
|
||||
int slot = 10;
|
||||
for (Material m : wools) {
|
||||
if (slot == 17) slot = 19;
|
||||
gui.setItem(slot++, createItem(m, "§fBallon: " + m.name().replace("_WOOL", ""), "§7Klicke zum Ausrüsten"));
|
||||
}
|
||||
gui.setItem(31, createItem(Material.ARROW, "§7Zurück", "§8Zum Hauptmenü"));
|
||||
player.openInventory(gui);
|
||||
}
|
||||
|
||||
private void openParticleGUI(Player player) {
|
||||
Inventory gui = Bukkit.createInventory(null, 27, PARTICLE_TITLE);
|
||||
fillEdges(gui);
|
||||
|
||||
gui.setItem(11, createItem(Material.POPPY, "§cHerzchen-Aura", "§7Verbreite Liebe"));
|
||||
gui.setItem(13, createItem(Material.BLAZE_POWDER, "§6Flammen-Ring", "§7Werde feurig"));
|
||||
gui.setItem(15, createItem(Material.WATER_BUCKET, "§bRegenwolke", "§7Lass es regnen"));
|
||||
|
||||
gui.setItem(22, createItem(Material.ARROW, "§7Zurück", "§8Zum Hauptmenü"));
|
||||
player.openInventory(gui);
|
||||
}
|
||||
|
||||
private void openFunGUI(Player player) {
|
||||
Inventory gui = Bukkit.createInventory(null, 27, FUN_TITLE);
|
||||
fillEdges(gui);
|
||||
|
||||
gui.setItem(13, createItem(Material.EGG, "§f§lChicken-Rain", "§7Lass es Küken regnen!"));
|
||||
|
||||
gui.setItem(22, createItem(Material.ARROW, "§7Zurück", "§8Zum Hauptmenü"));
|
||||
player.openInventory(gui);
|
||||
}
|
||||
|
||||
// --- EVENT HANDLER ---
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
String title = event.getView().getTitle();
|
||||
if (!title.equals(MAIN_TITLE) && !title.equals(BALLOON_TITLE) && !title.equals(PARTICLE_TITLE) && !title.equals(FUN_TITLE)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item == null || item.getType() == Material.AIR) return;
|
||||
|
||||
// Zurück-Button Logik
|
||||
if (item.getType() == Material.ARROW) {
|
||||
openGUI(player);
|
||||
return;
|
||||
}
|
||||
|
||||
// HAUPTMENÜ LOGIK
|
||||
if (title.equals(MAIN_TITLE)) {
|
||||
if (item.getType() == Material.LEAD) openBalloonGUI(player);
|
||||
else if (item.getType() == Material.NETHER_STAR) openParticleGUI(player);
|
||||
else if (item.getType() == Material.FIREWORK_ROCKET) openFunGUI(player);
|
||||
else if (item.getType() == Material.BARRIER) {
|
||||
removeGadgets(player);
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
// BALLON MENÜ LOGIK
|
||||
else if (title.equals(BALLOON_TITLE)) {
|
||||
if (item.getType().toString().endsWith("_WOOL")) {
|
||||
if (activeBalloons.containsKey(player.getUniqueId())) activeBalloons.get(player.getUniqueId()).remove();
|
||||
activeBalloons.put(player.getUniqueId(), new Balloon(player, item.getType()));
|
||||
player.sendMessage("§8[§6Nexus§8] §aBallon ausgerüstet!");
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
// PARTIKEL MENÜ LOGIK
|
||||
else if (title.equals(PARTICLE_TITLE)) {
|
||||
if (item.getType() == Material.POPPY) activeEffects.put(player.getUniqueId(), new ParticleEffect("hearts"));
|
||||
else if (item.getType() == Material.BLAZE_POWDER) activeEffects.put(player.getUniqueId(), new ParticleEffect("flames"));
|
||||
else if (item.getType() == Material.WATER_BUCKET) activeEffects.put(player.getUniqueId(), new ParticleEffect("cloud"));
|
||||
|
||||
if (item.getType() != Material.GRAY_STAINED_GLASS_PANE) {
|
||||
player.sendMessage("§8[§6Nexus§8] §aEffekt aktiviert!");
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
// FUN MENÜ LOGIK
|
||||
else if (title.equals(FUN_TITLE)) {
|
||||
if (item.getType() == Material.EGG) {
|
||||
ChickenRain.start(player);
|
||||
player.sendMessage("§8[§6Nexus§8] §fEs regnet jetzt Hühner!");
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeGadgets(Player player) {
|
||||
if (activeBalloons.containsKey(player.getUniqueId())) {
|
||||
activeBalloons.get(player.getUniqueId()).remove();
|
||||
activeBalloons.remove(player.getUniqueId());
|
||||
}
|
||||
activeEffects.remove(player.getUniqueId());
|
||||
player.sendMessage("§8[§6Nexus§8] §cAlle Gadgets wurden entfernt.");
|
||||
}
|
||||
|
||||
private void fillEdges(Inventory inv) {
|
||||
ItemStack glass = createItem(Material.GRAY_STAINED_GLASS_PANE, " ", null);
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
if (i < 9 || i >= inv.getSize() - 9 || i % 9 == 0 || (i + 1) % 9 == 0) {
|
||||
inv.setItem(i, glass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack createItem(Material mat, String name, String lore) {
|
||||
ItemStack item = new ItemStack(mat);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(name);
|
||||
if (lore != null) {
|
||||
java.util.List<String> l = new java.util.ArrayList<>();
|
||||
l.add(lore);
|
||||
meta.setLore(l);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
activeBalloons.values().forEach(Balloon::remove);
|
||||
activeBalloons.clear();
|
||||
activeEffects.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package de.nexuslobby.modules.gadgets;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ParticleEffect {
|
||||
private final String type;
|
||||
private double angle = 0;
|
||||
|
||||
public ParticleEffect(String type) { this.type = type; }
|
||||
|
||||
public void update(Player player) {
|
||||
Location loc = player.getLocation();
|
||||
switch (type.toLowerCase()) {
|
||||
case "hearts":
|
||||
player.getWorld().spawnParticle(Particle.HEART, loc.clone().add(0, 2.2, 0), 1, 0.3, 0.3, 0.3, 0);
|
||||
break;
|
||||
case "flames":
|
||||
double x = 0.6 * Math.cos(angle);
|
||||
double z = 0.6 * Math.sin(angle);
|
||||
player.getWorld().spawnParticle(Particle.FLAME, loc.clone().add(x, 0.1, z), 1, 0, 0, 0, 0);
|
||||
angle += 0.2;
|
||||
break;
|
||||
case "cloud":
|
||||
player.getWorld().spawnParticle(Particle.CLOUD, loc.clone().add(0, 2.5, 0), 2, 0.2, 0.05, 0.2, 0);
|
||||
player.getWorld().spawnParticle(Particle.FALLING_WATER, loc.clone().add(0, 2.4, 0), 1, 0.1, 0, 0.1, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user