use of com.solinia.solinia.Interfaces.ISoliniaClass in project solinia3-core by mixxit.
the class CommandEditClass 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 classid = Integer.parseInt(args[0]);
if (args.length == 1) {
try {
ISoliniaClass solclass = StateManager.getInstance().getConfigurationManager().getClassObj(classid);
if (solclass != null) {
solclass.sendClassSettingsToSender(sender);
} else {
sender.sendMessage("CLASS ID doesnt exist");
}
return true;
} catch (CoreStateInitException e) {
sender.sendMessage(e.getMessage());
}
}
if (args.length < 3) {
sender.sendMessage("Insufficient arguments: classid setting value");
return false;
}
String setting = args[1];
String value = args[2];
// a string
if (args.length > 3 && (setting.toLowerCase().contains("text") || setting.toLowerCase().contains("description") || setting.toLowerCase().contains("title"))) {
value = "";
int current = 0;
for (String entry : args) {
current++;
if (current <= 2)
continue;
value = value + entry + " ";
}
value = value.trim();
}
if (classid < 1) {
sender.sendMessage("Invalid class id");
return false;
}
try {
if (StateManager.getInstance().getConfigurationManager().getClassObj(classid) == null) {
sender.sendMessage("Cannot locate class id: " + classid);
return false;
}
StateManager.getInstance().getConfigurationManager().editClass(classid, setting, value);
sender.sendMessage("Updating setting on class");
} catch (InvalidClassSettingException ne) {
sender.sendMessage("Invalid class setting: " + ne.getMessage());
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
sender.sendMessage(e.getMessage());
}
return true;
}
use of com.solinia.solinia.Interfaces.ISoliniaClass in project solinia3-core by mixxit.
the class SoliniaClassFactory method CreateClass.
public static ISoliniaClass CreateClass(String classname, boolean adminonly) throws CoreStateInitException, SoliniaClassCreationException {
if (StateManager.getInstance().getConfigurationManager().getClassObj(classname.toUpperCase()) != null)
throw new SoliniaClassCreationException("Class already exists");
SoliniaClass classObj = new SoliniaClass();
classObj.setId(StateManager.getInstance().getConfigurationManager().getNextClassId());
classObj.setName(classname.toUpperCase());
classObj.setAdmin(adminonly);
StateManager.getInstance().getConfigurationManager().addClass(classObj);
return classObj;
}
use of com.solinia.solinia.Interfaces.ISoliniaClass in project solinia3-core by mixxit.
the class CommandSetClass method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player))
return false;
try {
String prolist = "";
String prolistunformatted = "";
List<ISoliniaClass> pros = new ArrayList<ISoliniaClass>();
List<ISoliniaClass> rawpros = StateManager.getInstance().getConfigurationManager().getClasses();
if ((sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
String tmplist = "";
for (ISoliniaClass pro : rawpros) {
tmplist = prolist + " " + ChatColor.LIGHT_PURPLE + pro.getName().toUpperCase() + ChatColor.RESET + "(A:" + pro.isAdmin() + ")";
}
sender.sendMessage(tmplist);
return true;
}
Player player = (Player) sender;
try {
ISoliniaPlayer soliniaplayer = SoliniaPlayerAdapter.Adapt(player);
if (soliniaplayer.hasChosenRace() == false) {
SendProfessionFull(sender, rawpros);
sender.sendMessage("You cannot pick a profession until you set your race with /setrace");
return true;
}
if (soliniaplayer.hasChosenClass() == true) {
SendProfessionFull(sender, rawpros);
sender.sendMessage("You cannot pick a profession as you have already chosen one");
return true;
}
for (ISoliniaClass pro : rawpros) {
if (!pro.isAdmin() && StateManager.getInstance().getConfigurationManager().isValidRaceClass(soliniaplayer.getRaceId(), pro.getId())) {
prolist = prolist + " " + ChatColor.LIGHT_PURPLE + pro.getName().toUpperCase() + ChatColor.RESET;
prolistunformatted = prolistunformatted + " " + pro.getName().toUpperCase();
pros.add(pro);
}
}
if (args.length == 0) {
SendProfessionList(sender, rawpros, prolistunformatted);
sender.sendMessage("Insufficient arguments Valid Professions are: [" + prolist + "]");
if (soliniaplayer != null) {
ISoliniaClass profession = StateManager.getInstance().getConfigurationManager().getClassObj(soliniaplayer.getClassId());
if (profession != null)
sender.sendMessage("Your current profession is: " + profession.getName());
else
sender.sendMessage("Your current profession is: UNKNOWN");
}
return false;
}
String profession = args[0].toUpperCase();
boolean found = false;
ISoliniaClass solprofession = null;
for (ISoliniaClass allowedprofession : pros) {
if (allowedprofession.getName().equals(profession)) {
solprofession = allowedprofession;
found = true;
}
}
if (found == false) {
SendProfessionList(sender, rawpros, prolistunformatted);
return false;
}
if (!StateManager.getInstance().getConfigurationManager().isValidRaceClass(soliniaplayer.getRaceId(), solprofession.getId())) {
SendProfessionList(sender, rawpros, prolistunformatted);
sender.sendMessage("That is not a valid Race / Profession");
return true;
}
soliniaplayer.setClassId(solprofession.getId());
soliniaplayer.setChosenClass(true);
sender.sendMessage("* Profession set to " + profession);
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
solplayer.updateMaxHp();
return true;
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (CoreStateInitException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
sender.sendMessage(e1.getMessage());
return false;
}
return true;
}
use of com.solinia.solinia.Interfaces.ISoliniaClass in project solinia3-core by mixxit.
the class JsonClassRepository method reload.
@Override
public void reload() {
List<ISoliniaClass> file = new ArrayList<ISoliniaClass>();
try {
Gson gson = new Gson();
BufferedReader br = new BufferedReader(new FileReader(filePath));
file = gson.fromJson(br, new TypeToken<List<SoliniaClass>>() {
}.getType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
classes.clear();
for (ISoliniaClass i : file) {
classes.put(i.getId(), i);
}
System.out.println("Reloaded " + classes.size() + " classes");
}
use of com.solinia.solinia.Interfaces.ISoliniaClass in project solinia3-core by mixxit.
the class ConfigurationManager method getSpellsByClassId.
@Override
public List<ISoliniaSpell> getSpellsByClassId(int classId) {
List<ISoliniaSpell> returnSpells = new ArrayList<ISoliniaSpell>();
ISoliniaClass classObj;
try {
classObj = StateManager.getInstance().getConfigurationManager().getClassObj(classId);
} catch (CoreStateInitException e) {
return returnSpells;
}
for (ISoliniaSpell spell : getSpells()) {
boolean addSpell = false;
for (SoliniaSpellClass spellclass : spell.getAllowedClasses()) {
if (spellclass.getClassname().toUpperCase().equals(classObj.getName().toUpperCase())) {
addSpell = true;
break;
}
}
if (addSpell == true)
returnSpells.add(spell);
}
return returnSpells;
}
Aggregations