commit f344fa70d6813a99cedae764235e8e62de86f168 Author: Kyoukawa Meishin Date: Thu Oct 16 21:52:39 2025 +0800 StatusSystem的首次提交 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..480bdf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +.kotlin + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..eda147d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ed4c5b9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + com.mmlsystem + StatusSystem + 1.1 + + + + central + https://repo.maven.apache.org/maven2/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + jitpack-io + https://jitpack.io/ + + + + + + org.spigotmc + spigot-api + 1.21.8-R0.1-SNAPSHOT + provided + + + com.github.MilkBowl + VaultAPI + 1.7 + provided + + + org.jetbrains + annotations + 24.1.0 + compile + + + diff --git a/src/main/java/com/mmlsystem/StatusSystem/Foundation.java b/src/main/java/com/mmlsystem/StatusSystem/Foundation.java new file mode 100644 index 0000000..a09abdc --- /dev/null +++ b/src/main/java/com/mmlsystem/StatusSystem/Foundation.java @@ -0,0 +1,78 @@ +package com.mmlsystem.StatusSystem; + +import net.milkbowl.vault.economy.Economy; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scoreboard.*; + +public class Foundation extends JavaPlugin { + public static Economy econ; + + @Override + public void onEnable() { + getLogger().info("我为Type-C大人举大旗"); + getLogger().info("符玄矮矮的也很可爱"); + if (!setupEconomy()) { + getLogger().severe("忘记安装经济插件的腐竹是屑"); + getLogger().severe("请先安装Vault 1.7+或VaultUnlocked插件以继续操作"); + getServer().getPluginManager().disablePlugin(this); + return; + } + getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this); + getLogger().info("插件启用成功。"); + } + + @Override + public void onDisable() { + getLogger().info("插件禁用成功。"); + } + + private boolean setupEconomy() { + if (getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } + RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + econ = rsp.getProvider(); + return true; + } + + public void setScoreboardUI(Player player) { + ScoreboardManager manager = Bukkit.getScoreboardManager(); + Scoreboard board = manager.getNewScoreboard(); + + Objective objective = board.registerNewObjective("info", "dummy", ChatColor.GOLD + "✦ 统计数据 ✦"); + objective.setDisplaySlot(DisplaySlot.SIDEBAR); + + objective.getScore(ChatColor.AQUA + "金币").setScore(5); + objective.getScore(ChatColor.RED + " " + econ.getBalance(player) ).setScore(4); + objective.getScore(ChatColor.AQUA + "当前在线人数").setScore(3); + objective.getScore(ChatColor.GREEN + " " + Bukkit.getOnlinePlayers().size()).setScore(2); + objective.getScore(ChatColor.GRAY + "mymc.life").setScore(1); + + player.setScoreboard(board); + + new BukkitRunnable() { + @Override + public void run() { + if (!player.isOnline()) { + cancel(); + return; + } + for (String entry : board.getEntries()) { + if (entry.startsWith(ChatColor.RED + " ") || entry.startsWith(ChatColor.GREEN + " ")) { // 匹配你旧的在线人数行 + board.resetScores(entry); + } + } + objective.getScore(ChatColor.RED + " " + econ.getBalance(player) ).setScore(4); + objective.getScore(ChatColor.GREEN + " " + Bukkit.getOnlinePlayers().size()).setScore(2); + } + }.runTaskTimer(this, 0L, 100L); + } +} diff --git a/src/main/java/com/mmlsystem/StatusSystem/PlayerJoinListener.java b/src/main/java/com/mmlsystem/StatusSystem/PlayerJoinListener.java new file mode 100644 index 0000000..bc66a27 --- /dev/null +++ b/src/main/java/com/mmlsystem/StatusSystem/PlayerJoinListener.java @@ -0,0 +1,22 @@ +package com.mmlsystem.StatusSystem; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class PlayerJoinListener implements Listener { + private final Foundation plugin; + + public PlayerJoinListener(Foundation plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + try { + plugin.setScoreboardUI(event.getPlayer()); + } catch (Exception e) { + plugin.getLogger().severe(e.getMessage()); + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..37e00a7 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: StatusSystem +main: com.mmlsystem.StatusSystem.Foundation +version: 1.1 +api-version: 1.21 +author: 杏川铭心 +description: 提供服务器计分板UI功能。 \ No newline at end of file