Search in sources :

Example 1 with PortalTask

use of com.alessiodp.parties.tasks.PortalTask in project Parties by AlessioDP.

the class FollowListener method onChangeWorld.

@EventHandler
public void onChangeWorld(PlayerChangedWorldEvent event) {
    if (ConfigMain.ADDITIONAL_FOLLOW_ENABLE) {
        // Make it async
        plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
            if (ConfigMain.ADDITIONAL_FOLLOW_LISTWORLDS.contains("*") || ConfigMain.ADDITIONAL_FOLLOW_LISTWORLDS.contains(event.getPlayer().getWorld().getName())) {
                Player player = event.getPlayer();
                PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
                if (!pp.getPartyName().isEmpty()) {
                    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
                    if (party != null) {
                        if (pp.getRank() >= ConfigMain.ADDITIONAL_FOLLOW_RANKNEEDED) {
                            // Init teleport
                            for (Player pl : party.getOnlinePlayers()) {
                                if (!pl.getUniqueId().equals(player.getUniqueId()) && !pl.getWorld().equals(player.getWorld())) {
                                    PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(pl.getUniqueId());
                                    if (ppVictim.getRank() >= ConfigMain.ADDITIONAL_FOLLOW_RANKMINIMUM) {
                                        // Make it sync
                                        plugin.getPartiesScheduler().runSync(() -> {
                                            switch(ConfigMain.ADDITIONAL_FOLLOW_TYPE) {
                                                case 1:
                                                    ppVictim.setPortalTimeoutTask(new PortalTask(pl.getUniqueId()).runTaskLaterAsynchronously(plugin, ConfigMain.ADDITIONAL_FOLLOW_TIMEOUT).getTaskId());
                                                    ppVictim.sendMessage(Messages.OTHER_FOLLOW_WORLD.replace("%player%", player.getName()).replace("%world%", player.getWorld().getName()));
                                                    pl.teleport(player.getWorld().getSpawnLocation());
                                                    break;
                                                case 2:
                                                    ppVictim.setPortalTimeoutTask(new PortalTask(pl.getUniqueId()).runTaskLaterAsynchronously(plugin, ConfigMain.ADDITIONAL_FOLLOW_TIMEOUT).getTaskId());
                                                    ppVictim.sendMessage(Messages.OTHER_FOLLOW_WORLD.replace("%player%", player.getName()).replace("%world%", player.getWorld().getName()));
                                                    pl.teleport(player);
                                            }
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
    }
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PortalTask(com.alessiodp.parties.tasks.PortalTask) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 PortalTask (com.alessiodp.parties.tasks.PortalTask)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1