103 lines
3.0 KiB
Java
103 lines
3.0 KiB
Java
package ru.prisonlife.api.template;
|
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
import org.bukkit.Bukkit;
|
|
import ru.prisonlife.api.PrisonAPI;
|
|
import ru.prisonlife.api.PrisonAPI.Factions;
|
|
import ru.prisonlife.api.store.DailyRespectTaskEntity;
|
|
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
public class Faction extends AbstractApiData {
|
|
|
|
private WeakReference<DailyRespectTaskEntity> refDailyRespectTaskEntity;
|
|
|
|
private static final String[][] post = {
|
|
{"Vakasu", "Tomadati", "So Honbute", "Vakagasira", "Kambu", "Kumite"},
|
|
{"Novaro", "Amigo", "Latino", "Veterano", "Elite", "Padre"},
|
|
{"Baby", "Cracker", "Little Nigga", "Big Nigga", "Star", "Daddy"}};
|
|
|
|
public Faction(Prisoner me) {
|
|
super(me);
|
|
}
|
|
|
|
private DailyRespectTaskEntity getDailyRespectTaskEntity() {
|
|
DailyRespectTaskEntity entity;
|
|
if (refDailyRespectTaskEntity != null && (entity = refDailyRespectTaskEntity.get()) != null) {
|
|
return entity;
|
|
} else {
|
|
final SqlSession session = PrisonAPI.getSqlStore().openSession();
|
|
entity = session.selectOne("DailyRespectTask.selectOne", me.getPlayer().getUniqueId().toString());
|
|
session.close();
|
|
|
|
if (entity == null) {
|
|
throw new RuntimeException("no data in db by '" + me.getPlayer().getUniqueId().toString() + "'");
|
|
}
|
|
|
|
refDailyRespectTaskEntity = new WeakReference<>(entity);
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
public String getType() {
|
|
return Factions.valueOf(getPlayerStatsEntity().getFaction()).name();
|
|
}
|
|
|
|
public int getId() {
|
|
return getPlayerStatsEntity().getFaction();
|
|
}
|
|
|
|
public int getRangId() {
|
|
return getPlayerStatsEntity().getRang();
|
|
}
|
|
|
|
public String getRangType() {
|
|
return post[getId() - 1][getRangId() - 1];
|
|
}
|
|
|
|
public void addRang(int value) {
|
|
setRang(getRangId() + value);
|
|
}
|
|
|
|
public void setRang(int value) {
|
|
getPlayerStatsEntity().setRang(value);
|
|
}
|
|
|
|
public void setFaction(int id) {
|
|
getPlayerStatsEntity().setFaction(id);
|
|
}
|
|
|
|
public int getRespect() {
|
|
return getPlayerStatsEntity().getRespect();
|
|
}
|
|
|
|
public void addRespect(int value) {
|
|
setRespect(getRespect() + value);
|
|
}
|
|
|
|
public void setRespect(int value) {
|
|
getPlayerStatsEntity().setRespect(value);
|
|
}
|
|
|
|
public int getRespectDailyCooldown() {
|
|
return getDailyRespectTaskEntity().getCooldownRespect();
|
|
}
|
|
|
|
public void addRespectDailyCooldown(int value) {
|
|
setRespectDailyCooldown(getRespectDailyCooldown() + value);
|
|
}
|
|
|
|
public void setRespectDailyCooldown(int value) {
|
|
getDailyRespectTaskEntity().setCooldownRespect(value);
|
|
}
|
|
|
|
public List<Prisoner> getOnlineList() {
|
|
return Bukkit.getOnlinePlayers().stream()
|
|
.map(Prisoner::new)
|
|
.filter(prisoner -> prisoner.getFaction().getType().equals(me.getFaction().getType()))
|
|
.collect(Collectors.toList());
|
|
}
|
|
}
|