use of de.Keyle.MyPet.api.skill.skilltree.SkillTree in project MyPet by xXKeyleXx.
the class SqLiteRepository method resultSetToMyPet.
// Pets ------------------------------------------------------------------------------------------------------------
private List<StoredMyPet> resultSetToMyPet(MyPetPlayer owner, ResultSet resultSet, boolean next) {
List<StoredMyPet> pets = new ArrayList<>();
try {
while (!next || resultSet.next()) {
next = true;
InactiveMyPet pet = new InactiveMyPet(owner);
pet.setUUID(UUID.fromString(resultSet.getString("uuid")));
pet.setWorldGroup(resultSet.getString("world_group"));
pet.setExp(resultSet.getDouble("exp"));
pet.setHealth(resultSet.getDouble("health"));
pet.setRespawnTime(resultSet.getInt("respawn_time"));
pet.setPetName(new String(resultSet.getBytes("name"), StandardCharsets.UTF_8));
pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
pet.setLastUsed(resultSet.getLong("last_used"));
pet.setSaturation(resultSet.getDouble("hunger"));
pet.wantsToRespawn = resultSet.getBoolean("wants_to_spawn");
String skillTreeName = resultSet.getString("skilltree");
if (skillTreeName != null) {
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
if (skilltree != null) {
pet.setSkilltree(skilltree);
}
}
pet.setSkills(TagStream.readTag(resultSet.getBytes("skills"), true));
pet.setInfo(TagStream.readTag(resultSet.getBytes("info"), true));
List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
for (RepositoryMyPetConverterService converter : converters) {
converter.convert(pet);
}
pets.add(pet);
}
} catch (SQLException | IOException e) {
e.printStackTrace();
}
return pets;
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTree in project MyPet by xXKeyleXx.
the class CommandOptionCreate method updateData.
public static void updateData(InactiveMyPet inactiveMyPet, String[] args) {
for (String arg : args) {
if (arg.startsWith("skilltree:")) {
String skilltreeName = arg.replace("skilltree:", "");
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skilltreeName);
if (skilltree != null) {
inactiveMyPet.setSkilltree(skilltree, MyPetSelectSkilltreeEvent.Source.AdminCreation);
}
} else if (arg.startsWith("name:")) {
String name = arg.replace("name:", "");
int index = ArrayUtils.indexOf(args, arg);
if (args.length > index + 1) {
name += " " + String.join(" ", Arrays.copyOfRange(args, index + 1, args.length));
}
inactiveMyPet.setPetName(name);
break;
}
}
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTree in project MyPet by xXKeyleXx.
the class CommandOptionReload method reloadSkilltrees.
protected void reloadSkilltrees(CommandSender sender) {
MyPetApi.getSkilltreeManager().clearSkilltrees();
SkillTreeLoaderJSON.loadSkilltrees(new File(MyPetApi.getPlugin().getDataFolder(), "skilltrees"));
for (MyPet myPet : MyPetApi.getMyPetManager().getAllActiveMyPets()) {
Skilltree skilltree = myPet.getSkilltree();
if (skilltree != null) {
String skilltreeName = skilltree.getName();
if (MyPetApi.getSkilltreeManager().hasSkilltree(skilltreeName)) {
skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skilltreeName);
if (!skilltree.getMobTypes().contains(myPet.getPetType())) {
skilltree = null;
}
} else {
skilltree = null;
}
}
myPet.setSkilltree(skilltree);
}
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] skilltrees reloaded!");
MyPetApi.getLogger().info("Skilltrees reloaded!");
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTree in project MyPet by xXKeyleXx.
the class CommandOptionSkilltree method onCommandOption.
@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
if (args.length == 0) {
sender.sendMessage(Translation.getString("Message.Command.Help.MissingParameter", sender));
sender.sendMessage(" -> " + ChatColor.DARK_AQUA + "/petadmin skilltree " + ChatColor.RED + "<a player name> " + ChatColor.RED + "<new skilltree>");
return false;
}
if (args.length == 1) {
sender.sendMessage(Translation.getString("Message.Command.Help.MissingParameter", sender));
sender.sendMessage(" -> " + ChatColor.DARK_AQUA + "/petadmin skilltree " + args[0] + " " + ChatColor.RED + "<new skilltree>");
return false;
}
String lang = MyPetApi.getPlatformHelper().getCommandSenderLanguage(sender);
Player petOwner = Bukkit.getServer().getPlayer(args[0]);
if (petOwner == null || !petOwner.isOnline()) {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Translation.getString("Message.No.PlayerOnline", lang));
return true;
} else if (!MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Util.formatText(Translation.getString("Message.No.UserHavePet", lang), petOwner.getName()));
return true;
}
MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
if (MyPetApi.getSkilltreeManager().hasSkilltree(args[1])) {
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(args[1]);
if (skilltree.getMobTypes().contains(myPet.getPetType()) && myPet.setSkilltree(skilltree, MyPetSelectSkilltreeEvent.Source.AdminCommand)) {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Util.formatText(Translation.getString("Message.Skilltree.SwitchedToFor", lang), petOwner.getName(), Colorizer.setColors(skilltree.getDisplayName())));
} else {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Translation.getString("Message.Skilltree.NotSwitched", lang));
}
} else {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Util.formatText(Translation.getString("Message.Command.Skilltree.CantFindSkilltree", lang), args[1]));
}
return true;
}
use of de.Keyle.MyPet.api.skill.skilltree.SkillTree in project MyPet by xXKeyleXx.
the class InactiveMyPet method load.
@Override
public void load(TagCompound myPetNBT) {
if (myPetNBT.getCompoundData().containsKey("UUID")) {
uuid = UUID.fromString(myPetNBT.getAs("UUID", TagString.class).getStringData());
}
exp = myPetNBT.getAs("Exp", TagDouble.class).getDoubleData();
if (myPetNBT.containsKeyAs("Health", TagInt.class)) {
health = myPetNBT.getAs("Health", TagInt.class).getIntData();
} else if (myPetNBT.containsKeyAs("Health", TagDouble.class)) {
health = myPetNBT.getAs("Health", TagDouble.class).getDoubleData();
}
respawnTime = myPetNBT.getAs("Respawntime", TagInt.class).getIntData();
petName = myPetNBT.getAs("Name", TagString.class).getStringData();
if (myPetNBT.getCompoundData().containsKey("Type")) {
petType = MyPetType.valueOf(myPetNBT.getAs("Type", TagString.class).getStringData());
}
if (myPetNBT.getCompoundData().containsKey("LastUsed")) {
lastUsed = myPetNBT.getAs("LastUsed", TagLong.class).getLongData();
}
if (myPetNBT.getCompoundData().containsKey("Skilltree")) {
String skillTreeName = myPetNBT.getAs("Skilltree", TagString.class).getStringData();
if (skillTreeName != null) {
Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
if (skilltree.getMobTypes().contains(getPetType())) {
this.skilltree = skilltree;
}
}
}
if (myPetNBT.containsKeyAs("Hunger", TagInt.class)) {
saturation = myPetNBT.getAs("Hunger", TagInt.class).getIntData();
} else if (myPetNBT.containsKeyAs("Hunger", TagDouble.class)) {
saturation = myPetNBT.getAs("Hunger", TagDouble.class).getDoubleData();
}
if (myPetNBT.getCompoundData().containsKey("WorldGroup")) {
worldGroup = myPetNBT.getAs("WorldGroup", TagString.class).getStringData();
}
if (myPetNBT.getCompoundData().containsKey("Wants-To-Respawn")) {
wantsToRespawn = myPetNBT.getAs("Wants-To-Respawn", TagByte.class).getBooleanData();
}
setSkills(myPetNBT.getAs("Skills", TagCompound.class));
setInfo(myPetNBT.getAs("Info", TagCompound.class));
}
Aggregations