Compare commits

...

8 Commits

Author SHA1 Message Date
cd9f4549b2 尝试增加tab列表对齐功能(暂未成功) 2024-08-23 17:53:05 +08:00
6937a15225 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	pom.xml
2024-08-23 10:31:49 +08:00
937f9fcd8f 实现了tab papi功能
Some checks failed
Java CI-CD with Maven / build (push) Failing after 4m10s
2024-08-23 10:30:49 +08:00
06aeb33f50 修复了warp在不指定传送点时没有提示而是报错问题
All checks were successful
Java CI-CD with Maven / build (push) Successful in 13m24s
2024-08-18 12:25:06 +08:00
6381d51950 测试完成聊天前缀
All checks were successful
Java CI-CD with Maven / build (push) Successful in 11m3s
2024-08-11 12:00:40 +08:00
b44e5a658b Merge remote-tracking branch 'origin/master'
# Conflicts:
#	pom.xml
#	src/main/java/cn/lunadeer/essentialsd/events/ChatPrefixEvent.java
2024-08-11 11:58:41 +08:00
43dc8f0abc 更新 api 版本至 1.21.1 2024-08-11 02:34:39 +08:00
2da5d164d7 更新版本 2024-08-10 23:33:50 +08:00
13 changed files with 110 additions and 21 deletions

View File

@ -15,10 +15,10 @@ jobs:
fetch-depth: 0 fetch-depth: 0
- name: "Set up Maven" - name: "Set up Maven"
uses: https://ssl.lunadeer.cn:14446/actions/setup-maven@v4 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 uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
with: with:
java-version: '17' java-version: '21'
distribution: 'zulu' distribution: 'zulu'
cache: maven cache: maven
- name: "Build with Maven" - name: "Build with Maven"

View File

@ -7,7 +7,7 @@ EssentialsX其中D代表Deer。
## 支持版本 ## 支持版本
- 1.20.1+ (Folia) - 1.21.1+ (Folia)
## 安装方法 ## 安装方法

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId> <groupId>cn.lunadeer</groupId>
<artifactId>EssentialsD</artifactId> <artifactId>EssentialsD</artifactId>
<version>2.1.1</version> <version>2.3.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>EssentialsD</name> <name>EssentialsD</name>
@ -78,9 +78,9 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>dev.folia</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>folia-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version> <version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -22,6 +22,7 @@ import cn.lunadeer.essentialsd.commands.weather.Sun;
import cn.lunadeer.essentialsd.events.*; import cn.lunadeer.essentialsd.events.*;
import cn.lunadeer.essentialsd.managers.ConfigManager; import cn.lunadeer.essentialsd.managers.ConfigManager;
import cn.lunadeer.essentialsd.managers.DatabaseTables; import cn.lunadeer.essentialsd.managers.DatabaseTables;
import cn.lunadeer.essentialsd.managers.TabListUpdater;
import cn.lunadeer.essentialsd.managers.TeleportManager; import cn.lunadeer.essentialsd.managers.TeleportManager;
import cn.lunadeer.essentialsd.recipes.*; import cn.lunadeer.essentialsd.recipes.*;
import cn.lunadeer.minecraftpluginutils.*; import cn.lunadeer.minecraftpluginutils.*;
@ -53,6 +54,7 @@ public final class EssentialsD extends JavaPlugin {
if (config.getPrefixEnable()) { if (config.getPrefixEnable()) {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
Bukkit.getPluginManager().registerEvents(new ChatPrefixEvent(), this); Bukkit.getPluginManager().registerEvents(new ChatPrefixEvent(), this);
new TabListUpdater(); // 更新 TabList
} else { } else {
XLogger.warn("未找到 PlaceholderAPI 插件, 无法使用聊天前缀功能, 已自动关闭前缀功能"); XLogger.warn("未找到 PlaceholderAPI 插件, 无法使用聊天前缀功能, 已自动关闭前缀功能");
config.setPrefixEnable(false); config.setPrefixEnable(false);

View File

@ -3,7 +3,6 @@ package cn.lunadeer.essentialsd.commands.warp;
import cn.lunadeer.essentialsd.dtos.WarpPoint; import cn.lunadeer.essentialsd.dtos.WarpPoint;
import cn.lunadeer.minecraftpluginutils.Notification; import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -18,6 +17,10 @@ public class DelWarp implements TabExecutor {
*/ */
@Override @Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { 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]); WarpPoint point = WarpPoint.selectByName(strings[0]);
if (point == null) { if (point == null) {
Notification.error(commandSender, "传送点 %s 不存在", strings[0]); Notification.error(commandSender, "传送点 %s 不存在", strings[0]);

View File

@ -2,10 +2,8 @@ package cn.lunadeer.essentialsd.commands.warp;
import cn.lunadeer.essentialsd.EssentialsD; import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.essentialsd.dtos.WarpPoint; import cn.lunadeer.essentialsd.dtos.WarpPoint;
import cn.lunadeer.essentialsd.managers.TeleportManager;
import cn.lunadeer.minecraftpluginutils.Notification; import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,6 +24,10 @@ public class Warp implements TabExecutor {
return true; return true;
} }
Player player = (Player) commandSender; Player player = (Player) commandSender;
if (strings.length != 1) {
Notification.error(commandSender, "用法: /warp <name>");
return true;
}
WarpPoint point = WarpPoint.selectByName(strings[0]); WarpPoint point = WarpPoint.selectByName(strings[0]);
if (point == null) { if (point == null) {
Notification.error(commandSender, "传送点 %s 不存在", strings[0]); Notification.error(commandSender, "传送点 %s 不存在", strings[0]);

View File

@ -16,11 +16,11 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDismountEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.spigotmc.event.entity.EntityDismountEvent;
public class ChairEvent implements Listener { public class ChairEvent implements Listener {

View File

@ -11,7 +11,7 @@ public class ChatPrefixEvent implements Listener {
@EventHandler @EventHandler
public void onChat(AsyncPlayerChatEvent event) { public void onChat(AsyncPlayerChatEvent event) {
event.setCancelled(true); event.setCancelled(true);
String formated = PlaceholderAPI.setPlaceholders(event.getPlayer(), EssentialsD.config.getPrefixFormat()); String formated = PlaceholderAPI.setPlaceholders(event.getPlayer(), EssentialsD.config.getPrefixChatFormat());
formated += event.getMessage(); formated += event.getMessage();
EssentialsD.instance.getServer().broadcastMessage(formated); EssentialsD.instance.getServer().broadcastMessage(formated);
} }

View File

@ -57,7 +57,8 @@ public class ConfigManager {
_db_user = _file.getString("Database.User", "postgres"); _db_user = _file.getString("Database.User", "postgres");
_db_pass = _file.getString("Database.Pass", "postgres"); _db_pass = _file.getString("Database.Pass", "postgres");
_prefix_enable = _file.getBoolean("Prefix.Enable", true); _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 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.User", _db_user);
_file.set("Database.Pass", _db_pass); _file.set("Database.Pass", _db_pass);
_file.set("Prefix.Enable", _prefix_enable); _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(); _plugin.saveConfig();
} }
@ -323,16 +325,26 @@ public class ConfigManager {
_plugin.saveConfig(); _plugin.saveConfig();
} }
public String getPrefixFormat() { public String getPrefixChatFormat() {
return _prefix_format; return _prefix_chat_format;
} }
public void setPrefixFormat(String format) { public void setPrefixChatFormat(String format) {
_prefix_format = format; _prefix_chat_format = format;
_file.set("Prefix.Format", format); _file.set("Prefix.Format", format);
_plugin.saveConfig(); _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 final EssentialsD _plugin;
private FileConfiguration _file; private FileConfiguration _file;
@ -373,5 +385,6 @@ public class ConfigManager {
// prefix // prefix
private Boolean _prefix_enable; private Boolean _prefix_enable;
private String _prefix_format; private String _prefix_chat_format;
private String _prefix_tab_format;
} }

View File

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

View File

@ -1,6 +1,7 @@
package cn.lunadeer.essentialsd.recipes; package cn.lunadeer.essentialsd.recipes;
import cn.lunadeer.essentialsd.EssentialsD; import cn.lunadeer.essentialsd.EssentialsD;
import cn.lunadeer.minecraftpluginutils.XLogger;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;

View File

@ -58,7 +58,8 @@ HomeLimit:
# prefix (需要 PlaceholderAPI 支持) # prefix (需要 PlaceholderAPI 支持)
Prefix: Prefix:
Enable: false Enable: false
Format: '<%player_name%> ' ChatFormat: '<%player_name%> '
TabFormat: '%player_name%'
Debug: false Debug: false

View File

@ -1,7 +1,7 @@
name: EssentialsD name: EssentialsD
version: '${project.version}' version: '${project.version}'
main: cn.lunadeer.essentialsd.EssentialsD main: cn.lunadeer.essentialsd.EssentialsD
api-version: '1.20' api-version: '1.21'
description: Deer's Essentials description: Deer's Essentials
website: https://lunadeer.cn website: https://lunadeer.cn
load: STARTUP load: STARTUP