use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class PlayerListener method onMyPet.
@EventHandler
public void onMyPet(PlayerTeleportEvent event) {
if (!event.getPlayer().isOnline()) {
return;
}
if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer().getName())) {
final MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
if (myPetPlayer.hasMyPet()) {
final MyPet myPet = myPetPlayer.getMyPet();
if (myPet.getStatus() == MyPet.PetState.Here) {
if (myPet.getLocation().get().getWorld() != event.getTo().getWorld() || MyPetApi.getPlatformHelper().distance(myPet.getLocation().get(), event.getTo()) > 10) {
final boolean sameWorld = myPet.getLocation().get().getWorld() == event.getTo().getWorld();
myPet.removePet();
new BukkitRunnable() {
public void run() {
if (myPetPlayer.isOnline() && myPetPlayer.hasMyPet()) {
MyPet runMyPet = myPetPlayer.getMyPet();
switch(runMyPet.createEntity()) {
case Canceled:
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", myPetPlayer), runMyPet.getPetName()));
break;
case NoSpace:
if (sameWorld) {
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", myPetPlayer), runMyPet.getPetName()));
}
break;
case Flying:
if (sameWorld) {
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", myPetPlayer), runMyPet.getPetName()));
}
break;
case NotAllowed:
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", myPetPlayer), runMyPet.getPetName()));
break;
}
}
}
}.runTaskLater(MyPetApi.getPlugin(), 20L);
}
}
}
}
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class PlayerListener method on.
@EventHandler
public void on(final PlayerDeathEvent event) {
if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getEntity())) {
MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getEntity());
if (myPetPlayer.hasMyPet()) {
final MyPet myPet = myPetPlayer.getMyPet();
if (myPet.getStatus() == MyPet.PetState.Here && Configuration.Skilltree.Skill.Inventory.DROP_WHEN_OWNER_DIES) {
if (myPet.getSkills().isSkillActive(Inventory.class)) {
CustomInventory inv = myPet.getSkills().getSkill(Inventory.class).get().getInventory();
inv.dropContentAt(myPet.getLocation().get());
}
}
myPet.removePet();
}
}
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class PlayerListener method on.
@EventHandler
public void on(final PlayerRespawnEvent event) {
if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer())) {
final MyPetPlayer respawnedMyPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
final MyPet myPet = respawnedMyPetPlayer.getMyPet();
if (respawnedMyPetPlayer.hasMyPet() && myPet.wantsToRespawn()) {
new BukkitRunnable() {
public void run() {
if (respawnedMyPetPlayer.hasMyPet()) {
MyPet runMyPet = respawnedMyPetPlayer.getMyPet();
switch(runMyPet.createEntity()) {
case Canceled:
respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", respawnedMyPetPlayer), runMyPet.getPetName()));
break;
case NoSpace:
respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", respawnedMyPetPlayer), runMyPet.getPetName()));
break;
case NotAllowed:
respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", respawnedMyPetPlayer), runMyPet.getPetName()));
break;
case Dead:
if (runMyPet != myPet) {
respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Call.Dead", respawnedMyPetPlayer), runMyPet.getPetName(), runMyPet.getRespawnTime()));
}
break;
case Flying:
respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", respawnedMyPetPlayer), runMyPet.getPetName()));
break;
case Success:
if (runMyPet != myPet) {
respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Command.Call.Success", respawnedMyPetPlayer), runMyPet.getPetName()));
}
break;
}
}
}
}.runTaskLater(MyPetApi.getPlugin(), 25L);
}
}
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class PlayerListener method onMyPetPlayerChangeWorld.
@EventHandler
public void onMyPetPlayerChangeWorld(final PlayerChangedWorldEvent event) {
if (!event.getPlayer().isOnline()) {
return;
}
if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer())) {
final MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
final WorldGroup fromGroup = WorldGroup.getGroupByWorld(event.getFrom().getName());
final WorldGroup toGroup = WorldGroup.getGroupByWorld(event.getPlayer().getWorld().getName());
final MyPet myPet = myPetPlayer.hasMyPet() ? myPetPlayer.getMyPet() : null;
final BukkitRunnable callPet = new BukkitRunnable() {
public void run() {
if (myPetPlayer.isOnline() && myPetPlayer.hasMyPet()) {
MyPet runMyPet = myPetPlayer.getMyPet();
switch(runMyPet.createEntity()) {
case Canceled:
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", myPetPlayer), runMyPet.getPetName()));
break;
case NoSpace:
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", myPetPlayer), runMyPet.getPetName()));
break;
case NotAllowed:
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", myPetPlayer), runMyPet.getPetName()));
break;
case Dead:
if (runMyPet != myPet) {
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Call.Dead", myPetPlayer), runMyPet.getPetName(), runMyPet.getRespawnTime()));
}
break;
case Flying:
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", myPetPlayer), runMyPet.getPetName()));
break;
case Success:
if (runMyPet != myPet) {
myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Command.Call.Success", myPetPlayer), runMyPet.getPetName()));
}
break;
}
}
}
};
if (fromGroup != toGroup) {
final boolean hadMyPetInFromWorld = MyPetApi.getMyPetManager().deactivateMyPet(myPetPlayer, true);
if (myPetPlayer.hasMyPetInWorldGroup(toGroup)) {
final UUID groupMyPetUUID = myPetPlayer.getMyPetForWorldGroup(toGroup);
MyPetApi.getRepository().getMyPets(myPetPlayer, new RepositoryCallback<List<StoredMyPet>>() {
@Override
public void callback(List<StoredMyPet> pets) {
for (StoredMyPet myPet : pets) {
if (myPet.getUUID().equals(groupMyPetUUID)) {
MyPetApi.getMyPetManager().activateMyPet(myPet);
break;
}
}
if (myPetPlayer.hasMyPet()) {
if (myPetPlayer.getMyPet().wantsToRespawn()) {
callPet.runTaskLater(MyPetApi.getPlugin(), 20L);
}
} else {
myPetPlayer.setMyPetForWorldGroup(toGroup, null);
}
}
});
} else if (hadMyPetInFromWorld) {
myPetPlayer.getPlayer().sendMessage(Translation.getString("Message.MultiWorld.NoActivePetInThisWorld", myPetPlayer));
}
} else if (myPet != null) {
if (myPet.wantsToRespawn()) {
callPet.runTaskLater(MyPetApi.getPlugin(), 20L);
}
}
}
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class NbtRepository method getMyPetPlayer.
public void getMyPetPlayer(final UUID uuid, final RepositoryCallback<MyPetPlayer> callback) {
if (playerTags.containsKey(uuid)) {
if (callback != null) {
MyPetPlayer myPetPlayer = createMyPetPlayer(playerTags.get(uuid));
callback.run(myPetPlayer);
}
}
}
Aggregations