Skip to content

Commit 9654aaf

Browse files
优化语言系统
1 parent 95a2a0f commit 9654aaf

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

src/main/java/top/mpt/huihui/answerit/Main.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package top.mpt.huihui.answerit;
22

3+
import com.google.common.base.Charsets;
34
import org.bukkit.ChatColor;
45
import org.bukkit.configuration.file.FileConfiguration;
56
import org.bukkit.configuration.file.YamlConfiguration;
@@ -8,8 +9,8 @@
89
import top.mpt.huihui.answerit.listener.InvOpen;
910
import top.mpt.huihui.answerit.listener.PlayerChat;
1011

11-
import java.io.File;
12-
import java.io.IOException;
12+
import java.io.*;
13+
import java.nio.channels.FileChannel;
1314
import java.util.ArrayList;
1415
import java.util.List;
1516

@@ -38,15 +39,13 @@ public void onEnable() {
3839
// config
3940
getConfig().options().copyDefaults();
4041
saveDefaultConfig();
41-
// lang sys
42-
File file = new File(getDataFolder() + "\\lang", getConfig().getString("lang"));
43-
config = YamlConfiguration.loadConfiguration(file);
44-
config.options().copyDefaults();
45-
try {
46-
config.save(file);
47-
} catch (IOException e) {
48-
throw new RuntimeException(e);
42+
File file = new File(getDataFolder() + "\\lang\\", getConfig().getString("lang"));
43+
if (!file.exists()) {
44+
saveResource("lang/zh_cn.yml", false);
45+
saveResource("lang/en_us.yml", false);
4946
}
47+
config = YamlConfiguration.loadConfiguration(file);
48+
5049
// 指令
5150
getCommand("answer").setExecutor(new CommandHandler());
5251
// 注册事件

src/main/java/top/mpt/huihui/answerit/commands/impl/q.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public boolean onCommand(CommandSender sender, String[] args) {
4343
q.sender = (Player)sender;
4444
// ClickEvent用
4545
TextComponent message = null;
46+
// 防止index out of range
47+
if (args.length < 3){
48+
PlayerUtils.send(sender, ConfigUtils.getConfig(config, "global.command_err_format"));
49+
PlayerUtils.send(sender, "/answer q [PlayerName] [Question] [Type] [answer*n if select]");
50+
return true;
51+
}
4652
// 接收问答的人
4753
// 给event传参用
4854
target = Bukkit.getPlayer(args[0]);

src/main/java/top/mpt/huihui/answerit/commands/impl/reload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public reload(){
1717
public boolean onCommand(CommandSender sender, String[] args) {
1818
JavaPlugin main = getPlugin(Main.class);
1919
main.reloadConfig();
20-
File file = new File(getPlugin(Main.class).getDataFolder() + "\\lang", main.getConfig().getString("lang"));
20+
File file = new File(main.getDataFolder() + "\\lang", main.getConfig().getString("lang"));
2121
config = YamlConfiguration.loadConfiguration(file);
2222
sender.sendMessage("[AnswerIt] Plugin Reload Completed");
2323
return true;

src/main/java/top/mpt/huihui/answerit/commands/impl/send.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public boolean onCommand(CommandSender sender, String[] args){
2121
// args[1] == NameFlying(提问者)
2222
if (sender instanceof Player){
2323
if (!prize.canPrize){
24-
PlayerUtils.send(sender, ConfigUtils.getConfig(config, "player_cant_answer"));
24+
PlayerUtils.send(sender, ConfigUtils.getConfig(config, "global.player_cant_answer"));
2525
return true;
2626
}
2727
if (args.length != 2){

src/main/java/top/mpt/huihui/answerit/commands/impl/setAnswer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public boolean onCommand(CommandSender sender, String[] args){
3838
// 发送消息
3939
sendQuestion(((Player) sender).getPlayer(), args[2], args[3]);
4040
} else {
41-
sender.sendMessage((String) ConfigUtils.getConfig(config, "mode_err"));
41+
sender.sendMessage((String) ConfigUtils.getConfig(config, "sender_err"));
4242
}
4343
return true;
4444
}

src/main/resources/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Language
2+
# need reload to enable
3+
# please write the file name with suffix
24
lang: "zh_cn.yml"
35

46
# Write模式下,投票的等待时间(秒)
57
# 需要reload启用
8+
# Write Mode, Time for voting(seconds)
9+
# need reload to enable
610
Write-wait-time: 30
711

0 commit comments

Comments
 (0)