Update from Git Manager GUI
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user