实现了prefix功能(未测试)
This commit is contained in:
parent
50c8d8812a
commit
b71fec6329
10
pom.xml
10
pom.xml
@ -70,6 +70,10 @@
|
||||
<id>lunadeer-repo</id>
|
||||
<url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -90,5 +94,11 @@
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -38,7 +38,6 @@ public final class EssentialsD extends JavaPlugin {
|
||||
instance = this;
|
||||
new XLogger(instance);
|
||||
config = new ConfigManager(instance);
|
||||
XLogger.setDebug(config.isDebug());
|
||||
new Notification(instance);
|
||||
database = new DatabaseManager(this,
|
||||
DatabaseManager.TYPE.valueOf(config.getDbType().toUpperCase()),
|
||||
@ -51,6 +50,15 @@ public final class EssentialsD extends JavaPlugin {
|
||||
new Scheduler(this);
|
||||
tpManager = new TeleportManager();
|
||||
|
||||
if (config.getPrefixEnable()) {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
Bukkit.getPluginManager().registerEvents(new ChatPrefixEvent(), this);
|
||||
} else {
|
||||
XLogger.warn("未找到 PlaceholderAPI 插件, 无法使用聊天前缀功能, 已自动关闭前缀功能");
|
||||
config.setPrefixEnable(false);
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new InvisibleItemFrameEvent(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ChairEvent(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ArmorStandHandsEvent(), this);
|
||||
|
@ -0,0 +1,19 @@
|
||||
package cn.lunadeer.essentialsd.events;
|
||||
|
||||
import cn.lunadeer.essentialsd.EssentialsD;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class ChatPrefixEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event) {
|
||||
event.setCancelled(true);
|
||||
String formated = PlaceholderAPI.setPlaceholders(event.getPlayer(), EssentialsD.config.getPrefixFormat());
|
||||
EssentialsD.instance.getServer().sendMessage(Component.text(formated).append(event.message()));
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ public class ConfigManager {
|
||||
_plugin.reloadConfig();
|
||||
_file = _plugin.getConfig();
|
||||
_debug = _file.getBoolean("Debug", false);
|
||||
XLogger.setDebug(isDebug());
|
||||
_check_update = _file.getBoolean("CheckUpdate", true);
|
||||
_exp_bottle_ratio = (float) _file.getDouble("ExpBottleRatio", 1.0);
|
||||
_combine_exp_orbs_enable = _file.getBoolean("CombineExpOrbs.Enable", false);
|
||||
@ -55,6 +56,44 @@ public class ConfigManager {
|
||||
_db_name = _file.getString("Database.Name", "dominion");
|
||||
_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%> ");
|
||||
saveAll(); // save all to make sure all values are valid
|
||||
}
|
||||
|
||||
private void saveAll() {
|
||||
_file.set("Debug", _debug);
|
||||
_file.set("CheckUpdate", _check_update);
|
||||
_file.set("ExpBottleRatio", _exp_bottle_ratio);
|
||||
_file.set("CombineExpOrbs.Enable", _combine_exp_orbs_enable);
|
||||
_file.set("CombineExpOrbs.Radius", _combine_exp_orbs_radius);
|
||||
_file.set("NoExpCoolDown", _no_exp_cool_down);
|
||||
_file.set("ForceLoadChunks", _force_load_chunks);
|
||||
_file.set("ChunkOperateDelay", _chunk_operate_delay);
|
||||
_file.set("Teleport.Delay", _tp_delay);
|
||||
_file.set("Teleport.CoolDown", _tp_cool_down);
|
||||
_file.set("Teleport.TpaExpire", _tp_tpa_expire);
|
||||
_file.set("Teleport.RtpRadius", _tp_rtp_radius);
|
||||
_file.set("Teleport.WorldBlackList", _tp_world_blacklist);
|
||||
_file.set("Chair.Enable", _chair_enable);
|
||||
_file.set("Chair.MaxWidth", _chair_max_width);
|
||||
_file.set("Chair.SignCheck", _chair_sign_check);
|
||||
_file.set("Chair.SitHeight", _chair_sit_height);
|
||||
_file.set("Recipes.CrowBar", _recipes_crowbar);
|
||||
_file.set("Recipes.InvisibleItemFrame", _recipes_invisible_item_frame);
|
||||
_file.set("Recipes.LightBlock", _recipes_light_block);
|
||||
_file.set("Recipes.StackedEnchantBook", _recipes_stacked_enchant_book);
|
||||
_file.set("HomeLimit.Amount", _home_limit_amount);
|
||||
_file.set("HomeLimit.WorldBlacklist", _home_world_blacklist);
|
||||
_file.set("Database.Type", _db_type);
|
||||
_file.set("Database.Host", _db_host);
|
||||
_file.set("Database.Port", _db_port);
|
||||
_file.set("Database.Name", _db_name);
|
||||
_file.set("Database.User", _db_user);
|
||||
_file.set("Database.Pass", _db_pass);
|
||||
_file.set("Prefix.Enable", _prefix_enable);
|
||||
_file.set("Prefix.Format", _prefix_format);
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
public Boolean isDebug() {
|
||||
@ -274,6 +313,26 @@ public class ConfigManager {
|
||||
return _db_pass;
|
||||
}
|
||||
|
||||
public Boolean getPrefixEnable() {
|
||||
return _prefix_enable;
|
||||
}
|
||||
|
||||
public void setPrefixEnable(Boolean enable) {
|
||||
_prefix_enable = enable;
|
||||
_file.set("Prefix.Enable", enable);
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
public String getPrefixFormat() {
|
||||
return _prefix_format;
|
||||
}
|
||||
|
||||
public void setPrefixFormat(String format) {
|
||||
_prefix_format = format;
|
||||
_file.set("Prefix.Format", format);
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
|
||||
private final EssentialsD _plugin;
|
||||
private FileConfiguration _file;
|
||||
@ -311,4 +370,8 @@ public class ConfigManager {
|
||||
private String _db_user;
|
||||
private String _db_pass;
|
||||
private String _db_name;
|
||||
|
||||
// prefix
|
||||
private Boolean _prefix_enable;
|
||||
private String _prefix_format;
|
||||
}
|
||||
|
@ -55,6 +55,11 @@ HomeLimit:
|
||||
Amount: 5 # 数量限制
|
||||
WorldBlackList: [ ] # 不允许设置 home 的世界
|
||||
|
||||
# prefix (需要 PlaceholderAPI 支持)
|
||||
Prefix:
|
||||
Enable: false
|
||||
Format: '<%player_name%> '
|
||||
|
||||
Debug: false
|
||||
|
||||
CheckUpdate: true
|
@ -8,6 +8,7 @@ load: STARTUP
|
||||
folia-supported: true
|
||||
softdepend:
|
||||
- LuckPerms
|
||||
- PlaceholderAPI
|
||||
permissions:
|
||||
essd.*:
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user