use of com.solinia.solinia.Interfaces.ISoliniaRace in project solinia3-core by mixxit.
the class SoliniaRaceFactory method CreateRace.
public static ISoliniaRace CreateRace(String racename, int strength, int stamina, int agility, int dexterity, int wisdom, int intelligence, int charisma, boolean adminonly) throws CoreStateInitException, SoliniaRaceCreationException {
if (StateManager.getInstance().getConfigurationManager().getRace(racename.toUpperCase()) != null)
throw new SoliniaRaceCreationException("Race already exists");
SoliniaRace race = new SoliniaRace();
race.setId(StateManager.getInstance().getConfigurationManager().getNextRaceId());
race.setName(racename.toUpperCase());
race.setStrength(strength);
race.setStamina(stamina);
race.setAgility(agility);
race.setDexterity(dexterity);
race.setWisdom(wisdom);
race.setIntelligence(intelligence);
race.setCharisma(charisma);
race.setAdmin(adminonly);
StateManager.getInstance().getConfigurationManager().addRace(race);
return race;
}
use of com.solinia.solinia.Interfaces.ISoliniaRace in project solinia3-core by mixxit.
the class Utils method sendRaceInfo.
public static void sendRaceInfo(CommandSender sender) throws CoreStateInitException {
List<ISoliniaClass> classes = StateManager.getInstance().getConfigurationManager().getClasses();
for (ISoliniaRace race : StateManager.getInstance().getConfigurationManager().getRaces()) {
if (race.isAdmin())
continue;
String classBuilder = "";
for (ISoliniaClass solclass : classes) {
if (solclass.getValidRaces().contains(race.getId()))
classBuilder += solclass.getName() + " ";
}
TextComponent tc = new TextComponent();
tc.setText(ChatColor.RED + "~ RACE: " + ChatColor.GOLD + race.getName().toUpperCase() + ChatColor.GRAY + " [" + race.getId() + "] - " + ChatColor.RESET);
TextComponent tc2 = new TextComponent();
tc2.setText("Hover for more details");
String details = ChatColor.GOLD + race.getName() + ChatColor.RESET + "\nRecommended Alignment: " + ChatColor.GOLD + race.getAlignment() + ChatColor.RESET + "\n" + race.getDescription() + "\nSTR: " + ChatColor.GOLD + race.getStrength() + ChatColor.RESET + " STA: " + ChatColor.GOLD + race.getStamina() + ChatColor.RESET + " AGI: " + ChatColor.GOLD + race.getAgility() + ChatColor.RESET + " DEX: " + ChatColor.GOLD + race.getDexterity() + ChatColor.RESET + " INT: " + ChatColor.GOLD + race.getIntelligence() + ChatColor.RESET + " WIS: " + ChatColor.GOLD + race.getWisdom() + ChatColor.RESET + " CHA: " + ChatColor.GOLD + race.getCharisma() + ChatColor.GOLD + " \nClasses: " + ChatColor.RESET + classBuilder;
tc2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
tc.addExtra(tc2);
sender.spigot().sendMessage(tc);
}
}
use of com.solinia.solinia.Interfaces.ISoliniaRace in project solinia3-core by mixxit.
the class CommandSetRace method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender))
return false;
sender.sendMessage("See /raceinfo for more information");
String racelist = "";
List<ISoliniaRace> races = new ArrayList<ISoliniaRace>();
try {
for (ISoliniaRace race : StateManager.getInstance().getConfigurationManager().getRaces()) {
if (!race.isAdmin()) {
racelist = racelist + " " + ChatColor.LIGHT_PURPLE + race.getName().toUpperCase() + ChatColor.RESET;
races.add(race);
}
}
} catch (CoreStateInitException e1) {
sender.sendMessage("Race command failed. " + e1.getMessage());
return false;
}
if ((sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
try {
Utils.sendRaceInfo(sender);
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
Player player = (Player) sender;
ISoliniaPlayer soliniaplayer;
try {
soliniaplayer = SoliniaPlayerAdapter.Adapt(player);
} catch (CoreStateInitException e2) {
player.sendMessage("Race command failed. " + e2.getMessage());
return false;
}
if (soliniaplayer.hasChosenRace() == true) {
player.sendMessage("You cannot choose a race as you have already selected one");
return true;
}
if (args.length == 0) {
try {
Utils.sendRaceInfo(sender);
} catch (CoreStateInitException e1) {
}
player.sendMessage("Insufficient arguments. Please provide correct race name");
if (soliniaplayer != null) {
ISoliniaRace solrace;
try {
solrace = StateManager.getInstance().getConfigurationManager().getRace(soliniaplayer.getRaceId());
} catch (CoreStateInitException e) {
player.sendMessage("Race command failed. " + e.getMessage());
return false;
}
if (solrace == null)
player.sendMessage("Your current race is: UNKNOWN");
else
player.sendMessage("Your current race is: " + solrace.getName());
}
return false;
}
String race = args[0].toUpperCase();
boolean found = false;
for (ISoliniaRace allowedrace : races) {
if (allowedrace.getName().equals(race)) {
found = true;
}
}
if (found == false) {
try {
Utils.sendRaceInfo(sender);
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
player.sendMessage("Insufficient arguments. Please provide correct race name");
return false;
}
try {
if (StateManager.getInstance().getConfigurationManager().getRace(race) != null) {
soliniaplayer.setRaceId(StateManager.getInstance().getConfigurationManager().getRace(race).getId());
soliniaplayer.setChosenRace(true);
player.sendMessage("* Race set to " + race);
return true;
} else {
Utils.sendRaceInfo(sender);
player.sendMessage("Insufficient arguments. Please provide correct race name");
return false;
}
} catch (CoreStateInitException e) {
player.sendMessage("Race command failed. " + e.getMessage());
return false;
}
}
use of com.solinia.solinia.Interfaces.ISoliniaRace in project solinia3-core by mixxit.
the class CommandEditRace method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player) && !(sender instanceof CommandSender))
return false;
if (sender instanceof Player) {
Player player = (Player) sender;
if (!player.isOp()) {
player.sendMessage("This is an operator only command");
return false;
}
}
if (args.length == 0) {
return false;
}
int raceid = Integer.parseInt(args[0]);
if (args.length == 1) {
try {
ISoliniaRace solrace = StateManager.getInstance().getConfigurationManager().getRace(raceid);
if (solrace != null) {
solrace.sendRaceSettingsToSender(sender);
} else {
sender.sendMessage("RACE ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 3) {
sender.sendMessage("Insufficient arguments: raceid setting value");
return false;
}
String setting = args[1];
String value = args[2];
// a string
if (args.length > 3 && setting.toLowerCase().contains("description")) {
value = "";
int current = 0;
for (String entry : args) {
current++;
if (current <= 2)
continue;
value = value + entry + " ";
}
value = value.trim();
}
if (raceid < 1) {
sender.sendMessage("Invalid race id");
return false;
}
try {
if (StateManager.getInstance().getConfigurationManager().getRace(raceid) == null) {
sender.sendMessage("Cannot locate race id: " + raceid);
return false;
}
StateManager.getInstance().getConfigurationManager().editRace(raceid, setting, value);
sender.sendMessage("Updating setting on race");
} catch (InvalidRaceSettingException ne) {
sender.sendMessage("Invalid race setting: " + ne.getMessage());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
}
return true;
}
use of com.solinia.solinia.Interfaces.ISoliniaRace 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