feat: 完善 TPA 并整理插件配置
This commit is contained in:
@@ -36,6 +36,7 @@ public final class EssentialsC extends JavaPlugin {
|
||||
|
||||
private static LangManager langManager;
|
||||
private ModuleManager moduleManager;
|
||||
private FeatureConfigManager featureConfigManager;
|
||||
private AdminModeManager adminModeManager;
|
||||
private MaintenanceManager maintenanceManager;
|
||||
private TeleportRequestManager teleportRequestManager;
|
||||
@@ -54,6 +55,7 @@ public final class EssentialsC extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
langManager = new LangManager(this);
|
||||
moduleManager = new ModuleManager(this);
|
||||
featureConfigManager = new FeatureConfigManager(this);
|
||||
|
||||
reloadRuntimeModules();
|
||||
registerCommands();
|
||||
@@ -96,6 +98,10 @@ public final class EssentialsC extends JavaPlugin {
|
||||
return moduleManager;
|
||||
}
|
||||
|
||||
public FeatureConfigManager getFeatureConfigManager() {
|
||||
return featureConfigManager;
|
||||
}
|
||||
|
||||
public MaintenanceManager getMaintenanceManager() {
|
||||
return maintenanceManager;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package cn.infstar.essentialsC;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 管理体积较大的独立功能配置,并负责从旧版 config.yml 迁移数据。
|
||||
*/
|
||||
public final class FeatureConfigManager {
|
||||
|
||||
private static final int MAIN_CONFIG_VERSION = 2;
|
||||
|
||||
private final EssentialsC plugin;
|
||||
private final File skinBridgeFile;
|
||||
private final File blocksMenuFile;
|
||||
private FileConfiguration skinBridgeConfig;
|
||||
private FileConfiguration blocksMenuConfig;
|
||||
|
||||
public FeatureConfigManager(EssentialsC plugin) {
|
||||
this.plugin = plugin;
|
||||
this.skinBridgeFile = new File(plugin.getDataFolder(), "skin-bridge.yml");
|
||||
this.blocksMenuFile = new File(plugin.getDataFolder(), "blocks-menu.yml");
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
ensureResource(skinBridgeFile, "skin-bridge.yml");
|
||||
ensureResource(blocksMenuFile, "blocks-menu.yml");
|
||||
|
||||
skinBridgeConfig = loadWithDefaults(skinBridgeFile, "skin-bridge.yml");
|
||||
blocksMenuConfig = loadWithDefaults(blocksMenuFile, "blocks-menu.yml");
|
||||
migrateLegacyMainConfig();
|
||||
migrateLegacyDebugSettings();
|
||||
updateMainConfigVersion();
|
||||
saveSkinBridgeConfig();
|
||||
saveBlocksMenuConfig();
|
||||
}
|
||||
|
||||
public FileConfiguration getSkinBridgeConfig() {
|
||||
return skinBridgeConfig;
|
||||
}
|
||||
|
||||
public FileConfiguration getBlocksMenuConfig() {
|
||||
return blocksMenuConfig;
|
||||
}
|
||||
|
||||
public void saveSkinBridgeConfig() {
|
||||
save(skinBridgeConfig, skinBridgeFile);
|
||||
}
|
||||
|
||||
public void saveBlocksMenuConfig() {
|
||||
save(blocksMenuConfig, blocksMenuFile);
|
||||
}
|
||||
|
||||
private void migrateLegacyMainConfig() {
|
||||
FileConfiguration mainConfig = plugin.getConfig();
|
||||
boolean migrated = false;
|
||||
|
||||
if (mainConfig.contains("skin-bridge", true)) {
|
||||
copySection(mainConfig.getConfigurationSection("skin-bridge"), skinBridgeConfig);
|
||||
mainConfig.set("skin-bridge", null);
|
||||
migrated = true;
|
||||
}
|
||||
if (mainConfig.contains("blocks-menu", true)) {
|
||||
copySection(mainConfig.getConfigurationSection("blocks-menu"), blocksMenuConfig);
|
||||
mainConfig.set("blocks-menu", null);
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
if (!migrated) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainConfig.set("config-version", MAIN_CONFIG_VERSION);
|
||||
plugin.saveConfig();
|
||||
plugin.getLogger().info("已将 SkinBridge 与便捷菜单配置迁移到独立配置文件。");
|
||||
}
|
||||
|
||||
private void migrateLegacyDebugSettings() {
|
||||
FileConfiguration mainConfig = plugin.getConfig();
|
||||
boolean hasJeiDebug = mainConfig.contains("jei-sync.debug", true);
|
||||
boolean hasSkinBridgeDebug = skinBridgeConfig.contains("debug", true);
|
||||
if (!hasJeiDebug && !hasSkinBridgeDebug) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean debugEnabled = mainConfig.getBoolean("debug", false)
|
||||
|| mainConfig.getBoolean("jei-sync.debug", false)
|
||||
|| skinBridgeConfig.getBoolean("debug", false);
|
||||
mainConfig.set("debug", debugEnabled);
|
||||
mainConfig.set("jei-sync.debug", null);
|
||||
skinBridgeConfig.set("debug", null);
|
||||
plugin.saveConfig();
|
||||
plugin.getLogger().info("已将独立功能调试开关合并到 config.yml 的全局 debug。");
|
||||
}
|
||||
|
||||
private void updateMainConfigVersion() {
|
||||
if (plugin.getConfig().getInt("config-version", 0) >= MAIN_CONFIG_VERSION) {
|
||||
return;
|
||||
}
|
||||
plugin.getConfig().set("config-version", MAIN_CONFIG_VERSION);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
private void copySection(ConfigurationSection source, FileConfiguration target) {
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
for (String path : source.getKeys(true)) {
|
||||
if (!source.isConfigurationSection(path)) {
|
||||
target.set(path, source.get(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FileConfiguration loadWithDefaults(File file, String resourcePath) {
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
InputStream defaultsStream = plugin.getResource(resourcePath);
|
||||
if (defaultsStream != null) {
|
||||
YamlConfiguration defaults = YamlConfiguration.loadConfiguration(
|
||||
new InputStreamReader(defaultsStream, StandardCharsets.UTF_8)
|
||||
);
|
||||
config.setDefaults(defaults);
|
||||
config.options().copyDefaults(true);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
private void ensureResource(File file, String resourcePath) {
|
||||
if (!file.exists()) {
|
||||
plugin.saveResource(resourcePath, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void save(FileConfiguration config, File file) {
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException exception) {
|
||||
plugin.getLogger().warning("保存 " + file.getName() + " 失败: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package cn.infstar.essentialsC;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -15,10 +18,22 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class LangManager {
|
||||
|
||||
private static final int CURRENT_CONFIG_VERSION = 2;
|
||||
private static final int CURRENT_CONFIG_VERSION = 3;
|
||||
private static final Pattern HEX_COLOR_PATTERN = Pattern.compile("(?i)&#([0-9a-f]{6})");
|
||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||
private static final Map<String, String> THEME_COLORS = Map.of(
|
||||
"&a", "�fb9a",
|
||||
"&b", "ᒦff",
|
||||
"&c", "&#ff7e5e",
|
||||
"&d", "&#c160ff",
|
||||
"&e", "&#ffc43b",
|
||||
"&6", "&#f5c962"
|
||||
);
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private FileConfiguration config;
|
||||
@@ -32,7 +47,7 @@ public class LangManager {
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return translateColorCodes(langFile.getString("prefix", "&6[EssentialsC] &r"));
|
||||
return renderToLegacy(langFile.getString("prefix", "&6[EssentialsC] &r"));
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
@@ -40,11 +55,42 @@ public class LangManager {
|
||||
if (value == null) {
|
||||
return translateColorCodes("&c缺少语言文本: " + path);
|
||||
}
|
||||
return translateColorCodes(value);
|
||||
return renderToLegacy(value);
|
||||
}
|
||||
|
||||
public String getString(String path, Map<String, String> placeholders) {
|
||||
return applyPlaceholders(getString(path), placeholders);
|
||||
String value = langFile.getString(path);
|
||||
if (value == null) {
|
||||
return translateColorCodes("&c缺少语言文本: " + path);
|
||||
}
|
||||
return renderToLegacy(applyPlaceholders(value, placeholders));
|
||||
}
|
||||
|
||||
public Component getComponent(String path) {
|
||||
return getComponent(path, Map.of());
|
||||
}
|
||||
|
||||
public Component getComponent(String path, Map<String, String> placeholders) {
|
||||
String value = langFile.getString(path);
|
||||
if (value == null) {
|
||||
return LegacyComponentSerializer.legacySection()
|
||||
.deserialize(translateColorCodes("&c缺少语言文本: " + path));
|
||||
}
|
||||
|
||||
return renderToComponent(applyPlaceholders(value, placeholders));
|
||||
}
|
||||
|
||||
public Component getPrefixedComponent(String path) {
|
||||
return getPrefixedComponent(path, Map.of());
|
||||
}
|
||||
|
||||
public Component getPrefixedComponent(String path, Map<String, String> placeholders) {
|
||||
String value = langFile.getString(path);
|
||||
if (value == null) {
|
||||
return LegacyComponentSerializer.legacySection()
|
||||
.deserialize(getPrefix() + translateColorCodes("&c缺少语言文本: " + path));
|
||||
}
|
||||
return renderToComponent(langFile.getString("prefix", "") + applyPlaceholders(value, placeholders));
|
||||
}
|
||||
|
||||
public String getPrefixedString(String path) {
|
||||
@@ -63,7 +109,7 @@ public class LangManager {
|
||||
|
||||
List<String> translated = new ArrayList<>();
|
||||
for (String value : values) {
|
||||
translated.add(translateColorCodes(value));
|
||||
translated.add(renderToLegacy(value));
|
||||
}
|
||||
return translated;
|
||||
}
|
||||
@@ -100,7 +146,7 @@ public class LangManager {
|
||||
private void migrateConfigIfNeeded(File configFile) {
|
||||
FileConfiguration existingConfig = YamlConfiguration.loadConfiguration(configFile);
|
||||
int existingVersion = existingConfig.getInt("config-version", 0);
|
||||
if (existingVersion <= 0 || existingVersion >= CURRENT_CONFIG_VERSION) {
|
||||
if (existingVersion >= CURRENT_CONFIG_VERSION) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,14 +157,27 @@ public class LangManager {
|
||||
Files.copy(configFile.toPath(), backupFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
InputStream defaultConfigStream = plugin.getResource("config.yml");
|
||||
if (defaultConfigStream != null) {
|
||||
YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(
|
||||
YamlConfiguration migratedConfig = YamlConfiguration.loadConfiguration(
|
||||
new InputStreamReader(defaultConfigStream, StandardCharsets.UTF_8)
|
||||
);
|
||||
existingConfig.setDefaults(defaultConfig);
|
||||
existingConfig.options().copyDefaults(true);
|
||||
for (String path : existingConfig.getKeys(true)) {
|
||||
boolean migratedFeaturePath = path.startsWith("skin-bridge.") || path.startsWith("blocks-menu.");
|
||||
if (!existingConfig.isConfigurationSection(path)
|
||||
&& (migratedConfig.contains(path) || migratedFeaturePath)) {
|
||||
migratedConfig.set(path, existingConfig.get(path));
|
||||
}
|
||||
}
|
||||
boolean debugEnabled = existingConfig.getBoolean("debug", false)
|
||||
|| existingConfig.getBoolean("jei-sync.debug", false)
|
||||
|| existingConfig.getBoolean("skin-bridge.debug", false);
|
||||
migratedConfig.set("debug", debugEnabled);
|
||||
migratedConfig.set("jei-sync.debug", null);
|
||||
migratedConfig.set("config-version", CURRENT_CONFIG_VERSION);
|
||||
migratedConfig.save(configFile);
|
||||
} else {
|
||||
existingConfig.set("config-version", CURRENT_CONFIG_VERSION);
|
||||
existingConfig.save(configFile);
|
||||
}
|
||||
existingConfig.set("config-version", CURRENT_CONFIG_VERSION);
|
||||
existingConfig.save(configFile);
|
||||
|
||||
plugin.getLogger().info("已将 config.yml 从版本 " + existingVersion
|
||||
+ " 迁移到 " + CURRENT_CONFIG_VERSION + ",备份文件: " + backupFile.getName());
|
||||
@@ -175,12 +234,65 @@ public class LangManager {
|
||||
private String applyPlaceholders(String value, Map<String, String> placeholders) {
|
||||
String result = value;
|
||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
result = result.replace("{" + entry.getKey() + "}", entry.getValue());
|
||||
result = result.replace("{" + entry.getKey() + "}", escapeMiniMessageReplacement(entry.getValue()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String escapeMiniMessageReplacement(String value) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
return value.replace("\\", "\\\\").replace("<", "\\<");
|
||||
}
|
||||
|
||||
private String translateColorCodes(String text) {
|
||||
return text == null ? "" : ChatColor.translateAlternateColorCodes('&', text);
|
||||
if (text == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String themedText = text;
|
||||
for (Map.Entry<String, String> color : THEME_COLORS.entrySet()) {
|
||||
themedText = themedText.replace(color.getKey(), color.getValue());
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', expandHexColors(themedText));
|
||||
}
|
||||
|
||||
private String expandHexColors(String text) {
|
||||
Matcher matcher = HEX_COLOR_PATTERN.matcher(text);
|
||||
StringBuilder result = new StringBuilder();
|
||||
while (matcher.find()) {
|
||||
String hex = matcher.group(1);
|
||||
StringBuilder legacyHex = new StringBuilder("&x");
|
||||
for (char digit : hex.toCharArray()) {
|
||||
legacyHex.append('&').append(digit);
|
||||
}
|
||||
matcher.appendReplacement(result, Matcher.quoteReplacement(legacyHex.toString()));
|
||||
}
|
||||
matcher.appendTail(result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private String renderToLegacy(String text) {
|
||||
return LegacyComponentSerializer.legacySection().serialize(renderToComponent(text));
|
||||
}
|
||||
|
||||
private Component renderToComponent(String text) {
|
||||
if (text == null) {
|
||||
return Component.empty();
|
||||
}
|
||||
if (looksLikeMiniMessage(text)) {
|
||||
try {
|
||||
return MINI_MESSAGE.deserialize(text);
|
||||
} catch (RuntimeException ignored) {
|
||||
// 配置中 MiniMessage 语法错误时回退到旧颜色码解析,避免消息完全不可用。
|
||||
}
|
||||
}
|
||||
return LegacyComponentSerializer.legacySection().deserialize(translateColorCodes(text));
|
||||
}
|
||||
|
||||
private boolean looksLikeMiniMessage(String text) {
|
||||
int open = text.indexOf('<');
|
||||
return open >= 0 && text.indexOf('>', open) > open;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package cn.infstar.essentialsC.admin;
|
||||
|
||||
import cn.infstar.essentialsC.EssentialsC;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@@ -270,9 +268,7 @@ public final class AdminModeManager implements Listener {
|
||||
}
|
||||
|
||||
private void sendActionBar(Player player) {
|
||||
String text = EssentialsC.getLangManager().getString("admin-mode.actionbar");
|
||||
Component component = LegacyComponentSerializer.legacyAmpersand().deserialize(text);
|
||||
player.sendActionBar(component);
|
||||
player.sendActionBar(EssentialsC.getLangManager().getComponent("admin-mode.actionbar"));
|
||||
}
|
||||
|
||||
private float getAdminFlySpeed() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -60,7 +61,8 @@ public class BlocksMenuCommand extends BaseCommand implements Listener {
|
||||
private void openMenu(Player player) {
|
||||
Inventory menu = new BlocksMenuHolder(getLang().getString("blocks-menu.title")).getInventory();
|
||||
|
||||
var sectionsConfig = plugin.getConfig().getConfigurationSection("blocks-menu.sections");
|
||||
FileConfiguration menuConfig = plugin.getFeatureConfigManager().getBlocksMenuConfig();
|
||||
var sectionsConfig = menuConfig.getConfigurationSection("sections");
|
||||
if (sectionsConfig != null) {
|
||||
int visibleSections = renderSections(menu, player, sectionsConfig);
|
||||
if (visibleSections > 1) {
|
||||
@@ -75,7 +77,7 @@ public class BlocksMenuCommand extends BaseCommand implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
var itemsConfig = plugin.getConfig().getConfigurationSection("blocks-menu.items");
|
||||
var itemsConfig = menuConfig.getConfigurationSection("items");
|
||||
if (itemsConfig == null) {
|
||||
return;
|
||||
}
|
||||
@@ -253,66 +255,69 @@ public class BlocksMenuCommand extends BaseCommand implements Listener {
|
||||
}
|
||||
|
||||
private void addConfigDefaults() {
|
||||
plugin.getConfig().addDefault("blocks-menu.layout-version", 2);
|
||||
FileConfiguration config = plugin.getFeatureConfigManager().getBlocksMenuConfig();
|
||||
config.addDefault("config-version", 1);
|
||||
config.addDefault("layout-version", 2);
|
||||
|
||||
addMenuItemDefaults("blocks-menu.sections.blocks.items.workbench", 10, "CRAFTING_TABLE",
|
||||
addMenuItemDefaults(config, "sections.blocks.items.workbench", 10, "CRAFTING_TABLE",
|
||||
"essentialsc.command.workbench", "workbench");
|
||||
addMenuItemDefaults("blocks-menu.sections.blocks.items.enderchest", 11, "ENDER_CHEST",
|
||||
addMenuItemDefaults(config, "sections.blocks.items.enderchest", 11, "ENDER_CHEST",
|
||||
"essentialsc.command.enderchest", "enderchest");
|
||||
addMenuItemDefaults("blocks-menu.sections.blocks.items.anvil", 12, "ANVIL",
|
||||
addMenuItemDefaults(config, "sections.blocks.items.anvil", 12, "ANVIL",
|
||||
"essentialsc.command.anvil", "anvil");
|
||||
addMenuItemDefaults("blocks-menu.sections.blocks.items.grindstone", 19, "GRINDSTONE",
|
||||
addMenuItemDefaults(config, "sections.blocks.items.grindstone", 19, "GRINDSTONE",
|
||||
"essentialsc.command.grindstone", "grindstone");
|
||||
addMenuItemDefaults("blocks-menu.sections.blocks.items.smithingtable", 20, "SMITHING_TABLE",
|
||||
addMenuItemDefaults(config, "sections.blocks.items.smithingtable", 20, "SMITHING_TABLE",
|
||||
"essentialsc.command.smithingtable", "smithingtable");
|
||||
addMenuItemDefaults("blocks-menu.sections.blocks.items.stonecutter", 21, "STONECUTTER",
|
||||
addMenuItemDefaults(config, "sections.blocks.items.stonecutter", 21, "STONECUTTER",
|
||||
"essentialsc.command.stonecutter", "stonecutter");
|
||||
addMenuItemDefaults("blocks-menu.sections.blocks.items.loom", 28, "LOOM",
|
||||
addMenuItemDefaults(config, "sections.blocks.items.loom", 28, "LOOM",
|
||||
"essentialsc.command.loom", "loom");
|
||||
addMenuItemDefaults("blocks-menu.sections.blocks.items.cartographytable", 29, "CARTOGRAPHY_TABLE",
|
||||
addMenuItemDefaults(config, "sections.blocks.items.cartographytable", 29, "CARTOGRAPHY_TABLE",
|
||||
"essentialsc.command.cartographytable", "cartographytable");
|
||||
|
||||
addMenuItemDefaults("blocks-menu.sections.shortcuts.items.nightvision", 14, "TINTED_GLASS",
|
||||
addMenuItemDefaults(config, "sections.shortcuts.items.nightvision", 14, "TINTED_GLASS",
|
||||
"essentialsc.command.nightvision", "nightvision");
|
||||
addMenuItemDefaults("blocks-menu.sections.shortcuts.items.glow", 15, "GLOWSTONE",
|
||||
addMenuItemDefaults(config, "sections.shortcuts.items.glow", 15, "GLOWSTONE",
|
||||
"essentialsc.command.glow", "glow");
|
||||
|
||||
plugin.getConfig().options().copyDefaults(true);
|
||||
migrateLayoutIfNeeded();
|
||||
plugin.saveConfig();
|
||||
config.options().copyDefaults(true);
|
||||
migrateLayoutIfNeeded(config);
|
||||
plugin.getFeatureConfigManager().saveBlocksMenuConfig();
|
||||
}
|
||||
|
||||
private void migrateLayoutIfNeeded() {
|
||||
boolean hasStoredLayoutVersion = plugin.getConfig().contains("blocks-menu.layout-version", true);
|
||||
if (hasStoredLayoutVersion && plugin.getConfig().getInt("blocks-menu.layout-version", 0) >= 2) {
|
||||
private void migrateLayoutIfNeeded(FileConfiguration config) {
|
||||
boolean hasStoredLayoutVersion = config.contains("layout-version", true);
|
||||
if (hasStoredLayoutVersion && config.getInt("layout-version", 0) >= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
applySlot("blocks", "workbench", 10);
|
||||
applySlot("blocks", "enderchest", 11);
|
||||
applySlot("blocks", "anvil", 12);
|
||||
applySlot("blocks", "grindstone", 19);
|
||||
applySlot("blocks", "smithingtable", 20);
|
||||
applySlot("blocks", "stonecutter", 21);
|
||||
applySlot("blocks", "loom", 28);
|
||||
applySlot("blocks", "cartographytable", 29);
|
||||
applySlot("shortcuts", "nightvision", 14);
|
||||
applySlot("shortcuts", "glow", 15);
|
||||
applySlot(config, "blocks", "workbench", 10);
|
||||
applySlot(config, "blocks", "enderchest", 11);
|
||||
applySlot(config, "blocks", "anvil", 12);
|
||||
applySlot(config, "blocks", "grindstone", 19);
|
||||
applySlot(config, "blocks", "smithingtable", 20);
|
||||
applySlot(config, "blocks", "stonecutter", 21);
|
||||
applySlot(config, "blocks", "loom", 28);
|
||||
applySlot(config, "blocks", "cartographytable", 29);
|
||||
applySlot(config, "shortcuts", "nightvision", 14);
|
||||
applySlot(config, "shortcuts", "glow", 15);
|
||||
|
||||
plugin.getConfig().set("blocks-menu.sections.blocks.title-item", null);
|
||||
plugin.getConfig().set("blocks-menu.sections.shortcuts.title-item", null);
|
||||
plugin.getConfig().set("blocks-menu.layout-version", 2);
|
||||
config.set("sections.blocks.title-item", null);
|
||||
config.set("sections.shortcuts.title-item", null);
|
||||
config.set("layout-version", 2);
|
||||
}
|
||||
|
||||
private void applySlot(String section, String key, int slot) {
|
||||
plugin.getConfig().set("blocks-menu.sections." + section + ".items." + key + ".slot", slot);
|
||||
private void applySlot(FileConfiguration config, String section, String key, int slot) {
|
||||
config.set("sections." + section + ".items." + key + ".slot", slot);
|
||||
}
|
||||
|
||||
private void addMenuItemDefaults(String path, int slot, String material, String permission, String command) {
|
||||
plugin.getConfig().addDefault(path + ".slot", slot);
|
||||
plugin.getConfig().addDefault(path + ".material", material);
|
||||
plugin.getConfig().addDefault(path + ".permission", permission);
|
||||
plugin.getConfig().addDefault(path + ".command", command);
|
||||
private void addMenuItemDefaults(FileConfiguration config, String path, int slot, String material,
|
||||
String permission, String command) {
|
||||
config.addDefault(path + ".slot", slot);
|
||||
config.addDefault(path + ".material", material);
|
||||
config.addDefault(path + ".permission", permission);
|
||||
config.addDefault(path + ".command", command);
|
||||
}
|
||||
|
||||
private record MenuItem(int slot, Material material, String name, List<String> lore, String commandKey) {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class HelpCommand extends BaseCommand implements TabCompleter {
|
||||
}
|
||||
plugin.reloadConfig();
|
||||
EssentialsC.getLangManager().reload();
|
||||
plugin.getFeatureConfigManager().reload();
|
||||
plugin.getModuleManager().reload();
|
||||
CommandRegistry.clearCache();
|
||||
plugin.reloadRuntimeModules();
|
||||
@@ -55,6 +56,7 @@ public class HelpCommand extends BaseCommand implements TabCompleter {
|
||||
}
|
||||
plugin.reloadConfig();
|
||||
EssentialsC.getLangManager().reload();
|
||||
plugin.getFeatureConfigManager().reload();
|
||||
plugin.getModuleManager().reload();
|
||||
CommandRegistry.clearCache();
|
||||
plugin.reloadRuntimeModules();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.infstar.essentialsC.commands;
|
||||
|
||||
import cn.infstar.essentialsC.teleport.TeleportRequestManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@@ -20,17 +19,17 @@ public final class TpAcceptCommand extends BaseCommand implements TabCompleter {
|
||||
@Override
|
||||
protected boolean execute(Player player, String[] args) {
|
||||
if (args.length > 1) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.usage-tpaccept"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.usage-tpaccept"));
|
||||
return true;
|
||||
}
|
||||
|
||||
TeleportRequestManager manager = plugin.getTeleportRequestManager();
|
||||
if (manager == null) {
|
||||
player.sendMessage(getLang().getPrefixedString("messages.module-disabled"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("messages.module-disabled"));
|
||||
return true;
|
||||
}
|
||||
if (manager.isIgnoringRequests(player)) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.ignoring-requests"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.ignoring-requests"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,7 +38,9 @@ public final class TpAcceptCommand extends BaseCommand implements TabCompleter {
|
||||
args.length == 0 ? null : args[0]
|
||||
);
|
||||
if (request.isEmpty()) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.no-request"));
|
||||
player.sendMessage(args.length == 0
|
||||
? getLang().getPrefixedComponent("tpa.messages.no-request")
|
||||
: getLang().getPrefixedComponent("tpa.messages.invalid-request", Map.of("requester", args[0])));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -47,28 +48,18 @@ public final class TpAcceptCommand extends BaseCommand implements TabCompleter {
|
||||
Map<String, String> placeholders = manager.placeholders(accepted);
|
||||
TeleportRequestManager.TeleportResult result = manager.accept(player, accepted);
|
||||
if (result.status() == TeleportRequestManager.TeleportResult.Status.EXPIRED) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.expired", placeholders));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.expired", placeholders));
|
||||
return true;
|
||||
}
|
||||
if (result.status() == TeleportRequestManager.TeleportResult.Status.PLAYER_OFFLINE) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.player-offline", placeholders));
|
||||
return true;
|
||||
}
|
||||
if (result.status() == TeleportRequestManager.TeleportResult.Status.ALREADY_WARMING_UP) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.already-warming-up", placeholders));
|
||||
return true;
|
||||
}
|
||||
if (result.status() == TeleportRequestManager.TeleportResult.Status.ON_COOLDOWN) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.accept-cooldown",
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.accept-cooldown",
|
||||
Map.of("seconds", String.valueOf(result.cooldownSeconds()))));
|
||||
return true;
|
||||
}
|
||||
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.accepted-target", placeholders));
|
||||
Player requester = Bukkit.getPlayer(accepted.requesterId());
|
||||
if (requester != null && requester.isOnline()) {
|
||||
requester.sendMessage(getLang().getPrefixedString("tpa.messages.accepted-sender", placeholders));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.infstar.essentialsC.commands;
|
||||
|
||||
import cn.infstar.essentialsC.teleport.TeleportRequestManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@@ -20,17 +19,17 @@ public final class TpDenyCommand extends BaseCommand implements TabCompleter {
|
||||
@Override
|
||||
protected boolean execute(Player player, String[] args) {
|
||||
if (args.length > 1) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.usage-tpdeny"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.usage-tpdeny"));
|
||||
return true;
|
||||
}
|
||||
|
||||
TeleportRequestManager manager = plugin.getTeleportRequestManager();
|
||||
if (manager == null) {
|
||||
player.sendMessage(getLang().getPrefixedString("messages.module-disabled"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("messages.module-disabled"));
|
||||
return true;
|
||||
}
|
||||
if (manager.isIgnoringRequests(player)) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.ignoring-requests"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.ignoring-requests"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,23 +38,19 @@ public final class TpDenyCommand extends BaseCommand implements TabCompleter {
|
||||
args.length == 0 ? null : args[0]
|
||||
);
|
||||
if (request.isEmpty()) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.no-request"));
|
||||
player.sendMessage(args.length == 0
|
||||
? getLang().getPrefixedComponent("tpa.messages.no-request")
|
||||
: getLang().getPrefixedComponent("tpa.messages.invalid-request", Map.of("requester", args[0])));
|
||||
return true;
|
||||
}
|
||||
|
||||
TeleportRequestManager.TeleportRequest denied = request.get();
|
||||
TeleportRequestManager.TeleportResult result = manager.deny(player, denied);
|
||||
if (result.status() == TeleportRequestManager.TeleportResult.Status.EXPIRED) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.expired", manager.placeholders(denied)));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.expired", manager.placeholders(denied)));
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<String, String> placeholders = manager.placeholders(denied);
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.denied-target", placeholders));
|
||||
Player requester = Bukkit.getPlayer(denied.requesterId());
|
||||
if (requester != null && requester.isOnline()) {
|
||||
requester.sendMessage(getLang().getPrefixedString("tpa.messages.denied-sender", placeholders));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ public final class TpIgnoreCommand extends BaseCommand {
|
||||
protected boolean execute(Player player, String[] args) {
|
||||
TeleportRequestManager manager = plugin.getTeleportRequestManager();
|
||||
if (manager == null) {
|
||||
player.sendMessage(getLang().getPrefixedString("messages.module-disabled"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("messages.module-disabled"));
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean ignoring = manager.toggleIgnoringRequests(player);
|
||||
player.sendMessage(getLang().getPrefixedString(ignoring
|
||||
player.sendMessage(getLang().getPrefixedComponent(ignoring
|
||||
? "tpa.messages.ignore-enabled"
|
||||
: "tpa.messages.ignore-disabled"));
|
||||
return true;
|
||||
|
||||
@@ -3,8 +3,6 @@ package cn.infstar.essentialsC.commands;
|
||||
import cn.infstar.essentialsC.teleport.TeleportRequestManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class TpaAllCommand extends BaseCommand {
|
||||
|
||||
public TpaAllCommand() {
|
||||
@@ -14,32 +12,27 @@ public final class TpaAllCommand extends BaseCommand {
|
||||
@Override
|
||||
protected boolean execute(Player player, String[] args) {
|
||||
if (args.length != 0) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.usage-tpaall"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.usage-tpaall"));
|
||||
return true;
|
||||
}
|
||||
|
||||
TeleportRequestManager manager = plugin.getTeleportRequestManager();
|
||||
if (manager == null) {
|
||||
player.sendMessage(getLang().getPrefixedString("messages.module-disabled"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("messages.module-disabled"));
|
||||
return true;
|
||||
}
|
||||
if (manager.isIgnoringRequests(player)) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.ignoring-requests"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.ignoring-requests"));
|
||||
return true;
|
||||
}
|
||||
|
||||
int sent = manager.sendTeleportAllRequest(player, target -> !VanishCommand.isVanished(target));
|
||||
if (sent < 0) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.send-cooldown",
|
||||
Map.of("seconds", String.valueOf(manager.getSendCooldownSeconds(player)))));
|
||||
return true;
|
||||
}
|
||||
int sent = manager.sendTeleportAllRequest(player);
|
||||
if (sent <= 0) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.tpaall-no-targets"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.tpaall-no-targets"));
|
||||
return true;
|
||||
}
|
||||
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.tpaall-sent"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.tpaall-sent"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package cn.infstar.essentialsC.commands;
|
||||
|
||||
import cn.infstar.essentialsC.teleport.TeleportRequestManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -15,7 +10,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TpaCommand extends BaseCommand implements TabCompleter {
|
||||
|
||||
@@ -30,7 +24,7 @@ public class TpaCommand extends BaseCommand implements TabCompleter {
|
||||
|
||||
protected boolean sendRequest(Player player, String[] args, TeleportRequestManager.TeleportRequest.Type type) {
|
||||
if (args.length != 1) {
|
||||
player.sendMessage(getLang().getPrefixedString(type == TeleportRequestManager.TeleportRequest.Type.TPA
|
||||
player.sendMessage(getLang().getPrefixedComponent(type == TeleportRequestManager.TeleportRequest.Type.TPA
|
||||
? "tpa.messages.usage-tpa"
|
||||
: "tpa.messages.usage-tpahere"));
|
||||
return true;
|
||||
@@ -38,82 +32,73 @@ public class TpaCommand extends BaseCommand implements TabCompleter {
|
||||
|
||||
TeleportRequestManager manager = plugin.getTeleportRequestManager();
|
||||
if (manager == null) {
|
||||
player.sendMessage(getLang().getPrefixedString("messages.module-disabled"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("messages.module-disabled"));
|
||||
return true;
|
||||
}
|
||||
if (manager.isIgnoringRequests(player)) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.ignoring-requests"));
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.ignoring-requests"));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayerExact(args[0]);
|
||||
if (target == null || !target.isOnline() || VanishCommand.isVanished(target)) {
|
||||
player.sendMessage(getLang().getPrefixedString("messages.player-not-found", Map.of("player", args[0])));
|
||||
if (args[0].equalsIgnoreCase(player.getName())) {
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.self"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target.getUniqueId().equals(player.getUniqueId())) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.self"));
|
||||
int remainingCooldown = manager.getRemainingSendCooldownSeconds(player);
|
||||
if (remainingCooldown > 0) {
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.send-cooldown",
|
||||
Map.of("seconds", String.valueOf(remainingCooldown))));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = manager.findOnlinePlayer(args[0], onlinePlayer ->
|
||||
!onlinePlayer.getUniqueId().equals(player.getUniqueId()) && !manager.isVanished(onlinePlayer)
|
||||
).orElse(null);
|
||||
if (target == null || !target.isOnline()) {
|
||||
player.sendMessage(getLang().getPrefixedComponent("messages.player-not-found", Map.of("player", args[0])));
|
||||
return true;
|
||||
}
|
||||
|
||||
TeleportRequestManager.CreateRequestResult createdRequest = manager.createRequest(player, target, type);
|
||||
if (createdRequest.status() == TeleportRequestManager.CreateRequestStatus.DUPLICATE) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.duplicate-request", Map.of("target", target.getName())));
|
||||
return true;
|
||||
}
|
||||
if (createdRequest.status() == TeleportRequestManager.CreateRequestStatus.ON_COOLDOWN) {
|
||||
player.sendMessage(getLang().getPrefixedString("tpa.messages.send-cooldown",
|
||||
player.sendMessage(getLang().getPrefixedComponent("tpa.messages.send-cooldown",
|
||||
Map.of("seconds", String.valueOf(createdRequest.cooldownSeconds()))));
|
||||
return true;
|
||||
}
|
||||
|
||||
TeleportRequestManager.TeleportRequest request = createdRequest.request();
|
||||
Map<String, String> placeholders = manager.placeholders(request);
|
||||
player.sendMessage(getLang().getPrefixedString(type == TeleportRequestManager.TeleportRequest.Type.TPA
|
||||
player.sendMessage(getLang().getPrefixedComponent(type == TeleportRequestManager.TeleportRequest.Type.TPA
|
||||
? "tpa.messages.sent-tpa"
|
||||
: "tpa.messages.sent-tpahere", placeholders));
|
||||
if (createdRequest.status() == TeleportRequestManager.CreateRequestStatus.IGNORED) {
|
||||
if (createdRequest.status() == TeleportRequestManager.CreateRequestStatus.IGNORED
|
||||
|| createdRequest.status() == TeleportRequestManager.CreateRequestStatus.DUPLICATE) {
|
||||
return true;
|
||||
}
|
||||
target.sendMessage(getLang().getPrefixedString(type == TeleportRequestManager.TeleportRequest.Type.TPA
|
||||
target.sendMessage(getLang().getPrefixedComponent(type == TeleportRequestManager.TeleportRequest.Type.TPA
|
||||
? "tpa.messages.received-tpa"
|
||||
: "tpa.messages.received-tpahere", placeholders));
|
||||
manager.playRequestReceivedSound(target);
|
||||
sendResponseHint(target, request, placeholders);
|
||||
manager.sendResponseHint(target, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendResponseHint(Player target, TeleportRequestManager.TeleportRequest request, Map<String, String> placeholders) {
|
||||
String requesterName = request.requesterName();
|
||||
String acceptCommand = "/tpaccept " + requesterName;
|
||||
String denyCommand = "/tpdeny " + requesterName;
|
||||
|
||||
Component hint = LegacyComponentSerializer.legacySection()
|
||||
.deserialize(getLang().getPrefixedString("tpa.messages.response-hint", placeholders));
|
||||
Component accept = LegacyComponentSerializer.legacySection()
|
||||
.deserialize(getLang().getString("tpa.messages.accept-button"))
|
||||
.clickEvent(ClickEvent.runCommand(acceptCommand))
|
||||
.hoverEvent(HoverEvent.showText(Component.text(acceptCommand, NamedTextColor.GREEN)));
|
||||
Component deny = LegacyComponentSerializer.legacySection()
|
||||
.deserialize(getLang().getString("tpa.messages.deny-button"))
|
||||
.clickEvent(ClickEvent.runCommand(denyCommand))
|
||||
.hoverEvent(HoverEvent.showText(Component.text(denyCommand, NamedTextColor.RED)));
|
||||
|
||||
target.sendMessage(hint.append(Component.space()).append(accept).append(Component.space()).append(deny));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1 || !(sender instanceof Player player)) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
TeleportRequestManager manager = plugin.getTeleportRequestManager();
|
||||
if (manager == null) {
|
||||
return List.of();
|
||||
}
|
||||
String partial = args[0].toLowerCase();
|
||||
List<String> completions = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (!onlinePlayer.getUniqueId().equals(player.getUniqueId())
|
||||
&& !VanishCommand.isVanished(onlinePlayer)
|
||||
&& !manager.isVanished(onlinePlayer)
|
||||
&& onlinePlayer.getName().toLowerCase().startsWith(partial)) {
|
||||
completions.add(onlinePlayer.getName());
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class JeiRecipeSyncListener implements Listener {
|
||||
plugin.saveConfig();
|
||||
|
||||
this.enabled = config.getBoolean("jei-sync.enabled", true);
|
||||
this.debug = config.getBoolean("jei-sync.debug", config.getBoolean("debug", false));
|
||||
this.debug = config.getBoolean("debug", false);
|
||||
this.sendPlayerMessage = config.getBoolean("jei-sync.send-player-message", true);
|
||||
this.brandCheckDelayTicks = Math.max(0, config.getInt("jei-sync.brand-check-delay-ticks", 20));
|
||||
this.adapter = loadAdapter();
|
||||
@@ -112,10 +112,7 @@ public class JeiRecipeSyncListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
String fullMessage = EssentialsC.getLangManager().getPrefixedString(messageKey);
|
||||
net.kyori.adventure.text.Component component =
|
||||
net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacyAmpersand().deserialize(fullMessage);
|
||||
player.sendMessage(component);
|
||||
player.sendMessage(EssentialsC.getLangManager().getPrefixedComponent(messageKey));
|
||||
}
|
||||
|
||||
private void sendFabricRecipeSync(Player player) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public final class MineSkinGateway implements SkinBridgeGateway {
|
||||
}
|
||||
Thread.sleep(POLL_INTERVAL_MILLIS);
|
||||
}
|
||||
throw new IllegalStateException("MineSkin 生成任务超时,请增大 skin-bridge.mineskin.request-timeout-seconds。");
|
||||
throw new IllegalStateException("MineSkin 生成任务超时,请增大 skin-bridge.yml 中的 mineskin.request-timeout-seconds。");
|
||||
}
|
||||
|
||||
private HttpResponse<String> send(HttpRequest.Builder builder) throws Exception {
|
||||
|
||||
@@ -63,21 +63,21 @@ public final class SkinBridgeManager implements Listener {
|
||||
|
||||
public void reload() {
|
||||
configurationGeneration.incrementAndGet();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
FileConfiguration config = plugin.getFeatureConfigManager().getSkinBridgeConfig();
|
||||
addDefaults(config);
|
||||
config.options().copyDefaults(true);
|
||||
plugin.saveConfig();
|
||||
plugin.getFeatureConfigManager().saveSkinBridgeConfig();
|
||||
|
||||
enabled = config.getBoolean("skin-bridge.enabled", false);
|
||||
debug = config.getBoolean("skin-bridge.debug", false);
|
||||
sendPlayerMessage = config.getBoolean("skin-bridge.send-player-message", true);
|
||||
requestTimeoutSeconds = clamp(config.getInt("skin-bridge.profile-request-timeout-seconds", 5), 1, 30);
|
||||
String mineSkinEndpoint = config.getString("skin-bridge.mineskin.endpoint", "https://api.mineskin.org");
|
||||
String mineSkinApiKey = config.getString("skin-bridge.mineskin.api-key", "").trim();
|
||||
String mineSkinVisibility = config.getString("skin-bridge.mineskin.visibility", "unlisted");
|
||||
int mineSkinTimeoutSeconds = clamp(config.getInt("skin-bridge.mineskin.request-timeout-seconds", 30), 10, 180);
|
||||
cacheMinutes = clamp(config.getInt("skin-bridge.cache-minutes", 120), 5, 10080);
|
||||
joinDelayTicks = clamp(config.getLong("skin-bridge.join-delay-ticks", 20L), 0, 200);
|
||||
enabled = config.getBoolean("enabled", false);
|
||||
debug = plugin.getConfig().getBoolean("debug", false);
|
||||
sendPlayerMessage = config.getBoolean("send-player-message", true);
|
||||
requestTimeoutSeconds = clamp(config.getInt("profile-request-timeout-seconds", 5), 1, 30);
|
||||
String mineSkinEndpoint = config.getString("mineskin.endpoint", "https://api.mineskin.org");
|
||||
String mineSkinApiKey = config.getString("mineskin.api-key", "").trim();
|
||||
String mineSkinVisibility = config.getString("mineskin.visibility", "unlisted");
|
||||
int mineSkinTimeoutSeconds = clamp(config.getInt("mineskin.request-timeout-seconds", 30), 10, 180);
|
||||
cacheMinutes = clamp(config.getInt("cache-minutes", 120), 5, 10080);
|
||||
joinDelayTicks = clamp(config.getLong("join-delay-ticks", 20L), 0, 200);
|
||||
providers = loadProviders(config);
|
||||
cache.clear();
|
||||
gateway = loadGateway(mineSkinEndpoint, mineSkinApiKey, mineSkinVisibility, mineSkinTimeoutSeconds);
|
||||
@@ -322,7 +322,7 @@ public final class SkinBridgeManager implements Listener {
|
||||
}
|
||||
|
||||
private List<SkinProvider> loadProviders(FileConfiguration config) {
|
||||
ConfigurationSection providersSection = config.getConfigurationSection("skin-bridge.providers");
|
||||
ConfigurationSection providersSection = config.getConfigurationSection("providers");
|
||||
if (providersSection == null) {
|
||||
return List.of();
|
||||
}
|
||||
@@ -364,16 +364,16 @@ public final class SkinBridgeManager implements Listener {
|
||||
}
|
||||
|
||||
private void addDefaults(FileConfiguration config) {
|
||||
config.addDefault("skin-bridge.enabled", false);
|
||||
config.addDefault("skin-bridge.debug", false);
|
||||
config.addDefault("skin-bridge.send-player-message", true);
|
||||
config.addDefault("skin-bridge.profile-request-timeout-seconds", 5);
|
||||
config.addDefault("skin-bridge.mineskin.endpoint", "https://api.mineskin.org");
|
||||
config.addDefault("skin-bridge.mineskin.api-key", "");
|
||||
config.addDefault("skin-bridge.mineskin.visibility", "unlisted");
|
||||
config.addDefault("skin-bridge.mineskin.request-timeout-seconds", 30);
|
||||
config.addDefault("skin-bridge.cache-minutes", 120);
|
||||
config.addDefault("skin-bridge.join-delay-ticks", 20);
|
||||
config.addDefault("config-version", 1);
|
||||
config.addDefault("enabled", false);
|
||||
config.addDefault("send-player-message", true);
|
||||
config.addDefault("profile-request-timeout-seconds", 5);
|
||||
config.addDefault("mineskin.endpoint", "https://api.mineskin.org");
|
||||
config.addDefault("mineskin.api-key", "");
|
||||
config.addDefault("mineskin.visibility", "unlisted");
|
||||
config.addDefault("mineskin.request-timeout-seconds", 30);
|
||||
config.addDefault("cache-minutes", 120);
|
||||
config.addDefault("join-delay-ticks", 20);
|
||||
}
|
||||
|
||||
private void applySkin(UUID playerId, CachedLookup resolved, long lookupGeneration) {
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package cn.infstar.essentialsC.teleport;
|
||||
|
||||
import cn.infstar.essentialsC.EssentialsC;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import cn.infstar.essentialsC.commands.VanishCommand;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@@ -15,13 +12,15 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
@@ -30,6 +29,7 @@ import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -40,15 +40,19 @@ public final class TeleportRequestManager implements Listener {
|
||||
|
||||
public static final String BYPASS_WARMUP_PERMISSION = "essentialsc.tpa.bypass-warmup";
|
||||
public static final String BYPASS_COOLDOWN_PERMISSION = "essentialsc.tpa.bypass-cooldown";
|
||||
public static final String WARMUP_PERMISSION_PREFIX = "essentialsc.tpa.warmup.";
|
||||
private static final double MOVEMENT_THRESHOLD = 0.1D;
|
||||
|
||||
private final EssentialsC plugin;
|
||||
private final Map<UUID, Deque<TeleportRequest>> requests = new HashMap<>();
|
||||
private final Map<UUID, PendingTeleport> warmups = new HashMap<>();
|
||||
private final Map<UUID, Long> sendCooldowns = new HashMap<>();
|
||||
private final Map<UUID, Long> acceptCooldowns = new HashMap<>();
|
||||
private final Map<UUID, BukkitTask> invulnerabilityTasks = new HashMap<>();
|
||||
private final Set<UUID> warmupDamagedPlayers = new HashSet<>();
|
||||
private final Set<UUID> invulnerablePlayers = new HashSet<>();
|
||||
private final Set<UUID> ignoringRequests = new HashSet<>();
|
||||
private final File ignoreFile;
|
||||
private BukkitTask cleanupTask;
|
||||
|
||||
private int timeoutSeconds;
|
||||
private boolean strictTpaRequests;
|
||||
@@ -59,8 +63,9 @@ public final class TeleportRequestManager implements Listener {
|
||||
private boolean cooldownsEnabled;
|
||||
private int sendCooldownSeconds;
|
||||
private int acceptCooldownSeconds;
|
||||
private double warmupMoveThreshold;
|
||||
private String warmupDisplay;
|
||||
private int teleportInvulnerabilitySeconds;
|
||||
private boolean teleportAsync;
|
||||
private boolean soundsEnabled;
|
||||
private String requestSound;
|
||||
private String warmupSound;
|
||||
@@ -83,17 +88,19 @@ public final class TeleportRequestManager implements Listener {
|
||||
plugin.getConfig().addDefault("tpa.cooldowns.enabled", true);
|
||||
plugin.getConfig().addDefault("tpa.cooldowns.cooldown-times.SEND_TELEPORT_REQUEST", 0);
|
||||
plugin.getConfig().addDefault("tpa.cooldowns.cooldown-times.ACCEPT_TELEPORT_REQUEST", 0);
|
||||
plugin.getConfig().addDefault("tpa.warmup-move-threshold", 0.1D);
|
||||
plugin.getConfig().addDefault("tpa.warmup-display", "actionbar");
|
||||
plugin.getConfig().addDefault("tpa.teleport-invulnerability-seconds", 0);
|
||||
plugin.getConfig().addDefault("tpa.teleport-async", true);
|
||||
plugin.getConfig().addDefault("tpa.sounds.enabled", true);
|
||||
plugin.getConfig().addDefault("tpa.sounds.request-received", "entity.experience_orb.pickup");
|
||||
plugin.getConfig().addDefault("tpa.sounds.warmup", "block.note_block.banjo");
|
||||
plugin.getConfig().addDefault("tpa.sounds.cancelled", "entity.item.break");
|
||||
plugin.getConfig().addDefault("tpa.sounds.complete", "entity.enderman.teleport");
|
||||
plugin.getConfig().set("tpa.warmup-move-threshold", null);
|
||||
plugin.getConfig().options().copyDefaults(true);
|
||||
plugin.saveConfig();
|
||||
|
||||
timeoutSeconds = Math.max(5, plugin.getConfig().getInt("tpa.timeout-seconds", 60));
|
||||
timeoutSeconds = Math.max(0, plugin.getConfig().getInt("tpa.timeout-seconds", 60));
|
||||
strictTpaRequests = plugin.getConfig().getBoolean("tpa.strict-tpa-requests", false);
|
||||
strictTpaHereRequests = plugin.getConfig().getBoolean("tpa.strict-tpahere-requests", true);
|
||||
warmupSeconds = Math.max(0, plugin.getConfig().getInt("tpa.warmup-seconds", 5));
|
||||
@@ -102,15 +109,16 @@ public final class TeleportRequestManager implements Listener {
|
||||
cooldownsEnabled = plugin.getConfig().getBoolean("tpa.cooldowns.enabled", true);
|
||||
sendCooldownSeconds = Math.max(0, plugin.getConfig().getInt("tpa.cooldowns.cooldown-times.SEND_TELEPORT_REQUEST", 0));
|
||||
acceptCooldownSeconds = Math.max(0, plugin.getConfig().getInt("tpa.cooldowns.cooldown-times.ACCEPT_TELEPORT_REQUEST", 0));
|
||||
warmupMoveThreshold = Math.max(0.0D, plugin.getConfig().getDouble("tpa.warmup-move-threshold", 0.1D));
|
||||
warmupDisplay = plugin.getConfig().getString("tpa.warmup-display", "actionbar").toLowerCase();
|
||||
warmupDisplay = plugin.getConfig().getString("tpa.warmup-display", "actionbar").toLowerCase(Locale.ROOT);
|
||||
teleportInvulnerabilitySeconds = Math.max(0,
|
||||
plugin.getConfig().getInt("tpa.teleport-invulnerability-seconds", 0));
|
||||
teleportAsync = plugin.getConfig().getBoolean("tpa.teleport-async", true);
|
||||
soundsEnabled = plugin.getConfig().getBoolean("tpa.sounds.enabled", true);
|
||||
requestSound = plugin.getConfig().getString("tpa.sounds.request-received", "entity.experience_orb.pickup");
|
||||
warmupSound = plugin.getConfig().getString("tpa.sounds.warmup", "block.note_block.banjo");
|
||||
cancelSound = plugin.getConfig().getString("tpa.sounds.cancelled", "entity.item.break");
|
||||
completeSound = plugin.getConfig().getString("tpa.sounds.complete", "entity.enderman.teleport");
|
||||
loadIgnoringRequests();
|
||||
startCleanupTask();
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
@@ -118,7 +126,7 @@ public final class TeleportRequestManager implements Listener {
|
||||
sendCooldowns.clear();
|
||||
acceptCooldowns.clear();
|
||||
cancelAllWarmups();
|
||||
cancelCleanupTask();
|
||||
clearAllInvulnerability();
|
||||
saveIgnoringRequests();
|
||||
}
|
||||
|
||||
@@ -136,6 +144,9 @@ public final class TeleportRequestManager implements Listener {
|
||||
if (existingRequest.isPresent()
|
||||
&& existingRequest.get().type() == type
|
||||
&& !existingRequest.get().hasExpired()) {
|
||||
if (applyCooldown) {
|
||||
startCooldown(requester, sendCooldowns, sendCooldownSeconds);
|
||||
}
|
||||
return new CreateRequestResult(CreateRequestStatus.DUPLICATE, existingRequest.get());
|
||||
}
|
||||
|
||||
@@ -151,7 +162,7 @@ public final class TeleportRequestManager implements Listener {
|
||||
TeleportRequest.Status.PENDING
|
||||
);
|
||||
|
||||
if (isIgnoringRequests(target)) {
|
||||
if (isIgnoringRequests(target) || isVanished(target)) {
|
||||
request.setStatus(TeleportRequest.Status.IGNORED);
|
||||
if (applyCooldown) {
|
||||
startCooldown(requester, sendCooldowns, sendCooldownSeconds);
|
||||
@@ -225,35 +236,44 @@ public final class TeleportRequestManager implements Listener {
|
||||
return TeleportResult.onCooldown(acceptCooldown.seconds());
|
||||
}
|
||||
|
||||
removeIncomingByRequester(target, request.requesterName());
|
||||
if (request.hasExpired()) {
|
||||
removeIncomingByRequester(target, request.requesterName());
|
||||
return TeleportResult.EXPIRED;
|
||||
}
|
||||
|
||||
request.setStatus(TeleportRequest.Status.ACCEPTED);
|
||||
Map<String, String> placeholders = placeholders(request);
|
||||
target.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.accepted-target", placeholders));
|
||||
|
||||
Player requester = Bukkit.getPlayer(request.requesterId());
|
||||
Player currentTarget = Bukkit.getPlayer(request.targetId());
|
||||
if (requester == null || currentTarget == null || !requester.isOnline() || !currentTarget.isOnline()) {
|
||||
if (requester == null || !requester.isOnline()) {
|
||||
target.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.player-offline", placeholders));
|
||||
return TeleportResult.PLAYER_OFFLINE;
|
||||
}
|
||||
requester.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.accepted-sender", placeholders));
|
||||
|
||||
TeleportPlan plan = createTeleportPlan(request, requester, currentTarget);
|
||||
TeleportPlan plan = createTeleportPlan(request, requester, target);
|
||||
Player teleporter = plan.teleporter();
|
||||
int playerWarmupSeconds = getTeleportWarmupSeconds(teleporter);
|
||||
if (playerWarmupSeconds <= 0 || teleporter.hasPermission(BYPASS_WARMUP_PERMISSION)) {
|
||||
return executeTeleport(plan, true);
|
||||
}
|
||||
|
||||
if (warmups.containsKey(teleporter.getUniqueId())) {
|
||||
return TeleportResult.ALREADY_WARMING_UP;
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.already-warming-up"));
|
||||
return TeleportResult.ACCEPTED_WITHOUT_TELEPORT;
|
||||
}
|
||||
OptionalIntCooldown teleporterCooldown = getRemainingCooldown(teleporter, acceptCooldowns);
|
||||
if (teleporterCooldown.active()) {
|
||||
sendAcceptCooldown(teleporter, teleporterCooldown.seconds());
|
||||
return TeleportResult.ACCEPTED_WITHOUT_TELEPORT;
|
||||
}
|
||||
if (isMoving(teleporter)) {
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.warmup-stand-still"));
|
||||
return TeleportResult.ACCEPTED_WITHOUT_TELEPORT;
|
||||
}
|
||||
|
||||
removeIncomingByRequester(target, request.requesterName());
|
||||
request.setStatus(TeleportRequest.Status.ACCEPTED);
|
||||
if (warmupSeconds <= 0 || teleporter.hasPermission(BYPASS_WARMUP_PERMISSION)) {
|
||||
TeleportResult result = executeTeleport(plan, true);
|
||||
if (result.status() == TeleportResult.Status.SUCCESS) {
|
||||
startCooldown(target, acceptCooldowns, acceptCooldownSeconds);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
startWarmup(plan);
|
||||
startCooldown(target, acceptCooldowns, acceptCooldownSeconds);
|
||||
startWarmup(plan, playerWarmupSeconds);
|
||||
return TeleportResult.WARMING_UP;
|
||||
}
|
||||
|
||||
@@ -265,6 +285,14 @@ public final class TeleportRequestManager implements Listener {
|
||||
return TeleportResult.EXPIRED;
|
||||
}
|
||||
request.setStatus(TeleportRequest.Status.DECLINED);
|
||||
Map<String, String> placeholders = placeholders(request);
|
||||
target.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.denied-target", placeholders));
|
||||
Player requester = Bukkit.getPlayer(request.requesterId());
|
||||
if (requester != null && requester.isOnline()) {
|
||||
requester.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.denied-sender", placeholders));
|
||||
} else {
|
||||
target.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.player-offline", placeholders));
|
||||
}
|
||||
return TeleportResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -286,6 +314,16 @@ public final class TeleportRequestManager implements Listener {
|
||||
return ignoringRequests.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isVanished(Player player) {
|
||||
if (VanishCommand.isVanished(player)) {
|
||||
return true;
|
||||
}
|
||||
return player.hasMetadata("vanished") && player.getMetadata("vanished").stream()
|
||||
.map(metadata -> metadata.asBoolean())
|
||||
.findFirst()
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
public boolean toggleIgnoringRequests(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
boolean nowIgnoring;
|
||||
@@ -301,64 +339,52 @@ public final class TeleportRequestManager implements Listener {
|
||||
}
|
||||
|
||||
public void playRequestReceivedSound(Player player) {
|
||||
playConfiguredSound(player, requestSound, 0.7F, 1.0F);
|
||||
playConfiguredSound(player, requestSound, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
public int sendTeleportAllRequest(Player requester) {
|
||||
return sendTeleportAllRequest(requester, ignored -> true);
|
||||
}
|
||||
|
||||
public int sendTeleportAllRequest(Player requester, Predicate<Player> targetFilter) {
|
||||
OptionalIntCooldown sendCooldown = getRemainingCooldown(requester, sendCooldowns);
|
||||
if (sendCooldown.active()) {
|
||||
return -sendCooldown.seconds();
|
||||
}
|
||||
|
||||
int recipients = 0;
|
||||
for (Player target : Bukkit.getOnlinePlayers()) {
|
||||
if (target.getUniqueId().equals(requester.getUniqueId())) {
|
||||
continue;
|
||||
}
|
||||
if (!targetFilter.test(target)) {
|
||||
continue;
|
||||
}
|
||||
recipients++;
|
||||
CreateRequestResult result = createRequest(requester, target, TeleportRequest.Type.TPAHERE, false);
|
||||
if (result.status() != CreateRequestStatus.SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
Map<String, String> placeholders = placeholders(result.request());
|
||||
target.sendMessage(plugin.getLangManager().getPrefixedString("tpa.messages.received-tpahere", placeholders));
|
||||
sendResponseHint(target, result.request(), placeholders);
|
||||
target.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.received-tpahere", placeholders));
|
||||
sendResponseHint(target, placeholders);
|
||||
playRequestReceivedSound(target);
|
||||
}
|
||||
if (recipients > 0) {
|
||||
startCooldown(requester, sendCooldowns, sendCooldownSeconds);
|
||||
}
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public int getSendCooldownSeconds(Player player) {
|
||||
public int getRemainingSendCooldownSeconds(Player player) {
|
||||
return getRemainingCooldown(player, sendCooldowns).seconds();
|
||||
}
|
||||
|
||||
private void sendResponseHint(Player target, TeleportRequest request, Map<String, String> placeholders) {
|
||||
String requesterName = request.requesterName();
|
||||
String acceptCommand = "/tpaccept " + requesterName;
|
||||
String denyCommand = "/tpdeny " + requesterName;
|
||||
public Optional<Player> findOnlinePlayer(String playerName, Predicate<Player> filter) {
|
||||
Optional<Player> exactMatch = Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player.class::cast)
|
||||
.filter(filter)
|
||||
.filter(player -> player.getName().equalsIgnoreCase(playerName))
|
||||
.findFirst();
|
||||
if (exactMatch.isPresent()) {
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
Component hint = LegacyComponentSerializer.legacySection()
|
||||
.deserialize(plugin.getLangManager().getPrefixedString("tpa.messages.response-hint", placeholders));
|
||||
Component accept = LegacyComponentSerializer.legacySection()
|
||||
.deserialize(plugin.getLangManager().getString("tpa.messages.accept-button"))
|
||||
.clickEvent(ClickEvent.runCommand(acceptCommand))
|
||||
.hoverEvent(HoverEvent.showText(Component.text(acceptCommand, NamedTextColor.GREEN)));
|
||||
Component deny = LegacyComponentSerializer.legacySection()
|
||||
.deserialize(plugin.getLangManager().getString("tpa.messages.deny-button"))
|
||||
.clickEvent(ClickEvent.runCommand(denyCommand))
|
||||
.hoverEvent(HoverEvent.showText(Component.text(denyCommand, NamedTextColor.RED)));
|
||||
String playerNameLower = playerName.toLowerCase();
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player.class::cast)
|
||||
.filter(filter)
|
||||
.filter(player -> player.getName().toLowerCase().startsWith(playerNameLower))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
target.sendMessage(hint.append(Component.space()).append(accept).append(Component.space()).append(deny));
|
||||
public void sendResponseHint(Player target, Map<String, String> placeholders) {
|
||||
target.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.response-buttons", placeholders));
|
||||
}
|
||||
|
||||
public int getTimeoutSeconds() {
|
||||
@@ -406,19 +432,40 @@ public final class TeleportRequestManager implements Listener {
|
||||
);
|
||||
}
|
||||
|
||||
private void startWarmup(TeleportPlan plan) {
|
||||
private int getTeleportWarmupSeconds(Player player) {
|
||||
return player.getEffectivePermissions().stream()
|
||||
.filter(PermissionAttachmentInfo::getValue)
|
||||
.map(PermissionAttachmentInfo::getPermission)
|
||||
.filter(permission -> permission.startsWith(WARMUP_PERMISSION_PREFIX))
|
||||
.map(permission -> permission.substring(WARMUP_PERMISSION_PREFIX.length()))
|
||||
.mapToInt(this::parseWarmupPermission)
|
||||
.filter(seconds -> seconds >= 0)
|
||||
.max()
|
||||
.orElse(warmupSeconds);
|
||||
}
|
||||
|
||||
private int parseWarmupPermission(String value) {
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void startWarmup(TeleportPlan plan, int playerWarmupSeconds) {
|
||||
Player teleporter = plan.teleporter();
|
||||
UUID uuid = teleporter.getUniqueId();
|
||||
PendingTeleport pendingTeleport = new PendingTeleport(
|
||||
plan,
|
||||
teleporter.getLocation().clone(),
|
||||
warmupSeconds
|
||||
playerWarmupSeconds
|
||||
);
|
||||
warmupDamagedPlayers.remove(uuid);
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(plugin, () -> tickWarmup(uuid), 0L, 20L);
|
||||
pendingTeleport.setTask(task);
|
||||
warmups.put(uuid, pendingTeleport);
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedString("tpa.messages.warmup-start",
|
||||
Map.of("seconds", String.valueOf(warmupSeconds))));
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.warmup-start",
|
||||
Map.of("seconds", String.valueOf(playerWarmupSeconds))));
|
||||
}
|
||||
|
||||
private void tickWarmup(UUID teleporterId) {
|
||||
@@ -433,17 +480,28 @@ public final class TeleportRequestManager implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cancelWarmupOnDamage && warmupDamagedPlayers.contains(teleporterId)) {
|
||||
cancelWarmup(teleporterId, "tpa.messages.warmup-cancelled-damage", true);
|
||||
return;
|
||||
}
|
||||
if (cancelWarmupOnMove && hasMoved(pendingTeleport.startLocation(), teleporter.getLocation())) {
|
||||
cancelWarmup(teleporterId, "tpa.messages.warmup-cancelled-move", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pendingTeleport.remainingSeconds() <= 0) {
|
||||
sendWarmupStatus(teleporter, "tpa.messages.warmup-processing", Map.of());
|
||||
cancelWarmup(teleporterId, null, false);
|
||||
TeleportResult result = executeTeleport(pendingTeleport.plan(), true);
|
||||
if (result.status() == TeleportResult.Status.PLAYER_OFFLINE) {
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedString("tpa.messages.player-offline"));
|
||||
if (result.status() == TeleportResult.Status.ON_COOLDOWN) {
|
||||
sendAcceptCooldown(teleporter, result.cooldownSeconds());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sendWarmupStatus(teleporter, pendingTeleport.remainingSeconds());
|
||||
playConfiguredSound(teleporter, warmupSound, 0.5F, 1.0F);
|
||||
sendWarmupStatus(teleporter, "tpa.messages.warmup-status",
|
||||
Map.of("seconds", String.valueOf(pendingTeleport.remainingSeconds())));
|
||||
playConfiguredSound(teleporter, warmupSound, 1.0F, 1.0F);
|
||||
pendingTeleport.decrementRemainingSeconds();
|
||||
}
|
||||
|
||||
@@ -453,47 +511,143 @@ public final class TeleportRequestManager implements Listener {
|
||||
return TeleportResult.PLAYER_OFFLINE;
|
||||
}
|
||||
|
||||
OptionalIntCooldown acceptCooldown = getRemainingCooldown(teleporter, acceptCooldowns);
|
||||
if (acceptCooldown.active()) {
|
||||
return TeleportResult.onCooldown(acceptCooldown.seconds());
|
||||
}
|
||||
|
||||
Location destination = plan.fixedDestination();
|
||||
if (destination == null && plan.dynamicTargetId() != null) {
|
||||
Player dynamicTarget = Bukkit.getPlayer(plan.dynamicTargetId());
|
||||
if (dynamicTarget == null || !dynamicTarget.isOnline()) {
|
||||
return TeleportResult.PLAYER_OFFLINE;
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.target-offline"));
|
||||
return TeleportResult.TARGET_OFFLINE;
|
||||
}
|
||||
destination = dynamicTarget.getLocation().clone();
|
||||
}
|
||||
|
||||
if (destination == null) {
|
||||
return TeleportResult.PLAYER_OFFLINE;
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.target-offline"));
|
||||
return TeleportResult.TARGET_OFFLINE;
|
||||
}
|
||||
|
||||
teleporter.teleportAsync(destination).thenAccept(success -> {
|
||||
if (!success || !notifyCompletion) {
|
||||
return;
|
||||
teleporter.leaveVehicle();
|
||||
teleporter.eject();
|
||||
teleporter.setFallDistance(0.0F);
|
||||
startCooldown(teleporter, acceptCooldowns, acceptCooldownSeconds);
|
||||
if (teleportAsync) {
|
||||
try {
|
||||
teleporter.teleportAsync(destination, PlayerTeleportEvent.TeleportCause.PLUGIN)
|
||||
.whenComplete((success, throwable) -> {
|
||||
if (!plugin.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> handleTeleportCompletion(
|
||||
teleporter, Boolean.TRUE.equals(success), throwable, notifyCompletion));
|
||||
});
|
||||
} catch (RuntimeException exception) {
|
||||
handleTeleportCompletion(teleporter, false, exception, notifyCompletion);
|
||||
}
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (teleporter.isOnline()) {
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedString("tpa.messages.teleport-complete"));
|
||||
playConfiguredSound(teleporter, completeSound, 0.7F, 1.0F);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
boolean success = teleporter.teleport(destination, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
handleTeleportCompletion(teleporter, success, null, notifyCompletion);
|
||||
} catch (RuntimeException exception) {
|
||||
handleTeleportCompletion(teleporter, false, exception, notifyCompletion);
|
||||
}
|
||||
}
|
||||
return TeleportResult.SUCCESS;
|
||||
}
|
||||
|
||||
private void sendWarmupStatus(Player player, int seconds) {
|
||||
String message = plugin.getLangManager().getString("tpa.messages.warmup-status",
|
||||
Map.of("seconds", String.valueOf(seconds)));
|
||||
if ("actionbar".equalsIgnoreCase(warmupDisplay)) {
|
||||
player.sendActionBar(LegacyComponentSerializer.legacySection().deserialize(message));
|
||||
private void handleTeleportCompletion(Player teleporter, boolean success, Throwable throwable,
|
||||
boolean notifyCompletion) {
|
||||
if (!success) {
|
||||
if (teleporter.isOnline()) {
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.teleport-failed"));
|
||||
}
|
||||
if (throwable != null) {
|
||||
String detail = throwable.getMessage() == null
|
||||
? throwable.getClass().getSimpleName()
|
||||
: throwable.getMessage();
|
||||
plugin.getLogger().warning("TPA 传送执行失败: " + detail);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!"none".equalsIgnoreCase(warmupDisplay)) {
|
||||
player.sendMessage(message);
|
||||
|
||||
applyTeleportInvulnerability(teleporter);
|
||||
if (notifyCompletion && teleporter.isOnline()) {
|
||||
teleporter.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.teleport-complete"));
|
||||
playConfiguredSound(teleporter, completeSound, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyTeleportInvulnerability(Player player) {
|
||||
if (teleportInvulnerabilitySeconds <= 0 || !player.isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
BukkitTask previousTask = invulnerabilityTasks.remove(uuid);
|
||||
if (previousTask != null) {
|
||||
previousTask.cancel();
|
||||
}
|
||||
if (player.isInvulnerable() && !invulnerablePlayers.contains(uuid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
invulnerablePlayers.add(uuid);
|
||||
player.setInvulnerable(true);
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskLater(plugin,
|
||||
() -> clearInvulnerability(uuid), teleportInvulnerabilitySeconds * 20L);
|
||||
invulnerabilityTasks.put(uuid, task);
|
||||
}
|
||||
|
||||
private void clearInvulnerability(UUID uuid) {
|
||||
BukkitTask task = invulnerabilityTasks.remove(uuid);
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
if (!invulnerablePlayers.remove(uuid)) {
|
||||
return;
|
||||
}
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
player.setInvulnerable(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearAllInvulnerability() {
|
||||
for (BukkitTask task : invulnerabilityTasks.values()) {
|
||||
task.cancel();
|
||||
}
|
||||
invulnerabilityTasks.clear();
|
||||
for (UUID uuid : new HashSet<>(invulnerablePlayers)) {
|
||||
clearInvulnerability(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendAcceptCooldown(Player player, int seconds) {
|
||||
player.sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.accept-cooldown",
|
||||
Map.of("seconds", String.valueOf(seconds))));
|
||||
}
|
||||
|
||||
private void sendWarmupStatus(Player player, String messagePath, Map<String, String> placeholders) {
|
||||
net.kyori.adventure.text.Component message = plugin.getLangManager().getPrefixedComponent(messagePath, placeholders);
|
||||
switch (warmupDisplay.replace("-", "_")) {
|
||||
case "actionbar", "action_bar" -> player.sendActionBar(message);
|
||||
case "title" -> player.showTitle(Title.title(message, net.kyori.adventure.text.Component.empty(),
|
||||
Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ofMillis(250))));
|
||||
case "subtitle" -> player.showTitle(Title.title(net.kyori.adventure.text.Component.empty(), message,
|
||||
Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ofMillis(250))));
|
||||
case "none" -> {
|
||||
}
|
||||
default -> player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelWarmup(UUID teleporterId, String messagePath, boolean playSound) {
|
||||
PendingTeleport pendingTeleport = warmups.remove(teleporterId);
|
||||
warmupDamagedPlayers.remove(teleporterId);
|
||||
if (pendingTeleport == null) {
|
||||
return;
|
||||
}
|
||||
@@ -503,9 +657,10 @@ public final class TeleportRequestManager implements Listener {
|
||||
|
||||
Player player = Bukkit.getPlayer(teleporterId);
|
||||
if (player != null && player.isOnline() && messagePath != null) {
|
||||
player.sendMessage(plugin.getLangManager().getPrefixedString(messagePath));
|
||||
player.sendMessage(plugin.getLangManager().getPrefixedComponent(messagePath));
|
||||
sendWarmupStatus(player, "tpa.messages.warmup-cancelled-actionbar", Map.of());
|
||||
if (playSound) {
|
||||
playConfiguredSound(player, cancelSound, 0.7F, 1.0F);
|
||||
playConfiguredSound(player, cancelSound, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -542,17 +697,6 @@ public final class TeleportRequestManager implements Listener {
|
||||
return removed;
|
||||
}
|
||||
|
||||
public void purgeExpired() {
|
||||
List<UUID> emptyQueues = new ArrayList<>();
|
||||
for (Map.Entry<UUID, Deque<TeleportRequest>> entry : requests.entrySet()) {
|
||||
entry.getValue().removeIf(TeleportRequest::hasExpired);
|
||||
if (entry.getValue().isEmpty()) {
|
||||
emptyQueues.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
emptyQueues.forEach(requests::remove);
|
||||
}
|
||||
|
||||
public Map<String, String> placeholders(TeleportRequest request) {
|
||||
Map<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("requester", request.requesterName());
|
||||
@@ -562,32 +706,13 @@ public final class TeleportRequestManager implements Listener {
|
||||
return placeholders;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
private void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (!cancelWarmupOnMove || !warmups.containsKey(event.getPlayer().getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
PendingTeleport pendingTeleport = warmups.get(event.getPlayer().getUniqueId());
|
||||
Location start = pendingTeleport.startLocation();
|
||||
Location to = event.getTo();
|
||||
if (to == null || !sameWorld(start, to)) {
|
||||
cancelWarmup(event.getPlayer().getUniqueId(), "tpa.messages.warmup-cancelled-move", true);
|
||||
return;
|
||||
}
|
||||
|
||||
double distance = Math.abs(start.getX() - to.getX())
|
||||
+ Math.abs(start.getY() - to.getY())
|
||||
+ Math.abs(start.getZ() - to.getZ());
|
||||
if (distance > warmupMoveThreshold) {
|
||||
cancelWarmup(event.getPlayer().getUniqueId(), "tpa.messages.warmup-cancelled-move", true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
private void onEntityDamage(EntityDamageEvent event) {
|
||||
if (cancelWarmupOnDamage && event.getEntity() instanceof Player player && warmups.containsKey(player.getUniqueId())) {
|
||||
cancelWarmup(player.getUniqueId(), "tpa.messages.warmup-cancelled-damage", true);
|
||||
if (event.getDamage() <= 0) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof Player player && warmups.containsKey(player.getUniqueId())) {
|
||||
warmupDamagedPlayers.add(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,33 +722,29 @@ public final class TeleportRequestManager implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPlayer().sendMessage(plugin.getLangManager().getPrefixedString("tpa.messages.ignore-notification"));
|
||||
event.getPlayer().sendMessage(plugin.getLangManager().getPrefixedComponent("tpa.messages.ignore-notification"));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onPlayerQuit(PlayerQuitEvent event) {
|
||||
cancelWarmup(event.getPlayer().getUniqueId(), null, false);
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
cancelWarmup(uuid, null, false);
|
||||
clearInvulnerability(uuid);
|
||||
}
|
||||
|
||||
private void startCleanupTask() {
|
||||
if (cleanupTask != null) {
|
||||
return;
|
||||
private boolean hasMoved(Location start, Location current) {
|
||||
if (start.getWorld() == null || current.getWorld() == null
|
||||
|| !start.getWorld().getUID().equals(current.getWorld().getUID())) {
|
||||
return true;
|
||||
}
|
||||
cleanupTask = Bukkit.getScheduler().runTaskTimer(plugin, this::purgeExpired, 20L * 60L, 20L * 60L);
|
||||
double distance = Math.abs(start.getX() - current.getX())
|
||||
+ Math.abs(start.getY() - current.getY())
|
||||
+ Math.abs(start.getZ() - current.getZ());
|
||||
return distance > MOVEMENT_THRESHOLD;
|
||||
}
|
||||
|
||||
private void cancelCleanupTask() {
|
||||
if (cleanupTask == null) {
|
||||
return;
|
||||
}
|
||||
cleanupTask.cancel();
|
||||
cleanupTask = null;
|
||||
}
|
||||
|
||||
private boolean sameWorld(Location first, Location second) {
|
||||
return first.getWorld() != null
|
||||
&& second.getWorld() != null
|
||||
&& first.getWorld().getUID().equals(second.getWorld().getUID());
|
||||
private boolean isMoving(Player player) {
|
||||
return player.getVelocity().length() >= MOVEMENT_THRESHOLD;
|
||||
}
|
||||
|
||||
private void loadIgnoringRequests() {
|
||||
@@ -673,7 +794,9 @@ public final class TeleportRequestManager implements Listener {
|
||||
public static final TeleportResult WARMING_UP = new TeleportResult(Status.WARMING_UP, 0);
|
||||
public static final TeleportResult EXPIRED = new TeleportResult(Status.EXPIRED, 0);
|
||||
public static final TeleportResult PLAYER_OFFLINE = new TeleportResult(Status.PLAYER_OFFLINE, 0);
|
||||
public static final TeleportResult TARGET_OFFLINE = new TeleportResult(Status.TARGET_OFFLINE, 0);
|
||||
public static final TeleportResult ALREADY_WARMING_UP = new TeleportResult(Status.ALREADY_WARMING_UP, 0);
|
||||
public static final TeleportResult ACCEPTED_WITHOUT_TELEPORT = new TeleportResult(Status.ACCEPTED_WITHOUT_TELEPORT, 0);
|
||||
|
||||
public static TeleportResult onCooldown(int seconds) {
|
||||
return new TeleportResult(Status.ON_COOLDOWN, seconds);
|
||||
@@ -684,7 +807,9 @@ public final class TeleportRequestManager implements Listener {
|
||||
WARMING_UP,
|
||||
EXPIRED,
|
||||
PLAYER_OFFLINE,
|
||||
TARGET_OFFLINE,
|
||||
ALREADY_WARMING_UP,
|
||||
ACCEPTED_WITHOUT_TELEPORT,
|
||||
ON_COOLDOWN
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user