use of com.solinia.solinia.Interfaces.ISoliniaAlignment in project solinia3-core by mixxit.
the class JsonAlignmentRepository method reload.
@Override
public void reload() {
List<ISoliniaAlignment> file = new ArrayList<ISoliniaAlignment>();
try {
Gson gson = new Gson();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaAlignment>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
alignments.clear();
for (ISoliniaAlignment i : file) {
alignments.put(i.getId(), i);
}
System.out.println("Reloaded " + alignments.size() + " Alignments");
}
use of com.solinia.solinia.Interfaces.ISoliniaAlignment in project solinia3-core by mixxit.
the class ConfigurationManager method addAlignment.
@Override
public void addAlignment(String alignmentname) throws Exception {
for (ISoliniaAlignment alignment : getAlignments()) {
if (alignment.getName().equals(alignmentname.toUpperCase()))
throw new Exception("Alignment already exists");
}
SoliniaAlignment alignment = new SoliniaAlignment();
alignment.setId(getNextAlignmentId());
alignment.setName(alignmentname);
alignmentsRepository.add(alignment);
}
use of com.solinia.solinia.Interfaces.ISoliniaAlignment in project solinia3-core by mixxit.
the class ConfigurationManager method updateKingsAndEmperors.
@Override
public void updateKingsAndEmperors() {
List<UUID> goodkingCache = new ArrayList<UUID>();
List<UUID> neutralkingCache = new ArrayList<UUID>();
List<UUID> evilkingCache = new ArrayList<UUID>();
for (ISoliniaRace race : getRaces()) {
HashMap<UUID, Integer> kingCount = new HashMap<UUID, Integer>();
try {
for (ISoliniaPlayer player : StateManager.getInstance().getPlayerManager().getCharacters()) {
if (player.getRaceId() != race.getId())
continue;
if (!player.isMain())
continue;
if (player.getFealty() == null)
continue;
ISoliniaPlayer fealtyPlayer = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getFealty());
if (fealtyPlayer.getRaceId() != player.getRaceId())
continue;
if (!fealtyPlayer.isMain())
continue;
if (fealtyPlayer.isAlignmentEmperor())
continue;
if (!kingCount.containsKey(player.getFealty())) {
kingCount.put(player.getFealty(), 1);
} else {
kingCount.put(player.getFealty(), kingCount.get(player.getFealty()) + 1);
}
}
Entry<UUID, Integer> maxEntry = null;
for (Entry<UUID, Integer> entry : kingCount.entrySet()) {
if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
maxEntry = entry;
}
}
if (maxEntry != null) {
if (race.getKing() == null || !race.getKing().equals(maxEntry.getKey()))
StateManager.getInstance().getConfigurationManager().getRace(race.getId()).setKing(maxEntry.getKey());
switch(race.getAlignment()) {
case "GOOD":
goodkingCache.add(maxEntry.getKey());
break;
case "NEUTRAL":
neutralkingCache.add(maxEntry.getKey());
break;
case "EVIL":
evilkingCache.add(maxEntry.getKey());
break;
default:
break;
}
}
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
// Good
HashMap<UUID, Integer> goodkingCount = new HashMap<UUID, Integer>();
if (StateManager.getInstance().getConfigurationManager().getAlignment("GOOD") != null)
for (UUID king : goodkingCache) {
ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
if (player == null)
continue;
if (!player.isMain())
continue;
if (player.getRace() == null)
continue;
if (!player.isRacialKing())
continue;
if (player.getVoteEmperor() == null)
continue;
if (player.getVoteEmperor().equals(player.getUUID()))
continue;
ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
if (fealty == null)
continue;
if (fealty.getRace() == null)
continue;
if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
continue;
if (fealty.isRacialKing())
continue;
if (!goodkingCount.containsKey(player.getVoteEmperor())) {
goodkingCount.put(player.getVoteEmperor(), 1);
} else {
goodkingCount.put(player.getVoteEmperor(), goodkingCount.get(player.getVoteEmperor()) + 1);
}
}
Entry<UUID, Integer> maxEntry = null;
for (Entry<UUID, Integer> entry : goodkingCount.entrySet()) {
if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
maxEntry = entry;
}
}
if (maxEntry != null) {
ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("GOOD");
if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
StateManager.getInstance().getConfigurationManager().getAlignment("GOOD").setEmperor(maxEntry.getKey());
}
// Neutral
HashMap<UUID, Integer> neutralkingCount = new HashMap<UUID, Integer>();
if (StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL") != null)
for (UUID king : neutralkingCache) {
ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
if (player == null)
continue;
if (player.getRace() == null)
continue;
if (!player.isRacialKing())
continue;
if (player.getVoteEmperor() == null)
continue;
if (player.getVoteEmperor().equals(player.getUUID()))
continue;
ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
if (fealty == null)
continue;
if (fealty.getRace() == null)
continue;
if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
continue;
if (fealty.isRacialKing())
continue;
if (!neutralkingCount.containsKey(player.getVoteEmperor())) {
neutralkingCount.put(player.getVoteEmperor(), 1);
} else {
neutralkingCount.put(player.getVoteEmperor(), neutralkingCount.get(player.getVoteEmperor()) + 1);
}
}
maxEntry = null;
for (Entry<UUID, Integer> entry : neutralkingCount.entrySet()) {
if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
maxEntry = entry;
}
}
if (maxEntry != null) {
ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL");
if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL").setEmperor(maxEntry.getKey());
}
// Evil
HashMap<UUID, Integer> evilkingCount = new HashMap<UUID, Integer>();
if (StateManager.getInstance().getConfigurationManager().getAlignment("EVIL") != null)
for (UUID king : evilkingCache) {
ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
if (player == null)
continue;
if (player.getRace() == null)
continue;
if (!player.isRacialKing())
continue;
if (player.getVoteEmperor() == null)
continue;
if (player.getVoteEmperor().equals(player.getUUID()))
continue;
ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
if (fealty == null)
continue;
if (fealty.getRace() == null)
continue;
if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
continue;
if (fealty.isRacialKing())
continue;
if (!evilkingCount.containsKey(player.getVoteEmperor())) {
evilkingCount.put(player.getVoteEmperor(), 1);
} else {
evilkingCount.put(player.getVoteEmperor(), evilkingCount.get(player.getVoteEmperor()) + 1);
}
}
maxEntry = null;
for (Entry<UUID, Integer> entry : evilkingCount.entrySet()) {
if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
maxEntry = entry;
}
}
if (maxEntry != null) {
ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("EVIL");
if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
StateManager.getInstance().getConfigurationManager().getAlignment("EVIL").setEmperor(maxEntry.getKey());
}
} catch (CoreStateInitException e) {
// try next loop
}
}
Aggregations