This commit is contained in:
yaohunya 2025-08-07 05:06:27 +08:00
commit 8b7e9f5791
9 changed files with 581 additions and 0 deletions

62
pom.xml Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>DemonPlayerView</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>public-rpg</id>
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2</version>
</dependency>
<dependency>
<groupId>com.yaohun.demonlogintime</groupId>
<artifactId>DemonLoginTime</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>me.Demon.DemonPlugin</groupId>
<artifactId>DemonAPI</artifactId>
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>com.yaohun.onlinereward</groupId>
<artifactId>AuOnlineReward</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.yaohun.aurechargedata</groupId>
<artifactId>AuRechargeData</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>eos.moe.dragoncore</groupId>
<artifactId>DragonCore</artifactId>
<version>2.6.2.0</version>
</dependency>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>Citizens</artifactId>
<version>2.0.26</version>
</dependency>
</dependencies>
</project>

View File

@ -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;
}
}

View File

@ -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<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;
}
}

View File

@ -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<inv.getSize();i++) {
inv.setItem(i, glass);
}
String targetName = target.getName();
inv.setItem(11, StackUtil.infoShow(target));
inv.setItem(13, StackUtil.backpackView(targetName));
inv.setItem(15, StackUtil.startTrade(targetName));
player.openInventory(inv);
player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG,0.8f,1);
}
}

View File

@ -0,0 +1,34 @@
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.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class MasterGui {
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<inv.getSize();i++) {
inv.setItem(i, glass);
}
String targetName = target.getName();
inv.setItem(10, StackUtil.infoShow(target));
inv.setItem(12, StackUtil.backpackView(targetName));
inv.setItem(14, StackUtil.startTrade(targetName));
inv.setItem(16, StackUtil.apprenticeInfo(target));
player.openInventory(inv);
player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG,0.8f,1);
}
}

View File

@ -0,0 +1,81 @@
package com.yaohun.playerview.listener;
import com.yaohun.playerview.gui.BackpackGui;
import me.Demon.DemonPlugin.DemonAPI;
import me.Demon.DemonPlugin.data.NbtItem;
import org.bukkit.Bukkit;
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.inventory.ItemStack;
public class ClickInventory implements Listener {
@EventHandler
public void onClick(InventoryClickEvent e){
int rawSlot = e.getRawSlot();
Player player = (Player) e.getWhoClicked();
ItemStack item = e.getCurrentItem();
if(e.getView().getTitle().contains("§v§i§e§w§r")){
e.setCancelled(true);
if(rawSlot == 40){
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.DIAMOND_CHESTPLATE){
NbtItem nbt = new NbtItem(item);
String targetName = nbt.getString("viewName");
Player targetPlayer = Bukkit.getPlayer(targetName);
if(targetPlayer == null){
return;
}
BackpackGui.openGui(player,targetPlayer,true);
}
}
}
if(e.getView().getTitle().contains("§l§o§o§k§r")){
e.setCancelled(true);
if(rawSlot >= 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);
}
}
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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();
}
}

View File

@ -0,0 +1,7 @@
name: DemonPlayerView
main: com.yaohun.playerview.ViewMain
version: 2.0.2
depend:
- DemonAPI
commands:
dlookt: