Initial commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package net.crankedpvp.factionlogs.data;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.crankedpvp.factionlogs.enums.LogType;
|
||||
import net.crankedpvp.factionlogs.struct.FactionLog;
|
||||
import net.crankedpvp.storageutils.utils.KeyToSave;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public class FactionLogsData implements KeyToSave {
|
||||
|
||||
private final Map<LogType, List<FactionLog>> logs;
|
||||
private String factionId;
|
||||
|
||||
public FactionLogsData(String factionId) {
|
||||
this.factionId = factionId;
|
||||
this.logs = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addFactionLog(FactionLog factionLog) {
|
||||
if (this.logs.containsKey(factionLog.getLogtype())) {
|
||||
this.logs.get(factionLog.getLogtype()).add(factionLog);
|
||||
} else {
|
||||
List<FactionLog> list = new ArrayList<>();
|
||||
list.add(factionLog);
|
||||
this.logs.put(factionLog.getLogtype(), list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return factionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKey(String s) {
|
||||
this.factionId = s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.crankedpvp.factionlogs.data;
|
||||
|
||||
import net.crankedpvp.factionlogs.FactionLogsPlugin;
|
||||
import net.crankedpvp.storageutils.utils.SaveLoadManager;
|
||||
|
||||
public class FactionLogsManager extends SaveLoadManager<FactionLogsData> {
|
||||
|
||||
public FactionLogsManager() {
|
||||
super(FactionLogsPlugin.getInstance(), FactionLogsPlugin.getInstance().getGson(), "data/", FactionLogsData.class);
|
||||
}
|
||||
|
||||
public FactionLogsData getFactionLogsData(String factionId) {
|
||||
if (!super.containsKey(factionId)) {
|
||||
FactionLogsData factionLogsData = new FactionLogsData(factionId);
|
||||
addToCache(factionLogsData);
|
||||
}
|
||||
return getFromCache(factionId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user