Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
cd9f4549b2 | |||
6937a15225 | |||
937f9fcd8f | |||
06aeb33f50 | |||
6381d51950 | |||
b44e5a658b | |||
43dc8f0abc | |||
2da5d164d7 |
@ -15,10 +15,10 @@ jobs:
|
||||
fetch-depth: 0
|
||||
- name: "Set up Maven"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4
|
||||
- name: "Set up JDK 17"
|
||||
- name: "Set up JDK 21"
|
||||
uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
distribution: 'zulu'
|
||||
cache: maven
|
||||
- name: "Build with Maven"
|
||||
|
@ -7,7 +7,7 @@ EssentialsX,其中D代表Deer。
|
||||
|
||||
## 支持版本
|
||||
|
||||
- 1.20.1+ (Folia)
|
||||
- 1.21.1+ (Folia)
|
||||
|
||||
## 安装方法
|
||||
|
||||
|
8
pom.xml
8
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>EssentialsD</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<version>2.3.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EssentialsD</name>
|
||||
@ -78,9 +78,9 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.folia</groupId>
|
||||
<artifactId>folia-api</artifactId>
|
||||
<version>1.20.1-R0.1-SNAPSHOT</version>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -22,6 +22,7 @@ import cn.lunadeer.essentialsd.commands.weather.Sun;
|
||||
import cn.lunadeer.essentialsd.events.*;
|
||||
import cn.lunadeer.essentialsd.managers.ConfigManager;
|
||||
import cn.lunadeer.essentialsd.managers.DatabaseTables;
|
||||
import cn.lunadeer.essentialsd.managers.TabListUpdater;
|
||||
import cn.lunadeer.essentialsd.managers.TeleportManager;
|
||||
import cn.lunadeer.essentialsd.recipes.*;
|
||||
import cn.lunadeer.minecraftpluginutils.*;
|
||||
@ -53,6 +54,7 @@ public final class EssentialsD extends JavaPlugin {
|
||||
if (config.getPrefixEnable()) {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new ChatPrefixEvent(), this);
|
||||
new TabListUpdater(); // 更新 TabList
|
||||
} else {
|
||||
XLogger.warn("未找到 PlaceholderAPI 插件, 无法使用聊天前缀功能, 已自动关闭前缀功能");
|
||||
config.setPrefixEnable(false);
|
||||
|
@ -3,7 +3,6 @@ package cn.lunadeer.essentialsd.commands.warp;
|
||||
import cn.lunadeer.essentialsd.dtos.WarpPoint;
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -18,6 +17,10 @@ public class DelWarp implements TabExecutor {
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
if (strings.length != 1) {
|
||||
Notification.error(commandSender, "用法: /delwarp <name>");
|
||||
return true;
|
||||
}
|
||||
WarpPoint point = WarpPoint.selectByName(strings[0]);
|
||||
if (point == null) {
|
||||
Notification.error(commandSender, "传送点 %s 不存在", strings[0]);
|
||||
|
@ -2,10 +2,8 @@ package cn.lunadeer.essentialsd.commands.warp;
|
||||
|
||||
import cn.lunadeer.essentialsd.EssentialsD;
|
||||
import cn.lunadeer.essentialsd.dtos.WarpPoint;
|
||||
import cn.lunadeer.essentialsd.managers.TeleportManager;
|
||||
import cn.lunadeer.minecraftpluginutils.Notification;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -26,6 +24,10 @@ public class Warp implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) commandSender;
|
||||
if (strings.length != 1) {
|
||||
Notification.error(commandSender, "用法: /warp <name>");
|
||||
return true;
|
||||
}
|
||||
WarpPoint point = WarpPoint.selectByName(strings[0]);
|
||||
if (point == null) {
|
||||
Notification.error(commandSender, "传送点 %s 不存在", strings[0]);
|
||||
|
@ -16,11 +16,11 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.EntityDismountEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spigotmc.event.entity.EntityDismountEvent;
|
||||
|
||||
public class ChairEvent implements Listener {
|
||||
|
||||
|
@ -11,7 +11,7 @@ public class ChatPrefixEvent implements Listener {
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
event.setCancelled(true);
|
||||
String formated = PlaceholderAPI.setPlaceholders(event.getPlayer(), EssentialsD.config.getPrefixFormat());
|
||||
String formated = PlaceholderAPI.setPlaceholders(event.getPlayer(), EssentialsD.config.getPrefixChatFormat());
|
||||
formated += event.getMessage();
|
||||
EssentialsD.instance.getServer().broadcastMessage(formated);
|
||||
}
|
||||
|
@ -57,7 +57,8 @@ public class ConfigManager {
|
||||
_db_user = _file.getString("Database.User", "postgres");
|
||||
_db_pass = _file.getString("Database.Pass", "postgres");
|
||||
_prefix_enable = _file.getBoolean("Prefix.Enable", true);
|
||||
_prefix_format = _file.getString("Prefix.Format", "<%player_name%> ");
|
||||
_prefix_chat_format = _file.getString("Prefix.ChatFormat", "<%player_name%> ");
|
||||
_prefix_tab_format = _file.getString("Prefix.TabFormat", "%player_name%");
|
||||
saveAll(); // save all to make sure all values are valid
|
||||
}
|
||||
|
||||
@ -92,7 +93,8 @@ public class ConfigManager {
|
||||
_file.set("Database.User", _db_user);
|
||||
_file.set("Database.Pass", _db_pass);
|
||||
_file.set("Prefix.Enable", _prefix_enable);
|
||||
_file.set("Prefix.Format", _prefix_format);
|
||||
_file.set("Prefix.ChatFormat", _prefix_chat_format);
|
||||
_file.set("Prefix.TabFormat", _prefix_tab_format);
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
@ -323,16 +325,26 @@ public class ConfigManager {
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
public String getPrefixFormat() {
|
||||
return _prefix_format;
|
||||
public String getPrefixChatFormat() {
|
||||
return _prefix_chat_format;
|
||||
}
|
||||
|
||||
public void setPrefixFormat(String format) {
|
||||
_prefix_format = format;
|
||||
public void setPrefixChatFormat(String format) {
|
||||
_prefix_chat_format = format;
|
||||
_file.set("Prefix.Format", format);
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
public String getPrefixTabFormat() {
|
||||
return _prefix_tab_format;
|
||||
}
|
||||
|
||||
public void setPrefixTabFormat(String format) {
|
||||
_prefix_tab_format = format;
|
||||
_file.set("Prefix.TabFormat", format);
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
|
||||
private final EssentialsD _plugin;
|
||||
private FileConfiguration _file;
|
||||
@ -373,5 +385,6 @@ public class ConfigManager {
|
||||
|
||||
// prefix
|
||||
private Boolean _prefix_enable;
|
||||
private String _prefix_format;
|
||||
private String _prefix_chat_format;
|
||||
private String _prefix_tab_format;
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
package cn.lunadeer.essentialsd.managers;
|
||||
|
||||
import cn.lunadeer.essentialsd.EssentialsD;
|
||||
import cn.lunadeer.minecraftpluginutils.Scheduler;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TabListUpdater {
|
||||
|
||||
public static TabListUpdater instance;
|
||||
|
||||
public TabListUpdater() {
|
||||
instance = this;
|
||||
Scheduler.runTaskRepeatAsync(this::update, 0, 40);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
|
||||
Map<UUID, String> formatedNames = new HashMap<>();
|
||||
|
||||
int longestFormatedStringLength = 0;
|
||||
|
||||
for (Player player : players) {
|
||||
String formated = PlaceholderAPI.setPlaceholders(player, EssentialsD.config.getPrefixTabFormat());
|
||||
if (length(formated) > longestFormatedStringLength) {
|
||||
longestFormatedStringLength = length(formated);
|
||||
}
|
||||
formatedNames.put(player.getUniqueId(), formated);
|
||||
}
|
||||
// <span> 将会被替换为填充空格 " " 用于保证长度一致
|
||||
for (Player player : players) {
|
||||
String formated = formatedNames.get(player.getUniqueId());
|
||||
int formatedLength = length(formated);
|
||||
int spaceLength = longestFormatedStringLength - formatedLength;
|
||||
StringBuilder space = new StringBuilder();
|
||||
for (int i = 0; i < spaceLength; i++) {
|
||||
space.append(" ");
|
||||
}
|
||||
player.setPlayerListName(formated.replace("<span>", space.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static int length(String value) {
|
||||
int valueLength = 0;
|
||||
String chinese = "[\u0391-\uFFE5]";
|
||||
/* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
/* 获取一个字符 */
|
||||
String temp = value.substring(i, i + 1);
|
||||
/* 判断是否为中文字符 */
|
||||
if (temp.matches(chinese)) {
|
||||
/* 中文字符长度为2 */
|
||||
valueLength += 2;
|
||||
} else {
|
||||
/* 其他字符长度为1 */
|
||||
valueLength += 1;
|
||||
}
|
||||
}
|
||||
return valueLength;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cn.lunadeer.essentialsd.recipes;
|
||||
|
||||
import cn.lunadeer.essentialsd.EssentialsD;
|
||||
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
@ -58,7 +58,8 @@ HomeLimit:
|
||||
# prefix (需要 PlaceholderAPI 支持)
|
||||
Prefix:
|
||||
Enable: false
|
||||
Format: '<%player_name%> '
|
||||
ChatFormat: '<%player_name%> '
|
||||
TabFormat: '%player_name%'
|
||||
|
||||
Debug: false
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: EssentialsD
|
||||
version: '${project.version}'
|
||||
main: cn.lunadeer.essentialsd.EssentialsD
|
||||
api-version: '1.20'
|
||||
api-version: '1.21'
|
||||
description: Deer's Essentials
|
||||
website: https://lunadeer.cn
|
||||
load: STARTUP
|
||||
|
Loading…
Reference in New Issue
Block a user