From cc4fd85bc6dc75c26026cc90d4b67297471db111 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Fri, 16 Oct 2015 22:29:00 +0800 Subject: [PATCH] fix OfflineData Read Null... Signed-off-by: j502647092 --- pom.xml | 2 +- src/main/java/cn/citycraft/LuckLottery/LuckLottery.java | 7 ++++--- .../cn/citycraft/LuckLottery/config/OfflineDate.java | 9 +++++++-- .../cn/citycraft/LuckLottery/listen/PlayerListen.java | 6 ++---- .../cn/citycraft/LuckLottery/runnable/LotteryReward.java | 3 +-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index ac0f92e..604092d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft LuckLottery - 1.1 + 1.2 ${project.name} diff --git a/src/main/java/cn/citycraft/LuckLottery/LuckLottery.java b/src/main/java/cn/citycraft/LuckLottery/LuckLottery.java index d4104d8..41032a1 100644 --- a/src/main/java/cn/citycraft/LuckLottery/LuckLottery.java +++ b/src/main/java/cn/citycraft/LuckLottery/LuckLottery.java @@ -5,6 +5,7 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import cn.citycraft.LuckLottery.command.LuckLotteryCommand; +import cn.citycraft.LuckLottery.config.OfflineDate; import cn.citycraft.LuckLottery.listen.PlayerListen; import cn.citycraft.LuckLottery.runnable.LotteryReward; import cn.citycraft.LuckLottery.utils.ChatUtils; @@ -18,7 +19,7 @@ public class LuckLottery extends JavaPlugin { public static boolean isEconomy; public static LuckLottery plugin; protected FileConfig config; - protected FileConfig offlinedata; + protected OfflineDate offlinedata; protected FileConfig playerdata; @Override @@ -26,7 +27,7 @@ public class LuckLottery extends JavaPlugin { return config; } - public FileConfig getOfflinedata() { + public OfflineDate getOfflineData() { return offlinedata; } @@ -69,7 +70,7 @@ public class LuckLottery extends JavaPlugin { public void onLoad() { plugin = this; config = new FileConfig(this); - offlinedata = new FileConfig(this, "offlinedata"); + offlinedata = new OfflineDate(this); playerdata = new FileConfig(this, "playerdate.yml"); LotteryUtils.init(this); LotteryUtils.reloadPlayerLottery(); diff --git a/src/main/java/cn/citycraft/LuckLottery/config/OfflineDate.java b/src/main/java/cn/citycraft/LuckLottery/config/OfflineDate.java index 3483482..22bbaa9 100644 --- a/src/main/java/cn/citycraft/LuckLottery/config/OfflineDate.java +++ b/src/main/java/cn/citycraft/LuckLottery/config/OfflineDate.java @@ -14,14 +14,19 @@ public class OfflineDate { instance = new FileConfig(p, CONFIG_NAME); } - public static void addMessage(final String p, final String message) { + public void addMessage(final String p, final String message) { final List messages = instance.getStringList(p); messages.add(message); instance.set(p, messages); instance.save(); } - public static List getMessage(final String p) { + public void clearMessage(final String p) { + instance.set(p, null); + instance.save(); + } + + public List getMessage(final String p) { return instance.getStringList(p); } } diff --git a/src/main/java/cn/citycraft/LuckLottery/listen/PlayerListen.java b/src/main/java/cn/citycraft/LuckLottery/listen/PlayerListen.java index a9967d6..ee08229 100644 --- a/src/main/java/cn/citycraft/LuckLottery/listen/PlayerListen.java +++ b/src/main/java/cn/citycraft/LuckLottery/listen/PlayerListen.java @@ -15,7 +15,6 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import cn.citycraft.LuckLottery.LuckLottery; -import cn.citycraft.LuckLottery.config.OfflineDate; import cn.citycraft.LuckLottery.runnable.LaterShow; import cn.citycraft.LuckLottery.utils.ChatUtils; import cn.citycraft.LuckLottery.utils.InvUtils; @@ -79,11 +78,10 @@ public class PlayerListen implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onPlayerInteract(final PlayerJoinEvent e) { final Player p = e.getPlayer(); - final List messages = OfflineDate.getMessage(p.getName()); + final List messages = plugin.getOfflineData().getMessage(p.getName()); if (messages != null && !messages.isEmpty()) { Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(LuckLottery.plugin, new LaterShow(p, messages), 5); - plugin.getOfflinedata().set(p.getName(), null); - plugin.getOfflinedata().save(); + plugin.getOfflineData().clearMessage(p.getName()); } } diff --git a/src/main/java/cn/citycraft/LuckLottery/runnable/LotteryReward.java b/src/main/java/cn/citycraft/LuckLottery/runnable/LotteryReward.java index bec05e5..4cebc09 100644 --- a/src/main/java/cn/citycraft/LuckLottery/runnable/LotteryReward.java +++ b/src/main/java/cn/citycraft/LuckLottery/runnable/LotteryReward.java @@ -8,7 +8,6 @@ import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import cn.citycraft.LuckLottery.LuckLottery; -import cn.citycraft.LuckLottery.config.OfflineDate; import cn.citycraft.LuckLottery.utils.ChatUtils; import cn.citycraft.LuckLottery.utils.LotteryUtils; @@ -45,7 +44,7 @@ public class LotteryReward implements Runnable { if (p.isOnline()) { // ChatUtils.sendMessage((Player) p, message); } else { - OfflineDate.addMessage(p.getName(), message); + plugin.getOfflineData().addMessage(p.getName(), message); } LuckLottery.economy.depositPlayer(p, winprices); }