129 lines
4.8 KiB
Java
129 lines
4.8 KiB
Java
package com.yaohun.playerview.gui;
|
|
|
|
import com.yaohun.playerview.util.StackUtil;
|
|
import eos.moe.dragoncore.api.FutureSlotAPI;
|
|
import me.Demon.DemonPlugin.DemonAPI;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.inventory.Inventory;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
public class BackpackGui {
|
|
|
|
private static final String INV_TITLE = "§v§i§e§w§r玩家交互 - ";
|
|
|
|
public static void openGui(Player player, Player target,boolean backpackD){
|
|
String targetName = target.getName();
|
|
Inventory inv = Bukkit.createInventory(null,45,INV_TITLE+"正在查看"+targetName+"的背包");
|
|
ItemStack glass = DemonAPI.glass(15, "§r");
|
|
for (int i = 36;i<45;i++) {
|
|
inv.setItem(i, glass);
|
|
}
|
|
if(backpackD){
|
|
PlayerInventory inventory = target.getInventory();
|
|
for(int i = 9; i < 45; i++){
|
|
ItemStack item = inventory.getItem(i);
|
|
if(!DemonAPI.itemIsNull(item)){
|
|
inv.setItem(i-9,infoItems(item));
|
|
}
|
|
}
|
|
for(int i = 0; i < 9; i++){
|
|
ItemStack item = inventory.getItem(i);
|
|
if(!DemonAPI.itemIsNull(item)){
|
|
inv.setItem(i+27,infoItems(item));
|
|
}
|
|
}
|
|
inv.setItem(40, StackUtil.modeSwitch(targetName,backpackD));
|
|
} else {
|
|
addEquipment(target,inv);
|
|
addDragonStack(target,inv,9,"头部兽骨");
|
|
addDragonStack(target,inv,10,"躯干兽骨");
|
|
addDragonStack(target,inv,11,"尾部兽骨");
|
|
addDragonStack(target,inv,12,"手部兽骨1");
|
|
addDragonStack(target,inv,13,"手部兽骨2");
|
|
addDragonStack(target,inv,14,"腿部兽骨1");
|
|
addDragonStack(target,inv,15,"腿部兽骨2");
|
|
addDragonStack(target,inv,18,"暗器槽1");
|
|
addDragonStack(target,inv,19,"暗器槽2");
|
|
addDragonStack(target,inv,20,"暗器槽3");
|
|
addDragonStack(target,inv,21,"暗器槽4");
|
|
addDragonStack(target,inv,23,"项链槽");
|
|
addDragonStack(target,inv,24,"戒指槽");
|
|
addDragonStack(target,inv,25,"手镯槽");
|
|
addDragonStack(target,inv,26,"公仔槽");
|
|
inv.setItem(40, StackUtil.modeSwitch(targetName,backpackD));
|
|
}
|
|
player.openInventory(inv);
|
|
player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG,0.8f,1);
|
|
}
|
|
|
|
private static void addDragonStack(Player target,Inventory inv,int slot,String identifier){
|
|
ItemStack stack = getDragonItems(target,identifier);
|
|
if(!DemonAPI.itemIsNull(stack)) {
|
|
inv.setItem(slot, infoItems(stack));
|
|
}
|
|
}
|
|
|
|
private static void addEquipment(Player target,Inventory inv){
|
|
// 添加头盔
|
|
PlayerInventory inventory = target.getInventory();
|
|
if(!DemonAPI.itemIsNull(inventory.getHelmet())){
|
|
inv.setItem(0, infoItems(inventory.getHelmet()));
|
|
}
|
|
// 添加胸甲
|
|
if(!DemonAPI.itemIsNull(inventory.getChestplate())){
|
|
inv.setItem(1, infoItems(inventory.getChestplate()));
|
|
}
|
|
// 添加护腿
|
|
if(!DemonAPI.itemIsNull(inventory.getLeggings())){
|
|
inv.setItem(2, infoItems(inventory.getLeggings()));
|
|
}
|
|
// 添加靴子
|
|
if(!DemonAPI.itemIsNull(inventory.getBoots())){
|
|
inv.setItem(3, infoItems(inventory.getBoots()));
|
|
}
|
|
// 添加主手
|
|
if(!DemonAPI.itemIsNull(inventory.getItemInMainHand())){
|
|
inv.setItem(4, infoItems(inventory.getItemInMainHand()));
|
|
}
|
|
// 添加副手
|
|
if(!DemonAPI.itemIsNull(inventory.getItemInOffHand())){
|
|
inv.setItem(5, infoItems(inventory.getItemInOffHand()));
|
|
}
|
|
}
|
|
|
|
private static ItemStack infoItems(ItemStack items){
|
|
ItemStack item = items.clone();
|
|
ItemMeta meta = item.getItemMeta();
|
|
List<String> lore = new ArrayList<>();
|
|
if(!DemonAPI.itemIsLore(items)){
|
|
lore.addAll(items.getItemMeta().getLore());
|
|
}
|
|
lore.add("§c仅供查看");
|
|
meta.setLore(lore);
|
|
item.setItemMeta(meta);
|
|
return item;
|
|
}
|
|
|
|
private static ItemStack getDragonItems(Player p, String identifier) {
|
|
try {
|
|
ItemStack item = FutureSlotAPI.getSlotItem(p, identifier).get(); // 只调用一次
|
|
|
|
if (!DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)) {
|
|
return item;
|
|
}
|
|
} catch (InterruptedException | ExecutionException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
}
|