package com.yaohun.trade.manage; import com.yaohun.trade.data.TradeLogData; import me.Demon.DemonPlugin.DemonAPI; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class LogsManager { private File file; private FileConfiguration config; private List logDataList = new ArrayList<>(); public LogsManager() { String pathData = "plugins/AuLogs/TradeLog"; File path = new File(pathData); if(!path.exists()){ path.mkdirs(); } this.file = new File(pathData, DemonAPI.getTime("yyyy-MM")+".yml"); if(!file.exists()){ try { file.createNewFile(); } catch (IOException e) { throw new RuntimeException(e); } } this.config = YamlConfiguration.loadConfiguration(this.file); } public void addLogData(TradeLogData logData){ this.logDataList.add(logData); } public void saveAllLog(){ if(logDataList.isEmpty()){ return; } for (TradeLogData logData : logDataList){ String tradeId = logData.getTradeID(); this.config.set(tradeId+".时间",DemonAPI.LongToStringData(logData.getTradeTime(),"yyyy-MM-dd HH:mm:ss")); this.config.set(tradeId+".发起者",logData.getPlayerName()); this.config.set(tradeId+".发起者物品",logData.getPlayerList()); this.config.set(tradeId+".接收者",logData.getTargetName()); this.config.set(tradeId+".接收者物品",logData.getTargetList()); } try { this.config.save(this.file); } catch (IOException e) { throw new RuntimeException(e); } Bukkit.getConsoleSender().sendMessage("§6[交易系统] §7成功保存交易日志: §a"+logDataList.size()+"条"); logDataList.clear(); } }