use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class RepositoryMyPetConverterService method v1_11_R1.
public void v1_11_R1(StoredMyPet pet) {
TagCompound info = pet.getInfo();
switch(pet.getPetType()) {
case Horse:
if (info.containsKey("Type")) {
byte type = info.getAs("Type", TagByte.class).getByteData();
switch(type) {
case 1:
pet.setPetType(MyPetType.Donkey);
break;
case 2:
pet.setPetType(MyPetType.Mule);
break;
case 3:
pet.setPetType(MyPetType.ZombieHorse);
break;
case 4:
pet.setPetType(MyPetType.SkeletonHorse);
break;
}
info.remove("Type");
}
break;
case Skeleton:
if (info.containsKey("Type")) {
int type = info.getAs("Type", TagInt.class).getIntData();
switch(type) {
case 1:
pet.setPetType(MyPetType.WitherSkeleton);
break;
case 2:
pet.setPetType(MyPetType.Stray);
break;
}
info.remove("Type");
}
if (info.containsKey("Wither")) {
if (info.getAs("Wither", TagByte.class).getBooleanData()) {
pet.setPetType(MyPetType.WitherSkeleton);
info.remove("Wither");
}
}
break;
case Zombie:
if (info.containsKey("Type")) {
int type = info.getAs("Type", TagInt.class).getIntData();
switch(type) {
case 6:
pet.setPetType(MyPetType.Husk);
break;
case 0:
break;
default:
if (type == 2) {
if (info.containsKey("Profession")) {
pet.setPetType(MyPetType.ZombieVillager);
info.put("Profession", new TagInt(info.getAs("Profession", TagInt.class).getIntData() - 1));
} else {
pet.setPetType(MyPetType.Husk);
}
} else {
pet.setPetType(MyPetType.ZombieVillager);
if (info.containsKey("Profession")) {
info.put("Profession", new TagInt(info.getAs("Profession", TagInt.class).getIntData() - 1));
}
}
}
info.remove("Type");
}
if (info.containsKey("Villager")) {
if (info.getAs("Villager", TagByte.class).getBooleanData()) {
pet.setPetType(MyPetType.ZombieVillager);
info.remove("Villager");
}
}
if (info.containsKey("Husk")) {
if (info.getAs("Husk", TagByte.class).getBooleanData()) {
pet.setPetType(MyPetType.Husk);
info.remove("Husk");
}
}
break;
case Guardian:
if (info.containsKey("Elder")) {
if (info.getAs("Elder", TagByte.class).getBooleanData()) {
pet.setPetType(MyPetType.ElderGuardian);
info.remove("Elder");
}
}
break;
}
}
use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class NbtRepository method getMyPetPlayer.
@Override
public void getMyPetPlayer(final Player player, final RepositoryCallback<MyPetPlayer> callback) {
if (callback != null) {
for (TagCompound playerTag : playerTags.values()) {
if (playerTag.containsKeyAs("UUID", TagCompound.class)) {
TagCompound uuidTag = playerTag.getAs("UUID", TagCompound.class);
if (uuidTag.getCompoundData().containsKey("Mojang-UUID")) {
if (UUID.fromString(uuidTag.getAs("Mojang-UUID", TagString.class).getStringData()).equals(player.getUniqueId())) {
MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
callback.run(myPetPlayer);
return;
}
}
if (uuidTag.getCompoundData().containsKey("Name")) {
if (uuidTag.getAs("Name", TagString.class).getStringData().equals(player.getName())) {
MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
callback.run(myPetPlayer);
return;
}
}
if (playerTag.getCompoundData().containsKey("Name")) {
if (playerTag.getAs("Name", TagString.class).getStringData().equals(player.getName())) {
MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
callback.run(myPetPlayer);
return;
}
}
}
}
}
}
use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class NbtRepository method loadPlayers.
private int loadPlayers(TagList playerList) {
int playerCount = 0;
for (int i = 0; i < playerList.getReadOnlyList().size(); i++) {
TagCompound playerTag = playerList.getTagAs(i, TagCompound.class);
UUID internalUUID = getInternalUUID(playerTag);
if (internalUUID != null) {
playerTags.put(internalUUID, playerTag);
playerCount++;
}
}
return playerCount;
}
use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class NbtRepository method countMyPets.
@Override
public void countMyPets(MyPetType type, final RepositoryCallback<Integer> callback) {
int counter = 0;
for (TagCompound petTag : petTags.values()) {
if (petTag.getAs("Type", TagString.class).equals(type.name())) {
counter++;
}
}
callback.run(counter);
}
use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class NbtRepository method getMyPet.
@Override
public void getMyPet(final UUID uuid, final RepositoryCallback<StoredMyPet> callback) {
if (callback != null) {
if (petTags.containsKey(uuid)) {
TagCompound petTag = petTags.get(uuid);
UUID ownerUUID;
if (petTag.containsKeyAs("Internal-Owner-UUID", TagString.class)) {
ownerUUID = UUID.fromString(petTag.getAs("Internal-Owner-UUID", TagString.class).getStringData());
} else {
return;
}
if (!playerTags.containsKey(ownerUUID)) {
return;
}
MyPetPlayer owner = MyPetApi.getPlayerManager().getMyPetPlayer(ownerUUID);
if (owner != null) {
InactiveMyPet myPet = new InactiveMyPet(owner);
myPet.load(petTag);
List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
for (RepositoryMyPetConverterService converter : converters) {
converter.convert(myPet);
}
callback.run(myPet);
}
}
}
}
Aggregations