diff --git a/pom.xml b/pom.xml
index 9203e1b..75a753e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.mstiles92.plugins
BookRules
- 2.1.1
+ 2.1.2-SNAPSHOT
UTF-8
diff --git a/src/main/java/com/mstiles92/plugins/bookrules/BookRules.java b/src/main/java/com/mstiles92/plugins/bookrules/BookRules.java
index 77b7415..53ed6fa 100644
--- a/src/main/java/com/mstiles92/plugins/bookrules/BookRules.java
+++ b/src/main/java/com/mstiles92/plugins/bookrules/BookRules.java
@@ -49,7 +49,6 @@
public class BookRules extends JavaPlugin {
private static BookRules instance = null;
- private Config config;
private UpdateChecker updateChecker;
private CommandRegistry commandRegistry;
@@ -57,9 +56,11 @@ public class BookRules extends JavaPlugin {
public void onEnable() {
instance = this;
- config = new Config();
+ saveDefaultConfig();
+ Config.loadFromConfig(getConfig());
+ saveConfig();
- if (!Localization.load(Language.fromAbbreviation(config.getLanguage()))) {
+ if (!Localization.load(Language.fromAbbreviation(Config.getLanguage()))) {
Log.warning("Error loading language file. BookRules will now be disabled.");
getPluginLoader().disablePlugin(this);
}
@@ -72,7 +73,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
- if (config.shouldCheckForUpdates()) {
+ if (Config.shouldCheckForUpdates()) {
updateChecker = new UpdateChecker(this, 44081, "bookrules", 216000);
updateChecker.start();
}
@@ -95,10 +96,6 @@ public void onDisable() {
}
- public Config getConfigObject() {
- return config;
- }
-
public UpdateChecker getUpdateChecker() {
return updateChecker;
}
diff --git a/src/main/java/com/mstiles92/plugins/bookrules/commands/BookRulesCommands.java b/src/main/java/com/mstiles92/plugins/bookrules/commands/BookRulesCommands.java
index f5d615f..1953fc7 100644
--- a/src/main/java/com/mstiles92/plugins/bookrules/commands/BookRulesCommands.java
+++ b/src/main/java/com/mstiles92/plugins/bookrules/commands/BookRulesCommands.java
@@ -24,6 +24,7 @@
package com.mstiles92.plugins.bookrules.commands;
import com.mstiles92.plugins.bookrules.BookRules;
+import com.mstiles92.plugins.bookrules.config.Config;
import com.mstiles92.plugins.bookrules.localization.Localization;
import com.mstiles92.plugins.bookrules.localization.Strings;
import com.mstiles92.plugins.bookrules.util.BookStorage;
@@ -53,7 +54,7 @@ public class BookRulesCommands implements CommandHandler {
public void bookrules(Arguments args) {
String currentVersion = BookRules.getInstance().getDescription().getVersion();
args.getSender().sendMessage(ChatColor.BLUE + String.format(Localization.getString(Strings.VERSION_MESSAGE), currentVersion));
- if (BookRules.getInstance().getConfigObject().shouldCheckForUpdates()) {
+ if (Config.shouldCheckForUpdates()) {
UpdateChecker updateChecker = BookRules.getInstance().getUpdateChecker();
if (updateChecker.isUpdateAvailable()) {
args.getSender().sendMessage(ChatColor.BLUE + Localization.getString(Strings.UPDATE_AVAILIBLE));
@@ -141,6 +142,7 @@ public List completeCommands(Arguments args) {
@Command(name = "bookrules.reload", aliases = {"rulebook.reload", "rb.reload", "br.reload"}, permission = "bookrules.reload")
public void reload(Arguments args) {
+ Config.loadFromConfig(BookRules.getInstance().getConfig());
BookStorage.getInstance().loadFromFile();
args.getSender().sendMessage(Strings.PLUGIN_TAG + Localization.getString(Strings.CONFIG_RELOADED));
}
diff --git a/src/main/java/com/mstiles92/plugins/bookrules/config/Config.java b/src/main/java/com/mstiles92/plugins/bookrules/config/Config.java
index 5beb4c4..5dc4e3e 100644
--- a/src/main/java/com/mstiles92/plugins/bookrules/config/Config.java
+++ b/src/main/java/com/mstiles92/plugins/bookrules/config/Config.java
@@ -23,55 +23,67 @@
package com.mstiles92.plugins.bookrules.config;
-import com.mstiles92.plugins.bookrules.BookRules;
import org.bukkit.configuration.file.FileConfiguration;
public class Config {
- private FileConfiguration config;
+ private static boolean checkForUpdates = true;
+ private static boolean verboseOutput = false;
+ private static boolean giveOnEveryJoin = false;
+ private static boolean giveNewBooksOnJoin = true;
+ private static boolean notifyPlayers = true;
+ private static int runnableDelay = 20;
+ private static boolean blockTrading = true;
+ private static String language = "EN";
- public Config() {
- config = BookRules.getInstance().getConfig();
- config.options().copyDefaults(true);
- updateOldConfig();
- BookRules.getInstance().saveConfig();
+ public static void loadFromConfig(FileConfiguration config) {
+ updateOldConfig(config);
+
+ checkForUpdates = config.getBoolean("Check-for-Updates", true);
+ verboseOutput = config.getBoolean("Verbose", false);
+ giveOnEveryJoin = config.getBoolean("Give-Books-Every-Join", false);
+ giveNewBooksOnJoin = config.getBoolean("Give-New-Books-On-Join", true);
+ notifyPlayers = config.getBoolean("Display-Messages", true);
+ runnableDelay = config.getInt("Seconds-Delay", 1) * 20;
+ blockTrading = config.getBoolean("Block-Villager-Book-Trading", true);
+ language = config.getString("Language", "EN");
}
- private void updateOldConfig() {
+ private static void updateOldConfig(FileConfiguration config) {
if (config.contains("Give-Books-On-First-Join")) {
config.set("Give-New-Books-On-Join", config.get("Give-Books-On-First-Join"));
config.set("Give-Books-On-First-Join", null);
}
}
- public boolean shouldCheckForUpdates() {
- return config.getBoolean("Check-for-Updates");
+ public static boolean shouldCheckForUpdates() {
+ return checkForUpdates;
}
- public boolean verboseOutputEnabled() {
- return config.getBoolean("Verbose");
+ public static boolean verboseOutputEnabled() {
+ return verboseOutput;
}
- public boolean shouldGiveBooksEveryJoin() {
- return config.getBoolean("Give-Books-Every-Join");
+ public static boolean shouldGiveBooksEveryJoin() {
+ return giveOnEveryJoin;
}
- public boolean shouldGiveNewBooksOnJoin() {
- return config.getBoolean("Give-New-Books-On-Join");
+ public static boolean shouldGiveNewBooksOnJoin() {
+ return giveNewBooksOnJoin;
}
- public boolean shouldNotifyPlayers() {
- return config.getBoolean("Display-Messages");
+ public static boolean shouldNotifyPlayers() {
+ return notifyPlayers;
}
- public int getRunnableDelay() {
- return config.getInt("Seconds-Delay") * 20;
+ public static int getRunnableDelay() {
+ return runnableDelay;
}
- public boolean shouldBlockVillagerTrading() {
- return config.getBoolean("Block-Villager-Book-Trading");
+ public static boolean shouldBlockVillagerTrading() {
+ return blockTrading;
}
- public String getLanguage() {
- return config.getString("Language", "EN");
+ public static String getLanguage() {
+ return language;
}
}
diff --git a/src/main/java/com/mstiles92/plugins/bookrules/listeners/PlayerListener.java b/src/main/java/com/mstiles92/plugins/bookrules/listeners/PlayerListener.java
index 86652ab..8630218 100644
--- a/src/main/java/com/mstiles92/plugins/bookrules/listeners/PlayerListener.java
+++ b/src/main/java/com/mstiles92/plugins/bookrules/listeners/PlayerListener.java
@@ -24,6 +24,7 @@
package com.mstiles92.plugins.bookrules.listeners;
import com.mstiles92.plugins.bookrules.BookRules;
+import com.mstiles92.plugins.bookrules.config.Config;
import com.mstiles92.plugins.bookrules.util.GiveBookRunnable;
import com.mstiles92.plugins.bookrules.localization.Localization;
import com.mstiles92.plugins.bookrules.localization.Strings;
@@ -38,8 +39,7 @@
import org.bukkit.inventory.ItemStack;
/**
- * PlayerListener is a class that is used to detect when a player joins the
- * server and handle the event appropriately.
+ * This class is used to handle general events fired off by the player.
*
* @author mstiles92
*/
@@ -54,14 +54,14 @@ public void onPlayerJoin(PlayerJoinEvent e) {
player.sendMessage(String.format(Strings.PLUGIN_TAG + Strings.UPDATE_VERSION_INFO, BookRules.getInstance().getDescription().getVersion(), BookRules.getInstance().getUpdateChecker().getNewVersion()));
}
- if (BookRules.getInstance().getConfigObject().shouldGiveNewBooksOnJoin()) {
- BookRules.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(BookRules.getInstance(), new GiveBookRunnable(player), BookRules.getInstance().getConfigObject().getRunnableDelay());
+ if (Config.shouldGiveNewBooksOnJoin()) {
+ BookRules.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(BookRules.getInstance(), new GiveBookRunnable(player), Config.getRunnableDelay());
}
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
- if (!BookRules.getInstance().getConfigObject().shouldBlockVillagerTrading()) {
+ if (!Config.shouldBlockVillagerTrading()) {
return;
}
diff --git a/src/main/java/com/mstiles92/plugins/bookrules/util/GiveBookRunnable.java b/src/main/java/com/mstiles92/plugins/bookrules/util/GiveBookRunnable.java
index 1c005cd..552c200 100644
--- a/src/main/java/com/mstiles92/plugins/bookrules/util/GiveBookRunnable.java
+++ b/src/main/java/com/mstiles92/plugins/bookrules/util/GiveBookRunnable.java
@@ -23,7 +23,7 @@
package com.mstiles92.plugins.bookrules.util;
-import com.mstiles92.plugins.bookrules.BookRules;
+import com.mstiles92.plugins.bookrules.config.Config;
import com.mstiles92.plugins.bookrules.localization.Localization;
import com.mstiles92.plugins.bookrules.localization.Strings;
import org.bukkit.entity.Player;
@@ -48,14 +48,14 @@ public GiveBookRunnable(Player player) {
@Override
public void run() {
- if (BookRules.getInstance().getConfigObject().shouldGiveBooksEveryJoin()) {
+ if (Config.shouldGiveBooksEveryJoin()) {
int num = BookStorage.getInstance().givePlayerAllBooks(player);
player.sendMessage(String.format(Strings.PLUGIN_TAG + Localization.getString(Strings.PLAYER_JOIN_MESSAGE), String.valueOf(num)));
} else {
int num = BookStorage.getInstance().givePlayerUngivenBooks(player);
Log.verbose(String.format(Localization.getString(Strings.PLAYER_GIVEN_BOOKS), player.getName(), String.valueOf(num)));
- if (num > 0 && BookRules.getInstance().getConfigObject().shouldNotifyPlayers()) {
+ if (num > 0 && Config.shouldNotifyPlayers()) {
player.sendMessage(String.format(Strings.PLUGIN_TAG + Localization.getString(Strings.PLAYER_JOIN_MESSAGE), String.valueOf(num)));
}
}
diff --git a/src/main/java/com/mstiles92/plugins/bookrules/util/Log.java b/src/main/java/com/mstiles92/plugins/bookrules/util/Log.java
index f942591..2078124 100644
--- a/src/main/java/com/mstiles92/plugins/bookrules/util/Log.java
+++ b/src/main/java/com/mstiles92/plugins/bookrules/util/Log.java
@@ -24,11 +24,12 @@
package com.mstiles92.plugins.bookrules.util;
import com.mstiles92.plugins.bookrules.BookRules;
+import com.mstiles92.plugins.bookrules.config.Config;
import org.bukkit.ChatColor;
public class Log {
public static void verbose(String message) {
- if (BookRules.getInstance().getConfigObject().verboseOutputEnabled()) {
+ if (Config.verboseOutputEnabled()) {
BookRules.getInstance().getLogger().info(message);
}
}
diff --git a/src/main/resources/localization/zh.json b/src/main/resources/localization/zh.json
new file mode 100644
index 0000000..de9d85d
--- /dev/null
+++ b/src/main/resources/localization/zh.json
@@ -0,0 +1,69 @@
+{
+ "Console": {
+ "Logging": {
+ "OldConfigConverted": "旧的 %s 格式转换成功。",
+ "PlayerGivenBooks": "玩家 %s 加入游戏时收到了一本 %s 。"
+ },
+ "Error": {
+ "Metrics": "度量标准启动失败。",
+ "FileOpen": "打开 %s 文件发生错误。",
+ "FileSave": "保存 %s 文件发生错误。",
+ "InvalidConfiguration": "文件 %s 配置无效。",
+ "OldFormatConversion": "转换到 %s 格式发生错误。",
+ "PluginDisabled": "BookRules 已被禁用。"
+ }
+ },
+ "Notification": {
+ "Update": {
+ "Available": "发现新版本! 请到 http://dev.bukkit.org/server-mods/bookrules/ 查看更多信息。",
+ "Version": "当前版本: %s, 新版本: %s",
+ "UpToDate": "已是最新版本。"
+ },
+ "JoinMessage": "%s 新书已收到。",
+ "GivenAllBooks": "%s 给了你所有的书。",
+ "GivenBook": "%s 给了你一本书。",
+ "NoTrading": "你不可以和村民进行 BookRules 书籍交易。"
+ },
+ "Commands": {
+ "Success": {
+ "Reload": "配置已重新加载。",
+ "GetAll": "你收到了所有已注册的书籍副本。",
+ "GetOne": "你收到了一本指定的书籍副本。",
+ "GiveAll": "你给了 %s 所有已注册的书籍。",
+ "GiveOne": "你给了 %s 一本指定的书籍副本。",
+ "Add": "你的书已成功添加。",
+ "Delete": "指定的书籍已被删除。",
+ "ChangedAuthor": "作者以成功更改。",
+ "ChangedTitle": "书名已成功更改。",
+ "Unsigned": "这本书已成功分拆。"
+ },
+ "Info": {
+ "Version": "Bookrules by mstiles92, 版本 %s",
+ "CommandsHeader": "所有你可使用的 BookRules 指令:",
+ "Info": "显示当前插件信息。",
+ "Reload": "重新加载配置文件信息。",
+ "Get": "通过书籍id或者书名获取指定的图书, 如果不指定id或书名,将获得所有的已注册书籍。",
+ "Give": "给玩家一本指定id或者书名的书籍, 如果不指定id或书名,将给玩家所有的已注册书籍。",
+ "Add": "添加手里的书到插件中。",
+ "Delete": "从插件中删除指定id或书名的书籍。",
+ "List": "列出插件已储存的所有书籍。",
+ "Author": "更改手中图书的作者。",
+ "Title": "更改手中图书的书名。",
+ "Unsign": "分拆手中的书籍, 使之变回本和笔。",
+ "ListHeader": "所有 BookRules 书籍:",
+ "ListEntry": "%s , 作者 %s"
+ },
+ "Error": {
+ "PlayerOnly": "该指令仅可由玩家使用。",
+ "NoPerms": "你没有权限使用这一指令。",
+ "NoBooks": "没有已注册书籍。",
+ "BookNotFound": "没有找到指定书籍。",
+ "NoPlayerSpecified": "你必须制定一个玩家来给予他书。",
+ "PlayerNotFound": "没有找到指定的玩家。",
+ "MustHoldBook": "你需要拿着一本已编辑好的书来执行这个指令。",
+ "NoBookSpecified": "你必须指定要删除的书。",
+ "NoAuthorSpecified": "编辑书籍作者的时候你必须为其指定一个作者。",
+ "NoTitleSpecified": "编辑书籍书名的时候你必须为其指定一个书名。"
+ }
+ }
+}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 38e8329..fb14fa7 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -2,7 +2,7 @@ author: mstiles92
description: Distribute rule books, getting started guides, etc to players in the form of written books.
name: BookRules
main: com.mstiles92.plugins.bookrules.BookRules
-version: '2.1.1'
+version: '${project.version}'
startup: postworld
permissions:
bookrules.*: