75 lines
2.6 KiB
Java
75 lines
2.6 KiB
Java
/*
|
|
* Copyright (c) 2018 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.lobby.listeners;
|
|
|
|
import eu.univento.commons.player.rank.Rank;
|
|
import eu.univento.commons.server.ServerType;
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.gui.inventory.InventoryGUI;
|
|
import eu.univento.core.api.items.ItemBuilder;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
import org.bukkit.inventory.Inventory;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class MenuEvents implements Listener {
|
|
|
|
private Inventory lobbySwitcher;
|
|
|
|
@EventHandler
|
|
public void onPlayerInteract(PlayerInteractEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
if (e.getItem().getType() == Material.BUCKET) {
|
|
p.openInventory(lobbySwitcher);
|
|
p.playSound(p.getEyeLocation(), Sound.BLOCK_CHEST_OPEN, 1.0F, 1.0F);
|
|
}
|
|
if(e.getItem().getType() == Material.NETHER_STAR) {
|
|
InventoryGUI gui = new InventoryGUI(p, 27, "Lobby Navigator");
|
|
|
|
//spawn teleport
|
|
gui.addItem(1, new ItemBuilder(p, Material.SLIME_BALL).name("Spawn").build(), player -> {
|
|
player.closeInventory();
|
|
player.teleport(player.getWorld().getSpawnLocation());
|
|
});
|
|
|
|
//build server teleport
|
|
if(p.getDatabasePlayer().isAllowed(Rank.Sound)) {
|
|
gui.addItem(0, new ItemBuilder(p, Material.GRASS).name("Bau Server").build(), player -> {
|
|
player.closeInventory();
|
|
player.connectToServer(ServerType.TEAM_BUILD);
|
|
});
|
|
}
|
|
|
|
gui.open();
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onInventoryClick(InventoryClickEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer((Player) e.getWhoClicked());
|
|
if (e.getClickedInventory() == null && e.getCurrentItem() == null) return;
|
|
if (e.getClickedInventory() == lobbySwitcher) {
|
|
e.setCancelled(true);
|
|
String server = ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
|
|
if (Core.getCloudAPI().getServerId().equals(server)) {
|
|
p.sendMessage("Nope, da bist du doch schon");
|
|
return;
|
|
}
|
|
p.connectToServer(server);
|
|
p.closeInventory();
|
|
}
|
|
}
|
|
} |