Compare commits

..

No commits in common. "master" and "v2.1.1" have entirely different histories.

13 changed files with 21 additions and 110 deletions

View File

@ -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 21"
- name: "Set up JDK 17"
uses: https://ssl.lunadeer.cn:14446/actions/setup-java@v3
with:
java-version: '21'
java-version: '17'
distribution: 'zulu'
cache: maven
- name: "Build with Maven"

View File

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

View File

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

View File

@ -22,7 +22,6 @@ 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.*;
@ -54,7 +53,6 @@ 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);

View File

@ -3,6 +3,7 @@ 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;
@ -17,10 +18,6 @@ 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]);

View File

@ -2,8 +2,10 @@ 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;
@ -24,10 +26,6 @@ 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]);

View File

@ -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 {

View File

@ -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.getPrefixChatFormat());
String formated = PlaceholderAPI.setPlaceholders(event.getPlayer(), EssentialsD.config.getPrefixFormat());
formated += event.getMessage();
EssentialsD.instance.getServer().broadcastMessage(formated);
}

View File

@ -57,8 +57,7 @@ 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_chat_format = _file.getString("Prefix.ChatFormat", "<%player_name%> ");
_prefix_tab_format = _file.getString("Prefix.TabFormat", "%player_name%");
_prefix_format = _file.getString("Prefix.Format", "<%player_name%> ");
saveAll(); // save all to make sure all values are valid
}
@ -93,8 +92,7 @@ public class ConfigManager {
_file.set("Database.User", _db_user);
_file.set("Database.Pass", _db_pass);
_file.set("Prefix.Enable", _prefix_enable);
_file.set("Prefix.ChatFormat", _prefix_chat_format);
_file.set("Prefix.TabFormat", _prefix_tab_format);
_file.set("Prefix.Format", _prefix_format);
_plugin.saveConfig();
}
@ -325,26 +323,16 @@ public class ConfigManager {
_plugin.saveConfig();
}
public String getPrefixChatFormat() {
return _prefix_chat_format;
public String getPrefixFormat() {
return _prefix_format;
}
public void setPrefixChatFormat(String format) {
_prefix_chat_format = format;
public void setPrefixFormat(String format) {
_prefix_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;
@ -385,6 +373,5 @@ public class ConfigManager {
// prefix
private Boolean _prefix_enable;
private String _prefix_chat_format;
private String _prefix_tab_format;
private String _prefix_format;
}

View File

@ -1,67 +0,0 @@
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,7 +1,6 @@
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;

View File

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

View File

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