use of de.Keyle.MyPet.api.event.MyPetPlayerJoinEvent in project MyPet by xXKeyleXx.
the class PlayerListener method on.
@EventHandler
public void on(final PlayerJoinEvent event) {
long delay = MyPetApi.getRepository() instanceof SqLiteRepository ? 1L : Configuration.Repository.EXTERNAL_LOAD_DELAY;
new BukkitRunnable() {
@Override
public void run() {
MyPetApi.getRepository().getMyPetPlayer(event.getPlayer(), new RepositoryCallback<MyPetPlayer>() {
@Override
public void callback(final MyPetPlayer p) {
final MyPetPlayerImpl joinedPlayer = (MyPetPlayerImpl) p;
joinedPlayer.setLastKnownName(event.getPlayer().getName());
if (!event.getPlayer().getUniqueId().equals(joinedPlayer.getOfflineUUID())) {
if (joinedPlayer.getMojangUUID() == null) {
joinedPlayer.setMojangUUID(event.getPlayer().getUniqueId());
}
joinedPlayer.setOnlineMode(true);
}
MyPetApi.getPlayerManager().setOnline(joinedPlayer);
final WorldGroup joinGroup = WorldGroup.getGroupByWorld(event.getPlayer().getWorld().getName());
if (joinedPlayer.hasMyPet()) {
MyPet myPet = joinedPlayer.getMyPet();
if (!myPet.getWorldGroup().equals(joinGroup.getName())) {
MyPetApi.getMyPetManager().deactivateMyPet(joinedPlayer, true);
}
}
if (!joinedPlayer.hasMyPet() && joinedPlayer.hasMyPetInWorldGroup(joinGroup.getName())) {
final UUID petUUID = joinedPlayer.getMyPetForWorldGroup(joinGroup.getName());
MyPetApi.getRepository().getMyPet(petUUID, new RepositoryCallback<StoredMyPet>() {
@Override
public void callback(StoredMyPet storedMyPet) {
MyPetApi.getMyPetManager().activateMyPet(storedMyPet);
if (joinedPlayer.hasMyPet()) {
final MyPet myPet = joinedPlayer.getMyPet();
if (myPet.wantsToRespawn()) {
switch(myPet.createEntity()) {
case Canceled:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", joinedPlayer), myPet.getPetName()));
break;
case NotAllowed:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", joinedPlayer), myPet.getPetName()));
break;
case Dead:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", joinedPlayer), myPet.getPetName(), myPet.getRespawnTime()));
break;
case Flying:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", joinedPlayer), myPet.getPetName()));
break;
case NoSpace:
joinedPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", joinedPlayer), myPet.getPetName()));
break;
}
}
}
}
});
}
joinedPlayer.checkForDonation();
Bukkit.getServer().getPluginManager().callEvent(new MyPetPlayerJoinEvent(joinedPlayer));
}
});
}
}.runTaskLater(MyPetApi.getPlugin(), delay);
if (event.getPlayer().isOp() && Updater.isUpdateAvailable()) {
event.getPlayer().sendMessage(Util.formatText(Translation.getString("Message.Update.Available", event.getPlayer())) + " " + Updater.getLatest());
event.getPlayer().sendMessage(ChatColor.DARK_GREEN + " https://mypet-plugin.de/download");
}
}
Aggregations