1
mirror of https://github.com/CarmJos/UserPrefix.git synced 2024-09-19 20:15:47 +00:00

当出现错误时,将发送错误的前缀是哪一个。

This commit is contained in:
carm 2021-09-15 16:36:25 +08:00
parent ee2cc259ef
commit 85f5e7d95a
3 changed files with 55 additions and 33 deletions

View File

@ -43,12 +43,15 @@ public class Main extends JavaPlugin {
log("注册变量...");
new UserPrefixExpansion(getInstance()).register();
} else {
log("未安装 PlaceholderAPI 放弃注册变量...");
log("未安装 PlaceholderAPI 不进行变量注册...");
log("若您想使用变量进行前缀的显示请安装PlaceholderAPI");
}
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
showAD();
if (Bukkit.getOnlinePlayers().size() > 0) {
Bukkit.getOnlinePlayers().forEach(UserManager::initPlayer); // 适配热重载
}
@ -64,6 +67,9 @@ public class Main extends JavaPlugin {
Bukkit.getServicesManager().unregisterAll(this);
log("卸载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
showAD();
}
/**
@ -89,4 +95,9 @@ public class Main extends JavaPlugin {
return instance;
}
private void showAD() {
log("&7感谢您使用 &3&lUserPrefix " + getDescription().getVersion() + "&7!");
log("&7本插件由 &b&lYourCraft &7提供长期支持与维护。");
}
}

View File

@ -41,22 +41,26 @@ public class PrefixManager {
for (String prefixIdentifier : prefixesSection.getKeys(false)) {
ConfigurationSection configuredPrefixSection = prefixesSection.getConfigurationSection(prefixIdentifier);
if (configuredPrefixSection == null) continue;
try {
String name = configuredPrefixSection.getString("name", "前缀名配置错误");
String content = configuredPrefixSection.getString("content", "&r");
String permission = configuredPrefixSection.getString("permission");
int weight = configuredPrefixSection.getInt("weight", 1);
String name = configuredPrefixSection.getString("name", "前缀名配置错误");
String content = configuredPrefixSection.getString("content", "&r");
String permission = configuredPrefixSection.getString("permission");
int weight = configuredPrefixSection.getInt("weight", 1);
ItemStack itemHasPermission = configuredPrefixSection.getItemStack("itemHasPermission",
new ItemStackFactory(Material.STONE).setDisplayName(name).addLore(" ").addLore("§a➥ 点击切换到该前缀").toItemStack()
);
ItemStack itemNoPermission = configuredPrefixSection.getItemStack("itemNoPermission", itemHasPermission);
ItemStack itemUsing = configuredPrefixSection.getItemStack("itemUsing", itemHasPermission);
ItemStack itemHasPermission = configuredPrefixSection.getItemStack("itemHasPermission",
new ItemStackFactory(Material.STONE).setDisplayName(name).addLore(" ").addLore("§a➥ 点击切换到该前缀").toItemStack()
);
ItemStack itemNoPermission = configuredPrefixSection.getItemStack("itemNoPermission", itemHasPermission);
ItemStack itemUsing = configuredPrefixSection.getItemStack("itemUsing", itemHasPermission);
Main.log("完成前缀加载 " + prefixIdentifier + " : " + name);
Main.log("完成前缀加载 " + prefixIdentifier + " : " + name);
dataPrefixes.put(prefixIdentifier, new ConfiguredPrefix(prefixIdentifier, name, content, weight, permission, itemHasPermission, itemNoPermission, itemUsing));
dataPrefixes.put(prefixIdentifier, new ConfiguredPrefix(prefixIdentifier, name, content, weight, permission, itemHasPermission, itemNoPermission, itemUsing));
} catch (Exception exception) {
Main.log("在加载前缀 " + prefixIdentifier + " 时出错,请检查配置!");
exception.printStackTrace();
}
}
PrefixManager.prefixes.clear();
@ -67,26 +71,31 @@ public class PrefixManager {
PrefixManager.defaultPrefix = null;
ConfigurationSection defaultPrefixSection = ConfigManager.getConfig().getConfigurationSection("defaultPrefix");
if (defaultPrefixSection != null) {
String name = defaultPrefixSection.getString("name", "默认前缀");
String content = defaultPrefixSection.getString("content", "&r");
ItemStack itemNotUsing = defaultPrefixSection.getItemStack(
"itemNotUsing",
new ItemStackFactory(Material.NAME_TAG)
.setDisplayName("&f默认前缀")
.addLore(" ")
.addLore("§a➥ 点击切换到该前缀")
.toItemStack()
);
ItemStack itemUsing = defaultPrefixSection.getItemStack("itemUsing",
new ItemStackFactory(Material.NAME_TAG)
.setDisplayName("&f默认前缀")
.addLore(" ")
.addLore("§a✔ 您正在使用该前缀")
.addEnchant(Enchantment.DURABILITY, 1, false)
.addFlag(ItemFlag.HIDE_ENCHANTS)
.toItemStack()
);
PrefixManager.defaultPrefix = new ConfiguredPrefix("default", name, content, 0, null, itemNotUsing, null, itemUsing);
try {
String name = defaultPrefixSection.getString("name", "默认前缀");
String content = defaultPrefixSection.getString("content", "&r");
ItemStack itemNotUsing = defaultPrefixSection.getItemStack(
"itemNotUsing",
new ItemStackFactory(Material.NAME_TAG)
.setDisplayName("&f默认前缀")
.addLore(" ")
.addLore("§a➥ 点击切换到该前缀")
.toItemStack()
);
ItemStack itemUsing = defaultPrefixSection.getItemStack("itemUsing",
new ItemStackFactory(Material.NAME_TAG)
.setDisplayName("&f默认前缀")
.addLore(" ")
.addLore("§a✔ 您正在使用该前缀")
.addEnchant(Enchantment.DURABILITY, 1, false)
.addFlag(ItemFlag.HIDE_ENCHANTS)
.toItemStack()
);
PrefixManager.defaultPrefix = new ConfiguredPrefix("default", name, content, 0, null, itemNotUsing, null, itemUsing);
} catch (Exception ex) {
Main.log("在加载默认前缀时出错,请检查配置!");
ex.printStackTrace();
}
} else {
PrefixManager.defaultPrefix = new ConfiguredPrefix("default", "默认前缀", "&r", 0, null,
new ItemStackFactory(Material.NAME_TAG)

View File

@ -3,6 +3,8 @@ name: UserPrefix
version: ${project.version}
authors:
- Carm
- YourCraft
- SakuraGame
depend:
- LuckPerms
softdepend: