Staff Online Menu

This commit is contained in:
Trixkz 2023-10-26 22:40:03 -04:00
parent faa11415e0
commit 97a24928fd
3 changed files with 182 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package com.loganmagnan.eventcore.managers.hotbar.types;
import com.loganmagnan.eventcore.EventCore;
import com.loganmagnan.eventcore.managers.hotbar.ClickableItem;
import com.loganmagnan.eventcore.managers.hotbar.HotBar;
import com.loganmagnan.eventcore.menusystem.menus.StaffOnlineMenu;
import com.loganmagnan.eventcore.utils.ColorUtils;
import com.loganmagnan.eventcore.utils.Constants;
import com.loganmagnan.eventcore.utils.ItemBuilder;
@ -60,7 +61,7 @@ public class StaffModeHotBar extends HotBar {
}, new ItemBuilder(Material.RED_CARPET).name(ColorUtils.getMessageType("&bBetter Looking")).build(), false, false, false));
this.addClickableItem("staff-online", new ClickableItem(player -> {
// To Do: Staff Online System
new StaffOnlineMenu(this.main.getPlayerMenuUtil(player)).open(player);
}, new ItemBuilder(Material.PLAYER_HEAD).name(ColorUtils.getMessageType("&bStaff Online")).build(), false, false, false));
this.addClickableItem("vanish", new ClickableItem(player -> {

View File

@ -0,0 +1,130 @@
package com.loganmagnan.eventcore.menusystem.menus;
import com.loganmagnan.eventcore.EventCore;
import com.loganmagnan.eventcore.menusystem.PaginatedMenu;
import com.loganmagnan.eventcore.menusystem.PlayerMenuUtil;
import com.loganmagnan.eventcore.utils.ColorUtils;
import com.loganmagnan.eventcore.utils.PlayerHeadUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class StaffOnlineMenu extends PaginatedMenu {
private EventCore main = EventCore.getInstance();
private List<Player> players = new ArrayList<Player>();
public StaffOnlineMenu(PlayerMenuUtil playerMenuUtil) {
super(playerMenuUtil);
for (Player playerOnline : this.main.getServer().getOnlinePlayers()) {
if (!playerOnline.hasPermission("eventcore.command.staffmode")) {
continue;
}
this.players.add(playerOnline);
}
}
@Override
public String getMenuName() {
return ColorUtils.getMessageType("&bStaff Online");
}
@Override
public int getSlots() {
return 27;
}
@Override
public void handleMenu(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (event.getView().getTitle().equalsIgnoreCase(ColorUtils.getMessageType("&bStaff Online"))) {
ItemStack itemStack = event.getCurrentItem();
switch (ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName())) {
case "Previous Page":
if (this.page == 0) {
player.sendMessage(ColorUtils.getMessageType("&aYou're on the first page"));
} else {
this.page--;
this.open(player);
}
break;
case "Close":
player.closeInventory();
break;
case "Next Page":
if (!((this.index++) >= this.players.size())) {
this.page++;
this.open(player);
} else {
player.sendMessage(ColorUtils.getMessageType("&aYou're on the last page"));
}
break;
}
String targetName = event.getCurrentItem().getItemMeta().getDisplayName();
Player target = this.main.getServer().getPlayer(ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName()));
if (target == null) {
return;
}
player.closeInventory();
player.teleport(target);
player.sendMessage(ColorUtils.getMessageType("&aTeleported to &a&l" + target.getName()));
}
}
@Override
public void setMenuItems(Player player) {
this.addMenuBorder();
if (this.players.isEmpty()) {
return;
}
for (int i = 0; i < this.getMaxItemsPerPage(); i++) {
this.index = this.getMaxItemsPerPage() * this.page + i;
if (this.index >= this.players.size()) {
break;
}
if (this.players.get(this.index) == null) {
continue;
}
Player playerOnline = this.players.get(this.index);
if (playerOnline == null) {
continue;
}
List<String> lore = new ArrayList<String>();
lore.add(ColorUtils.getMessageType("&fStaff Mode: " + (this.main.getStaffManager().isPlayerInStaffMode(playerOnline) ? "&aEnabled" : "&4Disabled")));
lore.add(ColorUtils.getMessageType("&fVanish: " + (this.main.getStaffManager().isPlayerVanished(playerOnline) ? "&aEnabled" : "&4Disabled")));
lore.add(ColorUtils.getMessageType(""));
lore.add(ColorUtils.getMessageType("&bClick to teleport"));
PlayerHeadUtils playerHeadUtils = new PlayerHeadUtils();
playerHeadUtils.name(playerOnline.getDisplayName());
playerHeadUtils.lore(lore);
playerHeadUtils.owner(playerOnline.getName());
ItemStack itemStack = playerHeadUtils.makeItemStack();
this.inventory.addItem(itemStack);
}
}
}

View File

@ -0,0 +1,50 @@
package com.loganmagnan.eventcore.utils;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
public class PlayerHeadUtils {
private Material material = Material.PLAYER_HEAD;
private Short durability = Short.valueOf((short)3);
private int amount = 1;
private String name;
private Object owner = "steve";
private List<String> lore;
public PlayerHeadUtils name(String name) {
this.name = name;
return this;
}
public PlayerHeadUtils owner(Object owner) {
this.owner = owner;
return this;
}
public PlayerHeadUtils lore(List<String> lore) {
this.lore = lore;
return this;
}
public ItemStack makeItemStack() {
ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD);
SkullMeta meta = (SkullMeta)itemStack.getItemMeta();
itemStack.setAmount(1);
itemStack.setDurability((short)3);
if (this.name != null)
meta.setDisplayName(ColorUtils.getMessageType("&r" + this.name));
if (this.lore != null && this.lore.size() > 0)
meta.setLore(ColorUtils.getMessageType(this.lore));
meta.setOwner((String)this.owner);
itemStack.setItemMeta(meta);
return itemStack;
}
}