1
0
mirror of https://e.coding.net/circlecloud/LuckLottery.git synced 2024-11-10 08:58:49 +00:00

fix OfflineData Read Null...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-10-16 22:29:00 +08:00
parent 5d97130868
commit cc4fd85bc6
5 changed files with 15 additions and 12 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.citycraft</groupId>
<artifactId>LuckLottery</artifactId>
<version>1.1</version>
<version>1.2</version>
<build>
<finalName>${project.name}</finalName>
<resources>

View File

@ -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();

View File

@ -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<String> messages = instance.getStringList(p);
messages.add(message);
instance.set(p, messages);
instance.save();
}
public static List<String> getMessage(final String p) {
public void clearMessage(final String p) {
instance.set(p, null);
instance.save();
}
public List<String> getMessage(final String p) {
return instance.getStringList(p);
}
}

View File

@ -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<String> messages = OfflineDate.getMessage(p.getName());
final List<String> 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());
}
}

View File

@ -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);
}