From 8b7e9f5791a630e5d19d405cd1026604c17359d8 Mon Sep 17 00:00:00 2001 From: yaohunya <1763917516@qq.com> Date: Thu, 7 Aug 2025 05:06:27 +0800 Subject: [PATCH] 2.0.2 --- pom.xml | 62 ++++++++ .../java/com/yaohun/playerview/ViewMain.java | 56 +++++++ .../yaohun/playerview/gui/BackpackGui.java | 128 ++++++++++++++++ .../com/yaohun/playerview/gui/CommonGui.java | 28 ++++ .../com/yaohun/playerview/gui/MasterGui.java | 34 ++++ .../playerview/listener/ClickInventory.java | 81 ++++++++++ .../playerview/listener/PlayerListener.java | 40 +++++ .../com/yaohun/playerview/util/StackUtil.java | 145 ++++++++++++++++++ src/main/resources/plugin.yml | 7 + 9 files changed, 581 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/yaohun/playerview/ViewMain.java create mode 100644 src/main/java/com/yaohun/playerview/gui/BackpackGui.java create mode 100644 src/main/java/com/yaohun/playerview/gui/CommonGui.java create mode 100644 src/main/java/com/yaohun/playerview/gui/MasterGui.java create mode 100644 src/main/java/com/yaohun/playerview/listener/ClickInventory.java create mode 100644 src/main/java/com/yaohun/playerview/listener/PlayerListener.java create mode 100644 src/main/java/com/yaohun/playerview/util/StackUtil.java create mode 100644 src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d5e62c2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + org.example + DemonPlayerView + 1.0-SNAPSHOT + + + 8 + 8 + UTF-8 + + + + + public-rpg + https://repo.aurora-pixels.com/repository/public-rpg/ + + + + + + org.spigotmc + spigot-api + 1.12.2 + + + com.yaohun.demonlogintime + DemonLoginTime + 2.1.0 + + + me.Demon.DemonPlugin + DemonAPI + 2.2.9 + + + com.yaohun.onlinereward + AuOnlineReward + 1.3.2 + + + com.yaohun.aurechargedata + AuRechargeData + 2.0.3 + + + eos.moe.dragoncore + DragonCore + 2.6.2.0 + + + net.citizensnpcs + Citizens + 2.0.26 + + + + \ No newline at end of file diff --git a/src/main/java/com/yaohun/playerview/ViewMain.java b/src/main/java/com/yaohun/playerview/ViewMain.java new file mode 100644 index 0000000..cac49db --- /dev/null +++ b/src/main/java/com/yaohun/playerview/ViewMain.java @@ -0,0 +1,56 @@ +package com.yaohun.playerview; + +import com.yaohun.playerview.gui.CommonGui; +import com.yaohun.playerview.gui.MasterGui; +import com.yaohun.playerview.listener.ClickInventory; +import com.yaohun.playerview.listener.PlayerListener; +import com.yaohun.shitu.api.ShituAPI; +import me.Demon.DemonPlugin.DemonAPI; +import me.Demon.DemonPlugin.Util.AreaType; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class ViewMain extends JavaPlugin { + + private static ViewMain instance; + + @Override + public void onEnable() { + instance = this; + getServer().getPluginManager().registerEvents(new PlayerListener(),this); + getServer().getPluginManager().registerEvents(new ClickInventory(),this); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if ("dlookt".equalsIgnoreCase(label) && sender.hasPermission("admin.use")) { + if (args.length == 0) { + DemonAPI.sendMessage(sender,"缺少玩家名的参数."); + return true; + } + String targetName = args[0]; + Player target = Bukkit.getPlayer(targetName); + if(target == null){ + DemonAPI.sendMessage(sender,"玩家不存在或不在线."); + return true; + } + Player player = (Player) sender; + if(ShituAPI.hasPlayerMaster(sender.getName())){ + if(!ShituAPI.hasPlayerApprentice(targetName)){ + MasterGui.openGui(player,target); + return true; + } + } + CommonGui.openGui(player,target); + return true; + } + return false; + } + + public static ViewMain inst() { + return instance; + } +} diff --git a/src/main/java/com/yaohun/playerview/gui/BackpackGui.java b/src/main/java/com/yaohun/playerview/gui/BackpackGui.java new file mode 100644 index 0000000..c2304e5 --- /dev/null +++ b/src/main/java/com/yaohun/playerview/gui/BackpackGui.java @@ -0,0 +1,128 @@ +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 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; + } + +} diff --git a/src/main/java/com/yaohun/playerview/gui/CommonGui.java b/src/main/java/com/yaohun/playerview/gui/CommonGui.java new file mode 100644 index 0000000..b3f15e4 --- /dev/null +++ b/src/main/java/com/yaohun/playerview/gui/CommonGui.java @@ -0,0 +1,28 @@ +package com.yaohun.playerview.gui; + +import com.yaohun.playerview.util.StackUtil; +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; + +public class CommonGui { + + private static final String INV_TITLE = "§l§o§o§k§r玩家交互 - "; + + public static void openGui(Player player, Player target){ + Inventory inv = Bukkit.createInventory(null,27,INV_TITLE+target.getName()); + ItemStack glass = DemonAPI.glass(15, "§r"); + for (int i = 0;i= 0 && rawSlot < 27) { + if (item.getType() == Material.STAINED_GLASS_PANE) { + return; + } + player.playSound(player.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 1); + if (item.getType() == Material.SKULL_ITEM) { + player.closeInventory(); + } + if (item.getType() == Material.CHEST) { + // 查看玩家背包 + NbtItem nbt = new NbtItem(item); + String targetName = nbt.getString("viewName"); + Player targetPlayer = Bukkit.getPlayer(targetName); + if(targetPlayer == null){ + return; + } + BackpackGui.openGui(player, targetPlayer, false); + } + if (item.getType() == Material.GOLD_INGOT) { + player.closeInventory(); + NbtItem nbt = new NbtItem(item); + String targetName = nbt.getString("viewName"); + player.performCommand("trade "+targetName); + DemonAPI.sendMessage(player,"§b交易请求已发送,请认准官方正规交易途径,谨防上当受骗。"); + } + if (item.getType() == Material.TOTEM) { + player.closeInventory(); + NbtItem nbt = new NbtItem(item); + String targetName = nbt.getString("viewName"); + player.performCommand("shitu invite "+targetName); + } + } + } + } +} diff --git a/src/main/java/com/yaohun/playerview/listener/PlayerListener.java b/src/main/java/com/yaohun/playerview/listener/PlayerListener.java new file mode 100644 index 0000000..5ea4792 --- /dev/null +++ b/src/main/java/com/yaohun/playerview/listener/PlayerListener.java @@ -0,0 +1,40 @@ +package com.yaohun.playerview.listener; + +import com.yaohun.onlinereward.api.OnlineAPI; +import com.yaohun.playerview.gui.CommonGui; +import com.yaohun.playerview.gui.MasterGui; +import com.yaohun.shitu.api.ShituAPI; +import net.citizensnpcs.api.CitizensAPI; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class PlayerListener implements Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + public void onuse(PlayerInteractEntityEvent e){ + if(e.isCancelled()) { + return; + } + Player player = e.getPlayer(); + Entity target = e.getRightClicked(); + if(target instanceof Player){ + Player targetPlayer = (Player) target; + String targetName = targetPlayer.getName(); + if(CitizensAPI.getNPCRegistry().isNPC(target)){ + return; + } + if(ShituAPI.hasPlayerMaster(player.getName())){ + if(!ShituAPI.hasPlayerApprentice(targetName)){ + MasterGui.openGui(player,targetPlayer); + return; + } + } + CommonGui.openGui(player,targetPlayer); + } + } + +} diff --git a/src/main/java/com/yaohun/playerview/util/StackUtil.java b/src/main/java/com/yaohun/playerview/util/StackUtil.java new file mode 100644 index 0000000..a96a39a --- /dev/null +++ b/src/main/java/com/yaohun/playerview/util/StackUtil.java @@ -0,0 +1,145 @@ +package com.yaohun.playerview.util; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.yaohun.aurechargedata.api.RechargeAPI; +import com.yaohun.aurechargedata.util.TimeType; +import com.yaohun.onlinereward.api.OnlineAPI; +import me.Demon.DemonPlugin.DemonAPI; +import me.Demon.DemonPlugin.Util.AreaType; +import me.Demon.DemonPlugin.data.NbtItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class StackUtil { + + public static ItemStack infoShow(Player p){ + ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); + ItemMeta meta = item.getItemMeta(); + GameProfile profile = new GameProfile(UUID.randomUUID(), null);profile.getProperties().put("textures", new Property("textures", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWYzYTEyNjVjNmEwYTc5NmFkYzc2ZTA3MzRkNjg4OTk3ZmViYTkwN2JkYjNkNzA4Yzg3MzNlY2JhYzFhZjY3OCJ9fX0="));Field profileField = null;try { profileField = meta.getClass().getDeclaredField("profile"); } catch (NoSuchFieldException | SecurityException e) { e.printStackTrace(); }assert profileField != null;profileField.setAccessible(true);try { profileField.set(meta, profile); } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } + meta.setDisplayName("§e§l♠ §a§l玩家基础信息§r §e§l♠"); + List lore = new ArrayList<>(); + lore.add("§a§l★ §7名称: §6"+p.getName()); + lore.add("§a§l★ §7等级: §6Lv."+ p.getLevel()); + lore.add("§a§l★ §7余额: §6"+ DemonAPI.seeMoney(p)+" §7金币"); + lore.add(""); + lore.add("§b§l★ §7点击 §6关闭 §7此界面"); + meta.setLore(lore); + item.setItemMeta(meta); + NbtItem nbt = new NbtItem(item); + nbt.setString("lookName",p.getName()); + return nbt.getItem(); + } + + public static ItemStack backpackView(String targetName){ + ItemStack item = new ItemStack(Material.CHEST); + ItemMeta meta = item.getItemMeta(); + if(DemonAPI.getAreaType() == AreaType.DEFAULT) { + meta.setDisplayName("§e§l♠ §a§l查看背包物品§r §e§l♠"); + List lore = new ArrayList<>(); + lore.add("§a§l★ §7点击 §6查看 §7他的背包"); + lore.add("§a§l★ §7全透明化了解该玩家的背包状况"); + lore.add(""); + lore.add("§b§l★ §7点击 §6查看 §7他的背包"); + meta.setLore(lore); + } else { + meta.setDisplayName("§e§l♠ §a§l查看背包物品§r §e§l♠"); + List lore = new ArrayList<>(); + lore.add("§a§l★ §7點擊 §6查看 §7他的背包"); + lore.add("§a§l★ §7全透明化瞭解該玩家的背包狀況"); + lore.add(""); + lore.add("§b§l★ §7點擊 §6查看 §7他的背包"); + meta.setLore(lore); + } + item.setItemMeta(meta); + NbtItem nbt = new NbtItem(item); + nbt.setString("viewName",targetName); + return nbt.getItem(); + } + + public static ItemStack startTrade(String targetName){ + ItemStack item = new ItemStack(Material.GOLD_INGOT); + ItemMeta meta = item.getItemMeta(); + if(DemonAPI.getAreaType() == AreaType.DEFAULT) { + meta.setDisplayName("§e§l♠ §a§l发起交易§r §e§l♠"); + List lore = new ArrayList<>(); + lore.add("§a§l★ §7用于向 §6" + targetName + " §7快速发起"); + lore.add("§a§l★ §7面对面物品交易,防止被骗。"); + lore.add(""); + lore.add("§b§l★ §7点击 §6发起 §7交易请求"); + meta.setLore(lore); + } else { + meta.setDisplayName("§e§l♠ §a§l發起交易§r §e§l♠"); + List lore = new ArrayList<>(); + lore.add("§a§l★ §7用於向 §6" + targetName + " §7快速發起"); + lore.add("§a§l★ §7面對面物品交易,防止被騙。"); + lore.add(""); + lore.add("§b§l★ §7點擊 §6發起 §7交易請求"); + meta.setLore(lore); + } + item.setItemMeta(meta); + NbtItem nbt = new NbtItem(item); + nbt.setString("viewName",targetName); + return nbt.getItem(); + } + + public static ItemStack apprenticeInfo(Player target){ + ItemStack item = new ItemStack(Material.TOTEM); + ItemMeta meta = item.getItemMeta(); + String targetName = target.getName(); + if(DemonAPI.getAreaType() == AreaType.DEFAULT) { + meta.setDisplayName("§e§l♠ §a§l收徒基本信息§r §e§l♠"); + List lore = new ArrayList<>(); + lore.add("§a§l★ §7玩家名称: §6" + targetName); + lore.add("§a§l★ §7本月储值: §b" + RechargeAPI.getRechargeData(targetName, TimeType.MONTHLY) + " §7软"); + lore.add("§a§l★ §7本月活跃: §d" + OnlineAPI.getTimeMonth(targetName) + " §7分钟"); + long firstPlayed = target.getFirstPlayed(); + lore.add("§a§l★ §7入服时间: §c" + DemonAPI.LongToStringData(firstPlayed, "yyyy年MM月dd日 HH:mm")); + lore.add(""); + lore.add("§b§l★ §7点击给他 §6发送 §7拜师请求"); + meta.setLore(lore); + } else { + meta.setDisplayName("§e§l♠ §a§l收徒基本信息§r §e§l♠"); + List lore = new ArrayList<>(); + lore.add("§a§l★ §7玩家名稱: §6" + targetName); + lore.add("§a§l★ §7本月儲值: §b" + RechargeAPI.getRechargeData(targetName, TimeType.MONTHLY) + " §7軟"); + lore.add("§a§l★ §7本月活躍: §d" + OnlineAPI.getTimeMonth(targetName) + " §7分鐘"); + long firstPlayed = target.getFirstPlayed(); + lore.add("§a§l★ §7入服時間: §c" + DemonAPI.LongToStringData(firstPlayed, "yyyy年MM月dd日 HH:mm")); + lore.add(""); + lore.add("§b§l★ §7點擊給他 §6發送 §7拜師請求"); + meta.setLore(lore); + } + item.setItemMeta(meta); + NbtItem nbt = new NbtItem(item); + nbt.setString("viewName",targetName); + return nbt.getItem(); + } + + public static ItemStack modeSwitch(String targetName,boolean backpackD){ + ItemStack item = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemMeta meta = item.getItemMeta(); + String itemName = "§6§l切换模式§7: §c装备"; + if(backpackD){ + itemName = "§6§l切换模式§7: §a背包"; + item.setType(Material.CHEST); + } + meta.setDisplayName(itemName); + List lore = new ArrayList<>(); + lore.add("§7点击切换模式"); + meta.setLore(lore); + meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + item.setItemMeta(meta); + NbtItem nbt = new NbtItem(item); + nbt.setString("viewName",targetName); + return nbt.getItem(); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..47ddf55 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,7 @@ +name: DemonPlayerView +main: com.yaohun.playerview.ViewMain +version: 2.0.2 +depend: + - DemonAPI +commands: + dlookt: \ No newline at end of file