From 26ee950c8634b5ce1757cd9b9be7375a5db538f4 Mon Sep 17 00:00:00 2001 From: yaohunya <1763917516@qq.com> Date: Thu, 7 Aug 2025 05:14:01 +0800 Subject: [PATCH] 3.0.2 --- pom.xml | 67 ++++++ .../java/com/yaohun/shitu/AdminCommand.java | 58 +++++ src/main/java/com/yaohun/shitu/StMain.java | 210 ++++++++++++++++++ .../java/com/yaohun/shitu/api/ShituAPI.java | 39 ++++ .../java/com/yaohun/shitu/config/Config.java | 58 +++++ .../com/yaohun/shitu/data/PlayerData.java | 118 ++++++++++ .../java/com/yaohun/shitu/gui/MasterGui.java | 163 ++++++++++++++ .../shitu/listsener/PlayerListener.java | 45 ++++ .../shitu/listsener/RechargeListener.java | 34 +++ .../yaohun/shitu/manage/InviteManager.java | 91 ++++++++ .../yaohun/shitu/manage/PlayerManager.java | 89 ++++++++ .../com/yaohun/shitu/util/AttributeUtil.java | 37 +++ .../java/com/yaohun/shitu/util/RankUtil.java | 69 ++++++ .../java/com/yaohun/shitu/util/StackUtil.java | 113 ++++++++++ src/main/resources/config.yml | 31 +++ src/main/resources/plugin.yml | 7 + 16 files changed, 1229 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/yaohun/shitu/AdminCommand.java create mode 100644 src/main/java/com/yaohun/shitu/StMain.java create mode 100644 src/main/java/com/yaohun/shitu/api/ShituAPI.java create mode 100644 src/main/java/com/yaohun/shitu/config/Config.java create mode 100644 src/main/java/com/yaohun/shitu/data/PlayerData.java create mode 100644 src/main/java/com/yaohun/shitu/gui/MasterGui.java create mode 100644 src/main/java/com/yaohun/shitu/listsener/PlayerListener.java create mode 100644 src/main/java/com/yaohun/shitu/listsener/RechargeListener.java create mode 100644 src/main/java/com/yaohun/shitu/manage/InviteManager.java create mode 100644 src/main/java/com/yaohun/shitu/manage/PlayerManager.java create mode 100644 src/main/java/com/yaohun/shitu/util/AttributeUtil.java create mode 100644 src/main/java/com/yaohun/shitu/util/RankUtil.java create mode 100644 src/main/java/com/yaohun/shitu/util/StackUtil.java create mode 100644 src/main/resources/config.yml create mode 100644 src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1508135 --- /dev/null +++ b/pom.xml @@ -0,0 +1,67 @@ + + + 4.0.0 + + org.example + DemonShiTu + 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 + + + org.serverct.ersha.jd + AttributePlus + 2.3.7 + + + me.clip.placeholderapi + PlaceholderAPI + 2.9.2 + + + me.Demon.DemonLevels + DemonLevels + 2.2.2 + + + + \ No newline at end of file diff --git a/src/main/java/com/yaohun/shitu/AdminCommand.java b/src/main/java/com/yaohun/shitu/AdminCommand.java new file mode 100644 index 0000000..f536f5d --- /dev/null +++ b/src/main/java/com/yaohun/shitu/AdminCommand.java @@ -0,0 +1,58 @@ +package com.yaohun.shitu; + +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.manage.PlayerManager; +import com.yaohun.shitu.util.RankUtil; +import me.Demon.DemonPlugin.DemonAPI; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; + +public class AdminCommand implements CommandExecutor { + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!sender.isOp()) { + return true; + } + if(args.length == 0){ + sender.sendMessage(""); + sender.sendMessage("§e------- ======= §6师徒系统 §e======= -------"); + sender.sendMessage("§2/"+label+" create §e[玩家名] §f- §2创建师傅档案"); + sender.sendMessage("§2/"+label+" top §f- §2查看收徒排行"); + sender.sendMessage("§2/"+label+" reload §f- §2重载配置文件"); + sender.sendMessage("§e------- ======= §6师徒系统 §e======= -------"); + sender.sendMessage(""); + } + if(args.length == 1 && "reload".equalsIgnoreCase(args[0])){ + Config.reloadConfig(StMain.inst()); + sender.sendMessage("[师徒] 配置文件已重载"); + return true; + } + if(args.length == 1 && "top".equalsIgnoreCase(args[0])){ + RankUtil.checkAcceptingApprenticesTop(sender); + return true; + } + if("create".equalsIgnoreCase(args[0]) && sender.isOp()){ + if(args.length == 1){ + DemonAPI.sendMessage(sender,"请输入你要创建的师傅名称."); + return true; + } + String masterName = args[1]; + PlayerManager playerManager = StMain.getPlayerManager(); + if(playerManager.isMaster(masterName)){ + DemonAPI.sendMessage(sender,"玩家 §e"+masterName+" §a已存在师傅档案."); + return true; + } + playerManager.createData(masterName); + DemonAPI.sendMessage(sender,"成功为玩家 §e"+masterName+" §a创建出师档案."); + return true; + } + return false; + } + +} diff --git a/src/main/java/com/yaohun/shitu/StMain.java b/src/main/java/com/yaohun/shitu/StMain.java new file mode 100644 index 0000000..d9f11ba --- /dev/null +++ b/src/main/java/com/yaohun/shitu/StMain.java @@ -0,0 +1,210 @@ +package com.yaohun.shitu; + +import com.yaohun.demonlogintime.api.LoginTimeAPI; +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.data.PlayerData; +import com.yaohun.shitu.gui.MasterGui; +import com.yaohun.shitu.listsener.PlayerListener; +import com.yaohun.shitu.listsener.RechargeListener; +import com.yaohun.shitu.manage.InviteManager; +import com.yaohun.shitu.manage.PlayerManager; +import me.Demon.DemonPlugin.DemonAPI; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class StMain extends JavaPlugin { + + private static StMain instance; + private static PlayerManager playerManager; + + @Override + public void onEnable() { + instance = this; + Config.reloadConfig(this); + playerManager = new PlayerManager(); + + getServer().getPluginManager().registerEvents(new MasterGui(),this); + getServer().getPluginManager().registerEvents(new PlayerListener(),this); + getServer().getPluginManager().registerEvents(new RechargeListener(),this); + + AdminCommand adminCommand = new AdminCommand(); + Bukkit.getPluginCommand("stadmin").setExecutor(adminCommand); + } + + @Override + public void onDisable() { + getPlayerManager().saveDataAll(); + Bukkit.getConsoleSender().sendMessage("§f[§6!§f] §aDemonShiTu §f已卸载"); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(args.length == 0){ + Player player = (Player) sender; + String playerName = player.getName(); + if(getPlayerManager().isMaster(playerName)){ + sender.sendMessage("§r "); + sender.sendMessage("§c§m §r §c师傅命令 §c§m §r"); + sender.sendMessage("§a/"+label+" open §8- §7打开师徒系统"); + sender.sendMessage("§a/"+label+" invite §e[玩家名] §8- §7邀请对方成为徒弟"); + sender.sendMessage("§a/"+label+" remove §e[徒弟名] §8- §7解除师徒关系"); + sender.sendMessage("§r "); + return true; + } + if(getPlayerManager().isDisciple(playerName)){ + sender.sendMessage("§r "); + sender.sendMessage("§c§m §r §c徒弟命令 §c§m §r"); + sender.sendMessage("§a/"+label+" jiechu §8- §7解除师徒关系§4(暂未开放)"); + sender.sendMessage("§r "); + return true; + } + sender.sendMessage("§r "); + sender.sendMessage("§c§m §r §c玩家命令 §c§m §r"); + sender.sendMessage("§a/"+label+" accept §8- §7接受拜师邀请"); + sender.sendMessage("§a/"+label+" deny §8- §7拒绝拜师邀请"); + sender.sendMessage("§r "); + return true; + } + if("jiechu".equalsIgnoreCase(args[0])) { + return true; + } + if("remove".equalsIgnoreCase(args[0])) { + if(args.length < 2){ + DemonAPI.sendMessage(sender,"正确用法: §e/"+label+" remove [玩家名]",Sound.ENTITY_VILLAGER_NO); + return true; + } + String masterName = sender.getName(); + PlayerData playerData = getPlayerManager().getPlayerData(masterName); + String targetName = args[1]; + if(!playerData.isApprenticeExit(targetName)){ + DemonAPI.sendMessage(sender,"玩家 §e"+targetName+" §a貌似不是你的徒弟.",Sound.ENTITY_VILLAGER_NO); + return true; + } + int quitTimeDays = LoginTimeAPI.getQuitTimeDays(targetName); + int offlineDays = Config.master_remove_after_offline; + if(quitTimeDays < offlineDays){ + DemonAPI.sendMessage(sender,"解除失败,徒弟 §e"+targetName+" §a尚未离线超过 §b"+offlineDays+"天",Sound.ENTITY_VILLAGER_NO); + return true; + } + playerData.removeApprentice(targetName); + playerData.saveData(); + DemonAPI.sendMessage(sender,"成功解除与 §e"+targetName+" §a的师徒关系.",Sound.ENTITY_EXPERIENCE_ORB_PICKUP); + return true; + } + if("invite".equalsIgnoreCase(args[0])) { + if(args.length < 2){ + DemonAPI.sendMessage(sender,"正确用法: §e/"+label+" invite [玩家名]",Sound.ENTITY_VILLAGER_NO); + return true; + } + Player master = (Player) sender; + int masterLevel = master.getLevel(); + int needLevel = Config.master_level_limit; + if(masterLevel < needLevel){ + DemonAPI.sendMessage(sender,"你需要将等级提升至 §e§lLv."+needLevel+" §a才能进行收徒.",Sound.ENTITY_VILLAGER_NO); + return true; + } + // 获取玩家已加入服务器多少天 + int masterJoinDays = Config.master_join_days; + long firstTime = master.getFirstPlayed() + (1000L * 60 * 60 * 24 * masterJoinDays); + if(System.currentTimeMillis() < firstTime){ + DemonAPI.sendMessage(sender,"你需要加入服务器 §e§l"+masterJoinDays+"天 §a后才能进行收徒.",Sound.ENTITY_VILLAGER_NO); + return true; + } + String masterName = master.getName(); + PlayerData masterData = getPlayerManager().getPlayerData(masterName); + int maxDiscipleSize = Config.master_max_disciple_size; + if(masterData.getApprenticeSize() >= maxDiscipleSize){ + DemonAPI.sendMessage(sender,"发送失败,你最多可以收徒 §e§l"+maxDiscipleSize+"名",Sound.ENTITY_VILLAGER_NO); + return true; + } + String targetName = args[1]; + Player target = Bukkit.getPlayer(targetName); + if (target == null || !target.isOnline()) { + DemonAPI.sendMessage(sender,"玩家 §e"+targetName+" §a貌似不在线.",Sound.ENTITY_VILLAGER_NO); + return true; + } + if(target == master){ + DemonAPI.sendMessage(sender,"发送失败,目标玩家不能是自己.",Sound.ENTITY_VILLAGER_NO); + return true; + } + if(getPlayerManager().isDisciple(targetName)){ + DemonAPI.sendMessage(sender,"发送失败,目标玩家已拜其他人为师.",Sound.ENTITY_VILLAGER_NO); + return true; + } + int playerLevel = target.getLevel(); + int levelLimit = Config.disciple_level_limit; + if(playerLevel > levelLimit){ + DemonAPI.sendMessage(sender,"发送失败,对方等级已超过 §eLv."+levelLimit+"级 §a无法成为你的徒弟.",Sound.ENTITY_VILLAGER_NO); + return true; + } + int targetJoinDays = Config.disciple_join_days; + long targetFirstTime = target.getFirstPlayed() + (1000L * 60 * 60 * 24 * targetJoinDays); + if(System.currentTimeMillis() >= targetFirstTime){ + DemonAPI.sendMessage(sender,"发送失败,对方已经加入本服超 §e"+targetJoinDays+"天 §a无法成为你的徒弟.",Sound.ENTITY_VILLAGER_NO); + return true; + } + InviteManager.sendInvite(master, target); + return true; + } + if("accept".equalsIgnoreCase(args[0])){ + InviteManager.acceptInvite((Player) sender); + return true; + } + if("deny".equalsIgnoreCase(args[0])){ + InviteManager.denyInvite((Player) sender); + return true; + } + if(args.length == 1 && "open".equalsIgnoreCase(args[0])){ + String masterName = sender.getName(); + if(!getPlayerManager().isMaster(masterName)){ + DemonAPI.sendMessage(sender,"打开失败,你还没有宗师档案.", Sound.ENTITY_VILLAGER_NO); + return true; + } + MasterGui.openGui((Player) sender,1); + return true; + } + if("create".equalsIgnoreCase(args[0])){ + Player player = (Player) sender; + String masterName = player.getName(); + if(getPlayerManager().isMaster(masterName)){ + DemonAPI.sendMessage(sender,"创建失败,你已存在出师档案.",Sound.ENTITY_VILLAGER_NO); + return true; + } + if(getPlayerManager().isDisciple(masterName)){ + DemonAPI.sendMessage(sender,"创建失败,你需要先解除师徒关系.",Sound.ENTITY_VILLAGER_NO); + return true; + } + int masterLevel = player.getLevel(); + int needLevel = Config.master_level_limit; + if(masterLevel < needLevel){ + DemonAPI.sendMessage(sender,"创建失败,你需要将等级提升至§e§lLv."+needLevel,Sound.ENTITY_VILLAGER_NO); + return true; + } + // 获取玩家已加入服务器多少天 + int masterJoinDays = Config.master_join_days; + long firstTime = player.getFirstPlayed() + (1000L * 60 * 60 * 24 * masterJoinDays); + if(System.currentTimeMillis() < firstTime){ + DemonAPI.sendMessage(sender,"创建失败,你需要加入服务器§e§l"+masterJoinDays+"天",Sound.ENTITY_VILLAGER_NO); + return true; + } + getPlayerManager().createData(masterName); + DemonAPI.sendMessage(sender,"创建成功,你已经完成了出师已拥有宗师档案.",Sound.ENTITY_EXPERIENCE_ORB_PICKUP); + MasterGui.openGui(player,1); + return true; + } + return false; + } + + + public static StMain inst() { + return instance; + } + + public static PlayerManager getPlayerManager() { + return playerManager; + } +} diff --git a/src/main/java/com/yaohun/shitu/api/ShituAPI.java b/src/main/java/com/yaohun/shitu/api/ShituAPI.java new file mode 100644 index 0000000..a0adea7 --- /dev/null +++ b/src/main/java/com/yaohun/shitu/api/ShituAPI.java @@ -0,0 +1,39 @@ +package com.yaohun.shitu.api; + +import com.yaohun.shitu.StMain; +import com.yaohun.shitu.data.PlayerData; +import com.yaohun.shitu.manage.PlayerManager; +import org.bukkit.SandstoneType; + +public class ShituAPI { + + public static boolean hasPlayerMaster(String name){ + PlayerManager playerManager = StMain.getPlayerManager(); + if(playerManager.isMaster(name)){ + return true; + } + return false; + } + + public static int getMasterApprenticeSize(String name){ + PlayerManager playerManager = StMain.getPlayerManager(); + PlayerData playerData = playerManager.getPlayerData(name); + if(playerData == null){ + return 0; + } + return playerData.getApprenticeSize(); + } + + public static boolean hasPlayerApprentice(String name){ + PlayerManager playerManager = StMain.getPlayerManager(); + if(playerManager.isDisciple(name)){ + return true; + } + return false; + } + + public static String getPlayerMaster(String name){ + PlayerManager playerManager = StMain.getPlayerManager(); + return playerManager.getMasterName(name); + } +} diff --git a/src/main/java/com/yaohun/shitu/config/Config.java b/src/main/java/com/yaohun/shitu/config/Config.java new file mode 100644 index 0000000..469c394 --- /dev/null +++ b/src/main/java/com/yaohun/shitu/config/Config.java @@ -0,0 +1,58 @@ +package com.yaohun.shitu.config; + +import com.yaohun.shitu.StMain; +import org.bukkit.configuration.file.FileConfiguration; + +import java.util.ArrayList; +import java.util.List; + +public class Config { + + public static String pathData = "plugins/AuData/ShiTuData"; + public static double reward_recharge_scale; + public static int reward_level_target; + public static List reward_attribute = new ArrayList<>(); + public static List reward_commands1 = new ArrayList<>(); + public static List reward_commands2 = new ArrayList<>(); + public static List reward_commands3 = new ArrayList<>(); + + public static int disciple_auto_remove_days; + public static int disciple_level_limit; + public static int disciple_join_days; + + public static int master_level_limit; + public static int master_join_days; + public static int master_max_disciple_size; + public static int master_remove_after_offline; + + public static void reloadConfig(StMain plugin){ + plugin.reloadConfig(); + plugin.saveConfig(); + FileConfiguration config = plugin.getConfig(); + loadRewardSettings(config); + loadDiscipleSettings(config); + loadMasterSettings(config); + } + + private static void loadRewardSettings(FileConfiguration config){ + reward_attribute = config.getStringList("rewards.attributeList"); + reward_level_target = config.getInt("rewards.levelTarget",80); + reward_recharge_scale = config.getDouble("rewards.rechargeScale",0.05); + reward_commands1 = config.getStringList("rewards.rewardList_1"); + reward_commands2 = config.getStringList("rewards.rewardList_2"); + reward_commands3 = config.getStringList("rewards.rewardList_3"); + } + + private static void loadDiscipleSettings(FileConfiguration config){ + disciple_auto_remove_days = config.getInt("disciple.autoRemoveDays",30); + disciple_level_limit = config.getInt("disciple.maxLevelLimit",80); + disciple_join_days = config.getInt("disciple.maxJoinDays",30); + } + + private static void loadMasterSettings(FileConfiguration config){ + master_level_limit = config.getInt("master.levelLimit",90); + master_join_days = config.getInt("master.joinDaysLimit",30); + master_max_disciple_size = config.getInt("master.maxDiscipleSize",25); + master_remove_after_offline = config.getInt("master.removeAfterOffline",3); + } +} diff --git a/src/main/java/com/yaohun/shitu/data/PlayerData.java b/src/main/java/com/yaohun/shitu/data/PlayerData.java new file mode 100644 index 0000000..155da87 --- /dev/null +++ b/src/main/java/com/yaohun/shitu/data/PlayerData.java @@ -0,0 +1,118 @@ +package com.yaohun.shitu.data; + +import com.yaohun.shitu.StMain; +import com.yaohun.shitu.config.Config; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class PlayerData { + private final String playerName; + private final File file; + private final FileConfiguration config; + + private double incomeValue; + private long loginTime; + private HashMap apprenticeMap = new HashMap<>(); + private List challengeGoals = new ArrayList<>(); + + public PlayerData(String name){ + this.playerName = name; + File path = new File(Config.pathData); + if(!path.exists()){ + path.mkdirs(); + } + this.file = new File(path, name + ".yml"); + if(!file.exists()){ + try { + file.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + this.config= YamlConfiguration.loadConfiguration(this.file); + loadData(); + } + + private void loadData(){ + this.loginTime = config.getLong("loginTime", System.currentTimeMillis()); + this.incomeValue = config.getDouble("incomeValue", 0); + ConfigurationSection section = config.getConfigurationSection("Apprentice"); + if(section != null){ + for(String key : section.getKeys(false)){ + this.apprenticeMap.put(key, section.getBoolean(key)); + } + } + } + + public String getPlayerName() { + return playerName; + } + + public long getLoginTime() { + return loginTime; + } + + public double getIncomeValue() { + return incomeValue; + } + + public void addIncomeValue(double value){ + this.incomeValue += value; + } + + public void removeApprentice(String name){ + apprenticeMap.remove(name); + } + + public List getApprenticeList() { + return new ArrayList<>(apprenticeMap.keySet()); + } + + public int getApprenticeSize(){ + return apprenticeMap.size(); + } + + public boolean isApprenticeExit(String name){ + return apprenticeMap.containsKey(name); + } + + public boolean isActiveReward(String name){ + if(apprenticeMap.containsKey(name)){ + return apprenticeMap.get(name); + } + return false; + } + + public void setActivePlayer(String name,boolean isActive){ + apprenticeMap.put(name, isActive); + } + + public boolean isChallengeGoal(String name){ + return challengeGoals.contains(name); + } + + public void addChallengeGoal(String name){ + challengeGoals.add(name); + } + + public void saveData(){ + config.set("loginTime", System.currentTimeMillis()); + config.set("incomeValue", incomeValue); + config.set("Apprentice",null); + for (String playerName : apprenticeMap.keySet()){ + config.set("Apprentice." + playerName, apprenticeMap.get(playerName)); + } + try { + config.save(file); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/com/yaohun/shitu/gui/MasterGui.java b/src/main/java/com/yaohun/shitu/gui/MasterGui.java new file mode 100644 index 0000000..15740ab --- /dev/null +++ b/src/main/java/com/yaohun/shitu/gui/MasterGui.java @@ -0,0 +1,163 @@ +package com.yaohun.shitu.gui; + +import com.yaohun.onlinereward.api.OnlineAPI; +import com.yaohun.shitu.StMain; +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.data.PlayerData; +import com.yaohun.shitu.manage.PlayerManager; +import com.yaohun.shitu.util.StackUtil; +import me.Demon.DemonLevels.api.DLevelAPI; +import me.Demon.DemonPlugin.DemonAPI; +import me.Demon.DemonPlugin.data.NbtItem; +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.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Deque; +import java.util.HashMap; +import java.util.List; + +public class MasterGui implements Listener { + + private static String invTitle = "斗魂帝国 - 师徒系统"; + + public static void openGui(Player player,int page){ + String masterName = player.getName(); + PlayerManager playerManager = StMain.getPlayerManager(); + PlayerData masterData = playerManager.getPlayerData(masterName); + Inventory inv = Bukkit.createInventory(null,54,invTitle); + inv.setItem(2, StackUtil.getApprenticeSize(masterData)); + inv.setItem(4,StackUtil.getRewardChest()); + inv.setItem(6,StackUtil.getPointsShop()); + inv.setItem(0,StackUtil.turnThePage("上一页",page)); + inv.setItem(8,StackUtil.turnThePage("下一页",page)); + List apprenticeList = masterData.getApprenticeList(); + int apprenticesPerPage = 5; + // 当前页起始下标 + int startIndex = (page - 1) * apprenticesPerPage; + // 当前页结束下标(不含) + int endIndex = Math.min(startIndex + apprenticesPerPage, apprenticeList.size()); + int slot = 9; + for (int i = startIndex; i < endIndex; i++) { + String name = apprenticeList.get(i); + inv.setItem(slot, StackUtil.getApprentice(name)); + inv.setItem(slot + 1, StackUtil.getActiveIncome(masterData, name)); + slot += 9; + } + player.openInventory(inv); + } + + private final List settlementIncomeD = new ArrayList<>(); + + @EventHandler + public void onClick(InventoryClickEvent e){ + int rawSlot = e.getRawSlot(); + Player player = (Player) e.getWhoClicked(); + String playerName = player.getName(); + Inventory inv = e.getInventory(); + if(e.getView().getTitle().contains(invTitle)){ + e.setCancelled(true); + if(rawSlot == 4){ + // 打开奖励界面 + player.closeInventory(); + DemonAPI.sendMessage(player,"宗师奖励礼包即将开放.",Sound.ENTITY_VILLAGER_NO); + } + if(rawSlot == 6){ + player.closeInventory(); + DemonAPI.sendMessage(player,"师徒商店尚未开放.",Sound.ENTITY_VILLAGER_NO); + } + int page = inv.getItem(0).getAmount(); + if(rawSlot == 0) { + // 上一页按钮组件 + if(page >= 2 && page <= 5){ + openGui(player,page - 1); + } else { + DemonAPI.sendMessage(player,"已经是第一页了.",Sound.ENTITY_VILLAGER_NO); + } + } + if(rawSlot == 8) { + // 下一页按钮组件 + if(page >= 1 && page <= 4){ + openGui(player,page + 1); + } else { + DemonAPI.sendMessage(player,"已经是最后一页了.",Sound.ENTITY_VILLAGER_NO); + } + } + if(rawSlot >= 9 && rawSlot <= 53) { + ItemStack stack = e.getCurrentItem(); + if (!DemonAPI.itemIsNull(stack)) { + NbtItem nbt = new NbtItem(stack); + if (!nbt.hasKey("apprenticeName")) { + return; + } + String apprenticeName = nbt.getString("apprenticeName"); + PlayerManager playerManager = StMain.getPlayerManager(); + PlayerData playerData = playerManager.getPlayerData(playerName); + if(!playerData.isApprenticeExit(apprenticeName)){ + player.closeInventory(); + DemonAPI.sendMessage(player,"这个玩家貌似已经不是你的徒弟了喔~",Sound.ENTITY_VILLAGER_NO); + return; + } + int onlineTime = OnlineAPI.getTime(apprenticeName); + if(onlineTime < 120){ + int valueTime = 120 - onlineTime; + DemonAPI.sendMessage(player,"你的徒弟 §e"+apprenticeName+" §a还需要活跃 §b"+valueTime+"分钟 §a才能结算活跃收益.",Sound.ENTITY_VILLAGER_NO); + return; + } + if(playerData.isActiveReward(apprenticeName)){ + DemonAPI.sendMessage(player,"结算失败,每名徒弟每天只能结算一次活跃收益。",Sound.ENTITY_VILLAGER_NO); + return; + } + double defaultBonus = 5; + // 若玩家是贵族6 将获得积分 8点 + // 若玩家是贵族8 将获得积分 10点 + // 获取当前日期的星期 + DayOfWeek currentDayOfWeek = LocalDate.now().getDayOfWeek(); + // 如果今天是周一至周五,奖金提高30% + if (currentDayOfWeek != DayOfWeek.SATURDAY && currentDayOfWeek != DayOfWeek.SUNDAY) { + defaultBonus *= 1.3; + } + // 增加收益 + settlementIncomeD.add(playerName); + playerData.addIncomeValue(defaultBonus); + playerData.setActivePlayer(apprenticeName,true); + DemonAPI.sendMessage(player,"结算成功,获得徒弟活跃收益: §b§l"+String.format("%.2f",defaultBonus)+"师徒币",Sound.ENTITY_EXPERIENCE_ORB_PICKUP); + System.out.println("[师徒] 活跃激励 玩家 <" + playerName + ">获得" + String.format("%.2f",defaultBonus) + "师徒币奖励"); + if(!playerData.isChallengeGoal(apprenticeName)){ + int levelTarget = Config.reward_level_target; + int level = (int) DLevelAPI.getOffPlayer_Level(apprenticeName); + if(level >= levelTarget) { + playerData.addChallengeGoal(apprenticeName); + // 玩家完成一次挑战目标 + System.out.println("[师徒] 成就目标 玩家 <" + playerName + "> 将 " + apprenticeName + " 已带至 Lv."+levelTarget); + Bukkit.broadcastMessage("§c§l★ §a宗师 §e"+playerName+" §a已将他的徒弟 §6"+apprenticeName+" §a培养成了 §r鑄"); + } + } + } + } + } + } + + @EventHandler + public void onClose(InventoryCloseEvent e){ + Player player = (Player) e.getPlayer(); + if(e.getView().getTitle().equalsIgnoreCase(invTitle)){ + String playerName = player.getName(); + if(settlementIncomeD.contains(playerName)){ + PlayerManager playerManager = StMain.getPlayerManager(); + PlayerData playerData = playerManager.getPlayerData(playerName); + playerData.saveData(); + settlementIncomeD.remove(playerName); + } + } + } +} diff --git a/src/main/java/com/yaohun/shitu/listsener/PlayerListener.java b/src/main/java/com/yaohun/shitu/listsener/PlayerListener.java new file mode 100644 index 0000000..34f9569 --- /dev/null +++ b/src/main/java/com/yaohun/shitu/listsener/PlayerListener.java @@ -0,0 +1,45 @@ +package com.yaohun.shitu.listsener; + +import com.yaohun.shitu.StMain; +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.data.PlayerData; +import com.yaohun.shitu.manage.PlayerManager; +import com.yaohun.shitu.util.AttributeUtil; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener { + + @EventHandler + public void onJoin(PlayerJoinEvent e){ + Player player = e.getPlayer(); + String playerName = player.getName(); + PlayerManager playerManager = StMain.getPlayerManager(); + if(playerManager.isDisciple(playerName)) { + // 计算玩家是否已进入服务器超过60天 + int limitDay = Config.disciple_auto_remove_days; + long firstTime = player.getFirstPlayed() + (1000L * 60 * 60 * 24 * limitDay); + long nowTime = System.currentTimeMillis(); + if (nowTime >= firstTime) { + // 执行师徒关系解除 + String masterName = playerManager.getMasterName(playerName); + PlayerData playerData = playerManager.getPlayerData(masterName); + playerData.removeApprentice(playerName); + System.out.printf("[师徒] 玩家 " + playerName + " 因加入服务器超过<" + limitDay + "天> 已与(" + masterName + ")解除师徒关系."); + } else { + AttributeUtil.addAttribute(player); + } + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + AttributeUtil.removeAttribute(player); + PlayerManager playerManager = StMain.getPlayerManager(); + playerManager.saveData(player.getName(), true); + } +} diff --git a/src/main/java/com/yaohun/shitu/listsener/RechargeListener.java b/src/main/java/com/yaohun/shitu/listsener/RechargeListener.java new file mode 100644 index 0000000..06a9735 --- /dev/null +++ b/src/main/java/com/yaohun/shitu/listsener/RechargeListener.java @@ -0,0 +1,34 @@ +package com.yaohun.shitu.listsener; + +import com.yaohun.aurechargedata.event.RechargeEvent; +import com.yaohun.shitu.StMain; +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.data.PlayerData; +import com.yaohun.shitu.manage.PlayerManager; +import me.Demon.DemonPlugin.DemonAPI; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class RechargeListener implements Listener { + + @EventHandler + public void onRecharge(RechargeEvent event) { + if(event.getMoney() >= 30) { + String playerName = event.getPlayerName(); + PlayerManager playerManager = StMain.getPlayerManager(); + if (playerManager.isDisciple(playerName)) { + String masterName = playerManager.getMasterName(playerName); + PlayerData playerData = playerManager.getPlayerData(masterName); + double pointsValue = Math.round(event.getMoney() * Config.reward_recharge_scale); + playerData.addIncomeValue(pointsValue); + Player mentorPlayer = Bukkit.getPlayerExact(masterName); + System.out.println("[调试 - 师徒] 充值玩家: " + playerName + " 他的师傅<" + masterName + ">获得" + pointsValue + "师徒币奖励"); + if (mentorPlayer != null && mentorPlayer.isOnline()) { + DemonAPI.sendMessage(mentorPlayer, "获得徒弟的充值激励收益: §6" + pointsValue + "师徒币"); + } + } + } + } +} diff --git a/src/main/java/com/yaohun/shitu/manage/InviteManager.java b/src/main/java/com/yaohun/shitu/manage/InviteManager.java new file mode 100644 index 0000000..c9be55f --- /dev/null +++ b/src/main/java/com/yaohun/shitu/manage/InviteManager.java @@ -0,0 +1,91 @@ +package com.yaohun.shitu.manage; + +import com.yaohun.shitu.StMain; +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.data.PlayerData; +import com.yaohun.shitu.util.AttributeUtil; +import me.Demon.DemonPlugin.DemonAPI; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +public class InviteManager { + + + private static final Map inviteMap = new HashMap<>(); + + public static void sendInvite(Player master,Player target){ + String masterName = master.getName(); + String targetName = target.getName(); + inviteMap.put(targetName,masterName); + DemonAPI.sendMessage(master,"发送成功,已向 §e" + targetName + " §a发出拜师邀请.", Sound.ENTITY_EXPERIENCE_ORB_PICKUP); + DemonAPI.sendMessage(target,"你收到了来自 §e" + masterName + " §a发出的拜师邀请.",Sound.ENTITY_CAT_AMBIENT); + sendClickMessage(target,"§r §a§l【点击同意】 §r", "shitu accept"); + sendClickMessage(target,"§r §c§l【点击拒绝】 §r", "shitu deny"); + } + + private static void sendClickMessage(Player player, String message,String commadns) { + TextComponent tomessage = new TextComponent(message); + tomessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+commadns)); + tomessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§a斗§b魂§c帝§d国").create())); + player.spigot().sendMessage(tomessage); + } + + // 玩家处理拜师邀请 + public static boolean acceptInvite(Player player) { + String playerName = player.getName(); + String masterName = inviteMap.get(playerName); + if(masterName == null){ + DemonAPI.sendMessage(player,"没有需要处理的拜师邀请.",Sound.ENTITY_VILLAGER_NO); + return false; + } + PlayerManager playerManager = StMain.getPlayerManager(); + if(masterName.equalsIgnoreCase(playerName)){ + DemonAPI.sendMessage(player,"无法同意自己的拜师请求.",Sound.ENTITY_VILLAGER_NO); + return false; + } + if(playerManager.isDisciple(playerName)){ + DemonAPI.sendMessage(player,"接受失败,你已经有师傅了.",Sound.ENTITY_VILLAGER_NO); + return false; + } + PlayerData masterData = playerManager.getPlayerData(masterName); + if(masterData.getApprenticeSize() >= Config.master_max_disciple_size){ + DemonAPI.sendMessage(player,"接受失败,对方已收徒弟数量达到上限.",Sound.ENTITY_VILLAGER_NO); + return false; + } + masterData.setActivePlayer(playerName,true); + masterData.saveData(); + playerManager.setApprenticeMap(playerName,masterName); + + DemonAPI.sendMessage(player,"恭喜你已经成为 §e"+masterName+" §a的徒弟之一.",Sound.ENTITY_EXPERIENCE_ORB_PICKUP); + AttributeUtil.addAttribute(player); + + Player master = Bukkit.getPlayer(masterName); + if(master != null && master.isOnline()){ + DemonAPI.sendMessage(master,"玩家 §e"+playerName+" §a已同意你的拜师邀请.",Sound.ENTITY_EXPERIENCE_ORB_PICKUP); + } + return true; + } + + public static boolean denyInvite(Player player) { + String playerName = player.getName(); + String masterName = inviteMap.get(playerName); + if(masterName == null){ + DemonAPI.sendMessage(player,"没有需要处理的拜师邀请.",Sound.ENTITY_VILLAGER_NO); + return false; + } + DemonAPI.sendMessage(player,"你已拒绝 §e"+masterName+" §a的拜师邀请.",Sound.ENTITY_BLAZE_DEATH); + Player master = Bukkit.getPlayer(masterName); + if(master != null && master.isOnline()){ + DemonAPI.sendMessage(master,"玩家 §e"+playerName+" §a已拒绝你的拜师邀请.",Sound.ENTITY_BLAZE_DEATH); + } + return true; + } +} diff --git a/src/main/java/com/yaohun/shitu/manage/PlayerManager.java b/src/main/java/com/yaohun/shitu/manage/PlayerManager.java new file mode 100644 index 0000000..92d434a --- /dev/null +++ b/src/main/java/com/yaohun/shitu/manage/PlayerManager.java @@ -0,0 +1,89 @@ +package com.yaohun.shitu.manage; + +import com.yaohun.shitu.StMain; +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.data.PlayerData; +import me.Demon.DemonPlugin.DemonAPI; +import org.bukkit.Bukkit; +import org.serverct.ersha.jd.Ha; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class PlayerManager { + + private HashMap playerDatas = new HashMap<>(); + private HashMap apprenticeMap = new HashMap<>(); + + public PlayerManager(){ + // 载入所有师傅的数据 + File folder = new File(Config.pathData); + if (!folder.exists() || !folder.isDirectory()) { + return; + } + List ymlFiles = new ArrayList<>(); + DemonAPI.collectYmlFiles(folder, ymlFiles); + if (ymlFiles .isEmpty()) { + return; + } + // 逐个加载文件并提取 statistics 内容 + for (File file : ymlFiles) { + String fileName = file.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); + playerDatas.put(playerName, new PlayerData(playerName)); + } + for (PlayerData playerData : playerDatas.values()){ + List stringList = playerData.getApprenticeList(); + for (String name : stringList) { + apprenticeMap.put(name, playerData.getPlayerName()); + } + } + Bukkit.getConsoleSender().sendMessage("§6[师徒系统] §7已出师玩家: §f"+playerDatas.size()+"名"); + Bukkit.getConsoleSender().sendMessage("§6[师徒系统] §7已拜师玩家: §f"+apprenticeMap.size()+"名"); + } + + public void createData(String masterName){ + PlayerData playerData = new PlayerData(masterName); + playerDatas.put(masterName, playerData); + playerData.saveData(); + } + + public PlayerData getPlayerData(String masterName) { + return playerDatas.get(masterName); + } + + public void saveData(String playerName, boolean unload) { + if (!playerDatas.containsKey(playerName)) { + return; + } + PlayerData playerData = playerDatas.remove(playerName); + playerData.saveData(); + if (unload) { + playerDatas.remove(playerName); + } + } + + public void saveDataAll() { + for(PlayerData playerData : playerDatas.values()){ + playerData.saveData(); + } + } + + public boolean isMaster(String name){ + return playerDatas.containsKey(name); + } + + public void setApprenticeMap(String name, String mentorName){ + apprenticeMap.put(name, mentorName); + } + + public boolean isDisciple(String name){ + return apprenticeMap.containsKey(name); + } + + public String getMasterName(String name){ + return apprenticeMap.get(name); + } +} diff --git a/src/main/java/com/yaohun/shitu/util/AttributeUtil.java b/src/main/java/com/yaohun/shitu/util/AttributeUtil.java new file mode 100644 index 0000000..388aa62 --- /dev/null +++ b/src/main/java/com/yaohun/shitu/util/AttributeUtil.java @@ -0,0 +1,37 @@ +package com.yaohun.shitu.util; + +import com.yaohun.shitu.StMain; +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.manage.PlayerManager; +import org.bukkit.entity.Player; +import org.serverct.ersha.jd.AttributeAPI; +import org.serverct.ersha.jd.attribute.AttributeData; + +import java.util.Arrays; + +public class AttributeUtil { + + private static String ATTRIBUTE_SOURCE_NAME = "aumaster_exp"; + + public static void checkPlayer(Player player) { + AttributeData attributeData = AttributeAPI.getAttrData(player); + PlayerManager playerManager = StMain.getPlayerManager(); + boolean hasAttribute = attributeData.getApiAttributeList(ATTRIBUTE_SOURCE_NAME) != null; + if (playerManager.isDisciple(player.getName())) { + if (!hasAttribute) { + addAttribute(player); + } + } else if (hasAttribute) { + removeAttribute(player); + } + } + + public static void addAttribute(Player player) { + AttributeAPI.addAttribute(player, ATTRIBUTE_SOURCE_NAME, Config.reward_attribute); + } + + public static void removeAttribute(Player player) { + AttributeAPI.deleteAttribute(player, ATTRIBUTE_SOURCE_NAME); + } + +} diff --git a/src/main/java/com/yaohun/shitu/util/RankUtil.java b/src/main/java/com/yaohun/shitu/util/RankUtil.java new file mode 100644 index 0000000..1c1f566 --- /dev/null +++ b/src/main/java/com/yaohun/shitu/util/RankUtil.java @@ -0,0 +1,69 @@ +package com.yaohun.shitu.util; + +import com.yaohun.shitu.config.Config; +import com.yaohun.shitu.data.PlayerData; +import me.Demon.DemonPlugin.DemonAPI; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.serverct.ersha.jd.Ya; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.text.DecimalFormat; +import java.util.*; +import java.util.stream.Collectors; + +public class RankUtil { + + public static void checkAcceptingApprenticesTop(CommandSender sender){ + File folder = new File(Config.pathData); + if (!folder.exists() || !folder.isDirectory()) { + sender.sendMessage("[师徒] 还没有玩家进行出师"); + return; + } + List ymlFiles = new ArrayList<>(); + DemonAPI.collectYmlFiles(folder, ymlFiles); + if (ymlFiles .isEmpty()) { + sender.sendMessage("[师徒] 还没有玩家进行出师"); + return; + } + HashMap valueMap = new HashMap<>(); + HashMap hashMap = new HashMap<>(); + // 逐个加载文件并提取 statistics 内容 + for (File file : ymlFiles) { + String fileName = file.getName(); + String playerName = fileName.substring(0, fileName.length() - 4); + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + double incomeValue = config.getDouble("incomeValue"); + ConfigurationSection section = config.getConfigurationSection("Apprentice"); + if(section == null){ + continue; + } + int amount = section.getKeys(false).size(); + hashMap.put(playerName,amount); + valueMap.put(playerName,incomeValue); + } + + LinkedHashMap sortedMap = hashMap.entrySet() + .stream() + .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) + .collect(Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue, + (e1, e2) -> e1, + LinkedHashMap::new + )); + sender.sendMessage(""); + sender.sendMessage("§e§l★ §a师徒激励计划-收益排行榜"); + int rank = 1; + for (String playerName : sortedMap.keySet()){ + double value = Math.round(valueMap.get(playerName) / 10); + int amount = sortedMap.get(playerName); + sender.sendMessage("§a§l★ §7第 §e" + rank + " §7名: §e" + playerName + " §f收益: §6"+new DecimalFormat(",###.##").format(value)+"元 §f徒弟: §e"+amount+"名"); + rank++; + } + sender.sendMessage(""); + } +} diff --git a/src/main/java/com/yaohun/shitu/util/StackUtil.java b/src/main/java/com/yaohun/shitu/util/StackUtil.java new file mode 100644 index 0000000..0095085 --- /dev/null +++ b/src/main/java/com/yaohun/shitu/util/StackUtil.java @@ -0,0 +1,113 @@ +package com.yaohun.shitu.util; + +import com.yaohun.aurechargedata.api.RechargeAPI; +import com.yaohun.aurechargedata.util.TimeType; +import com.yaohun.demonlogintime.api.LoginTimeAPI; +import com.yaohun.onlinereward.api.OnlineAPI; +import com.yaohun.shitu.data.PlayerData; +import me.Demon.DemonLevels.api.DLevelAPI; +import me.Demon.DemonPlugin.DemonAPI; +import me.Demon.DemonPlugin.data.NbtItem; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.List; + +public class StackUtil { + + public static ItemStack getApprenticeSize(PlayerData playerData){ + ItemStack stack = new ItemStack(Material.DIAMOND); + ItemMeta meta = stack.getItemMeta(); + int value = (int) playerData.getIncomeValue() / 10; + meta.setDisplayName("§l"+value); + List lore = new ArrayList<>(); + lore.add("§l"+playerData.getApprenticeSize()); + meta.setLore(lore); + stack.setItemMeta(meta); + return stack; + } + + public static ItemStack getRewardChest(){ + ItemStack stack = new ItemStack(Material.CHEST); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName("Reward Chest"); + stack.setItemMeta(meta); + return stack; + } + + public static ItemStack getPointsShop(){ + ItemStack stack = new ItemStack(Material.ENDER_CHEST); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName("Points Shop"); + stack.setItemMeta(meta); + return stack; + } + + public static ItemStack turnThePage(String name,int page){ + ItemStack stack = new ItemStack(Material.ARROW); + stack.setAmount(page); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(name); + stack.setItemMeta(meta); + return stack; + } + + public static ItemStack getApprentice(String name){ + ItemStack stack = new ItemStack(Material.GOLD_SWORD); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName("§l"+name); + List lore = new ArrayList<>(); + lore.add("§a§l★§7名称: §6§l"+name); + int level = (int) DLevelAPI.getOffPlayer_Level(name); + lore.add("§a§l★§7等级: §dLv."+level); + int minute = OnlineAPI.getTime(name); + lore.add("§a§l★§7今日活跃: §a"+minute+"分钟"); + int recharge = RechargeAPI.getRechargeData(name, TimeType.MONTHLY); + lore.add("§a§l★§7本月储值: §b"+recharge+"软妹币"); + long loginTime = LoginTimeAPI.getLoginTime(name); + lore.add("§a§l★§7最后上线: §5"+ DemonAPI.LongToStringData(loginTime,"yyyy年MM月dd日 HH:mm")); + meta.setLore(lore); + stack.setItemMeta(meta); + NbtItem nbtItem = new NbtItem(stack); + if(level >= 90){ + nbtItem.setString("bottomMap","Tudi_1"); + } else if(level >= 60){ + nbtItem.setString("bottomMap","Tudi_2"); + } else { + nbtItem.setString("bottomMap","Tudi_3"); + } + return nbtItem.getItem(); + } + + public static ItemStack getActiveIncome(PlayerData playerData,String name){ + int minute = OnlineAPI.getTime(name); + ItemStack stack = new ItemStack(Material.WATCH); + double progress = (double) minute / 120; + if(progress >= 1){ + progress = 1; + } else { + progress = Math.round(progress * 100.0) / 100.0; + } + // 若奖励已领取则设置为2 + if(playerData.isActiveReward(name)) { + stack.setAmount(2); + } else { + stack.setAmount(1); + } + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(String.valueOf(progress)); + + List lore = new ArrayList<>(); + lore.add("§a§l★§7名称: §6§l"+name); + int totalMinute = OnlineAPI.getTimeTotal(name); + lore.add("§a§l★§7今日活跃: §a"+minute+"分钟"); + lore.add("§a§l★§7总计活跃: §c"+totalMinute+"分钟"); + meta.setLore(lore); + stack.setItemMeta(meta); + NbtItem nbtItem = new NbtItem(stack); + nbtItem.setString("apprenticeName", name); + return nbtItem.getItem(); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..f0d4b46 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,31 @@ +disciple: + # 徒弟入服超过 N 天后自动解除关系 + autoRemoveDays: 30 + # 玩家等级 ≤ 该值时才允许拜师 + maxLevelLimit: 80 + # 玩家入服时间 ≤ N 天(单位:天)才允许拜师 + maxJoinDays: 30 +master: + # 玩家等级 ≥ 该值时才可收徒 + levelLimit: 90 + # 玩家注册时间 ≥ N 天时才可收徒 + joinDaysLimit: 30 + # 每位师傅最多拥有的徒弟数量 + maxDiscipleSize: 25 + # 徒弟离线超过 3 天后,师傅可解除关系 + removeAfterOffline: 3 +rewards: + # 徒弟单笔充值超过30元师傅可以获得返利 X % + rechargeScale: 0.05 + # 徒弟达到 X 级后则算完成1个成就目标 + levelTarget: 80 + # 徒弟上线时可获得的属性加成 + attributeList: + - '经验加成: 15%' + # 当徒弟达到指定人数要求后给予师傅的奖励命令组 + rewardList_1: + - "eco give %player% 100" + rewardList_2: + - "eco give %player% 100" + rewardList_3: + - "eco give %player% 100" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..c9b2ccb --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,7 @@ +name: DemonShiTu +main: com.yaohun.shitu.StMain +version: 3.0.2 +commands: + shitu: + aliases: [st] + stadmin: