Skip to content

Commit

Permalink
update to 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
myunco committed Feb 11, 2022
1 parent b425587 commit 22aab01
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
lore-exact: true

#匹配物品类型 可选 没有此项则不限物品类型 (虽然name,lore,type都是可选的,但至少要提供一个)
#如果你不知道某个物品的类型是什么 可以使用/ic add type命令将物品添加到物品配置文件 即可看到类型
#如果你不知道某个物品的类型是什么 可以使用 /ic type 命令查看手持物品的类型
type: 'PAPER'

#使用物品需要满足的条件 一行一个条件 可选 支持变量 格式为 类型:表达式,不满足条件时显示的消息(不想显示消息的话 只写,即可)
Expand Down
7 changes: 5 additions & 2 deletions src/lang/zh_cn.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#语言文件版本号 请勿修改
version: 1
version: 2

log-prefix: '[ItemCommand] '
message-prefix: '§8[§3ItemCommand§8] '
Expand All @@ -18,7 +18,7 @@ load-item-error-not-match: '§4加载 {0} 时出错! name、lore、type 至少
load-item-error-unknown-type: '§e加载 {0} 时出错! 未知的物品类型: type: {1}'
load-item-error-not-found-operator: '§e加载条件时出错! 在条件中未找到运算符: {0}'
load-item-error-unknown-trigger: '§e加载 {0} 时出错! 未知的触发方式: {1}'
action-execute-error-sound: '§e错误: 指定的音效 {0} 不存在'
action-execute-error-sound: '§e错误: 无法执行 sound(-all) 动作! 原因: 指定的音效 {0} 不存在'
action-execute-error-give-money-not-found-economy: '§e未找到经济插件, 无法执行 give-money 动作!'
action-execute-error-give-money-not-found-economy-tip: '§e请检查是否正确安装Vault插件以及经济提供插件! (如Essentials、CMI、Economy等)'
action-execute-error-give-money-invalid-value: '§e错误: 无法执行 give-money 动作! 原因: 无效的数字格式: {0}'
Expand Down Expand Up @@ -61,3 +61,6 @@ command-give-invalid-amount: '§c参数错误: 无效的数量: {0}'
command-give-error-amount: '§c错误: 物品数量不能小于1'
command-give-invalid-type: '§c错误: 无效的物品类型: {0}'
command-give: '§a已将§b{0}§a个{1}§a添加到§c{2}§a的物品栏.'
command-type-not-item: '§d你确定你手里有物品?'
command-type-console: '§a控制台无法使用此命令。'
command-type: '§a当前手持物品的类型是: §b{0}'
12 changes: 7 additions & 5 deletions src/ml/mcos/itemcommand/ItemCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ public void init() {
if (points == null) {
setupPoints();
}
Plugin papi = getServer().getPluginManager().getPlugin("PlaceholderAPI");
enablePAPI = papi != null && papi.isEnabled();
if (enablePAPI) {
papiVersion = papi.getDescription().getVersion();
logMessage("Found PlaceholderAPI: §3v" + papiVersion);
if (!enablePAPI) {
Plugin papi = getServer().getPluginManager().getPlugin("PlaceholderAPI");
enablePAPI = papi != null && papi.isEnabled();
if (enablePAPI) {
papiVersion = papi.getDescription().getVersion();
logMessage("Found PlaceholderAPI: §3v" + papiVersion);
}
}
ItemInfo.loadItemInfo(this);
}
Expand Down
17 changes: 17 additions & 0 deletions src/ml/mcos/itemcommand/command/ICCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
plugin.init();
sendMessage(sender, Language.commandReload);
break;
case "type":
commandType(sender);
break;
case "version":
sendMessage(sender, Language.replaceArgs(Language.commandVersion, plugin.getDescription().getVersion()));
break;
Expand Down Expand Up @@ -229,4 +232,18 @@ private void commandGive(CommandSender sender, String[] args) {
}
}

@SuppressWarnings("deprecation")
private void commandType(CommandSender sender) {
if (sender instanceof Player) {
ItemStack item = plugin.getMcVersion() > 8 ? ((Player) sender).getInventory().getItemInMainHand() : ((Player) sender).getItemInHand();
if (item.getType() == Material.AIR) {
sendMessage(sender, Language.commandTypeNotItem);
return;
}
sendMessage(sender, Language.replaceArgs(Language.commandType, item.getType()));
return;
}
sendMessage(sender, Language.commandTypeConsole);
}

}
2 changes: 1 addition & 1 deletion src/ml/mcos/itemcommand/command/TabComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TabComplete {
public static List<String> typeList = Arrays.stream(Material.values()).map(Material::toString).collect(Collectors.toList());

static {
tabListMap.put("ItemCommand", Arrays.asList("add", "give", "list", "reload", "version"));
tabListMap.put("ItemCommand", Arrays.asList("add", "give", "list", "reload", "type", "version"));
tabListMap.put("ItemCommand.add", Arrays.asList("name", "lore", "type", "lore-exact", "condition" ,"trigger", "action", "price", "points", "levels" ,"permission", "required-amount", "cooldown"));
tabListMap.put("ItemCommand.give", Collections.emptyList());
for (int i = 1; i <= 64; i++) {
Expand Down
30 changes: 23 additions & 7 deletions src/ml/mcos/itemcommand/config/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class Language {
public static String commandGiveErrorAmount;
public static String commandGiveInvalidType;
public static String commandGive;
public static String commandTypeNotItem;
public static String commandTypeConsole;
public static String commandType;

public static void loadLanguage(String language) {
if (language == null || !language.matches("[a-zA-Z]{2}[_-][a-zA-Z]{2}")) {
Expand Down Expand Up @@ -100,7 +103,7 @@ public static void loadLanguage(String language) {
loadItemErrorUnknownType = config.getString("load-item-error-unknown-type", "§e加载 {0} 时出错! 未知的物品类型: type: {1}");
loadItemErrorNotFoundOperator = config.getString("load-item-error-not-found-operator", "§e加载条件时出错! 在条件中未找到运算符: {0}");
loadItemErrorUnknownTrigger = config.getString("load-item-error-unknown-trigger", "§e加载 {0} 时出错! 未知的触发方式: {1}");
actionExecuteErrorSound = config.getString("action-execute-error-sound", "§e错误: 指定的音效 {0} 不存在");
actionExecuteErrorSound = config.getString("action-execute-error-sound", "§e错误: 无法执行 sound(-all) 动作! 原因: 指定的音效 {0} 不存在");
actionExecuteErrorGiveMoneyNotFoundEconomy = config.getString("action-execute-error-give-money-not-found-economy", "§e未找到经济插件, 无法执行 give-money 动作!");
actionExecuteErrorGiveMoneyNotFoundEconomyTip = config.getString("action-execute-error-give-money-not-found-economy-tip", "§e请检查是否正确安装Vault插件以及经济提供插件! (如Essentials、CMI、Economy等)");
actionExecuteErrorGiveMoneyInvalidValue = config.getString("action-execute-error-give-money-invalid-value", "§e错误: 无法执行 give-money 动作! 原因: 无效的数字格式: {0}");
Expand Down Expand Up @@ -143,7 +146,9 @@ public static void loadLanguage(String language) {
commandGiveErrorAmount = config.getString("command-give-error-amount", "§c错误: 物品数量不能小于1");
commandGiveInvalidType = config.getString("command-give-invalid-type", "§c错误: 无效的物品类型: {0}");
commandGive = config.getString("command-give", "§a已将§b{0}§a个{1}§a添加到§c{2}§a的物品栏.");

commandTypeNotItem = config.getString("command-type-not-item", "§d你确定你手里有物品?");
commandTypeConsole = config.getString("command-type-console", "§a控制台无法使用此命令。");
commandType = config.getString("command-type", "§a当前手持物品的类型是: §b{0}");
}

private static void saveDefaultLanguage(File lang, String langPath) {
Expand Down Expand Up @@ -174,11 +179,22 @@ private static void saveDefaultLanguage(File lang, String langPath) {
}

private static void languageUpdate(YamlConfiguration config, File lang) {
int currentVersion = 1;
if (version < currentVersion) {
//语言文件目前只有一个版本 升级代码暂时不写
plugin.getLogger().warning(Language.languageVersionError + Language.version);
config.set("version", 1);
int latestVersion = 2;
if (version < latestVersion) {
plugin.logMessage(replaceArgs(languageVersionOutdated, version, latestVersion));
switch (version) {
case 1:
config.set("command-type-not-item", "§d你确定你手里有物品?");
config.set("command-type-console", "§a控制台无法使用此命令。");
config.set("command-type", "§a当前手持物品的类型是: §b{0}");
break;
default:
plugin.logMessage(languageVersionError + version);
return;
}
plugin.logMessage(languageUpdateComplete);
version = latestVersion;
config.set("version", latestVersion);
Config.saveConfiguration(config, lang);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ItemCommand
main: ml.mcos.itemcommand.ItemCommand
version: 1.0.3-SNAPSHOT
version: 1.0.3
api-version: 1.13
author: myunco
softdepend:
Expand All @@ -9,7 +9,7 @@ softdepend:
- PlaceholderAPI
commands:
ItemCommand:
usage: '§6用法: /ItemCommand §e<§6add§7|§6give§7|§6list§7|§6reload§7|§6version§e>'
usage: '§6用法: /ItemCommand §e<§6add§7|§6give§7|§6list§7|§6reload§7|§6type§7|§6version§e>'
aliases: ic
permission: itemcommand.admin
permission-message: '§cYou don''t have permission!'
Expand Down

0 comments on commit 22aab01

Please sign in to comment.