Search in sources :

Example 1 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class CommandTeleport method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    Player player = (Player) commandData.getSender();
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
    /*
		 * Checks for command prerequisites
		 */
    if (!player.hasPermission(PartiesPermission.TELEPORT.toString())) {
        pp.sendNoPermission(PartiesPermission.TELEPORT);
        return false;
    }
    PartyEntity party = pp.getPartyName().isEmpty() ? null : plugin.getPartyManager().getParty(pp.getPartyName());
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
        return false;
    }
    if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_ADMIN_TELEPORT))
        return false;
    commandData.setPlayer(player);
    commandData.setPartyPlayer(pp);
    commandData.setParty(party);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 2 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class CommandTeleport method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command handling
		 */
    long unixNow = -1;
    if (ConfigParties.TELEPORT_COOLDOWN > 0 && !PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_BYPASSCOOLDOWN)) {
        Long unixTimestamp = plugin.getPlayerManager().getTeleportCooldown().get(pp.getPlayerUUID());
        unixNow = System.currentTimeMillis() / 1000L;
        if (unixTimestamp != null) {
            pp.sendMessage(Messages.ADDCMD_TELEPORT_COOLDOWN.replace("%seconds%", String.valueOf(ConfigParties.TELEPORT_COOLDOWN - (unixNow - unixTimestamp))));
            return;
        }
    }
    if (VaultHandler.payCommand(VaultHandler.VaultCommand.TELEPORT, pp, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    /*
		 * Command starts
		 */
    if (unixNow != -1) {
        plugin.getPlayerManager().getTeleportCooldown().put(pp.getPlayerUUID(), unixNow);
        new TeleportTask(pp.getPlayerUUID(), plugin.getPlayerManager()).runTaskLater(plugin, ConfigParties.TELEPORT_COOLDOWN * 20);
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_TELEPORT_START.replace("{value}", Integer.toString(ConfigParties.TELEPORT_COOLDOWN * 20)).replace("{player}", pp.getName()), true);
    }
    pp.sendMessage(Messages.ADDCMD_TELEPORT_TELEPORTING);
    for (Player pl : party.getOnlinePlayers()) {
        if (!pl.getUniqueId().equals(pp.getPlayerUUID())) {
            // Make it sync
            plugin.getPartiesScheduler().runSync(() -> {
                pl.teleport(commandData.getPlayer().getLocation());
                plugin.getPlayerManager().getPlayer(pl.getUniqueId()).sendMessage(Messages.ADDCMD_TELEPORT_TELEPORTED, pp);
            });
        }
    }
    LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_TELEPORT.replace("{player}", pp.getName()), true);
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) TeleportTask(com.alessiodp.parties.tasks.TeleportTask) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 3 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class FightListener method onEntityDieKill.

@EventHandler
public void onEntityDieKill(EntityDeathEvent event) {
    if (event.getEntity().getKiller() instanceof Player) {
        Player killer = event.getEntity().getKiller();
        PartyPlayerEntity ppKiller = plugin.getPlayerManager().getPlayer(killer.getUniqueId());
        if (!ppKiller.getPartyName().isEmpty()) {
            PartyEntity party = plugin.getPartyManager().getParty(ppKiller.getPartyName());
            if (ConfigParties.KILLS_ENABLE) {
                boolean gotKill = false;
                if (ConfigParties.KILLS_MOB_HOSTILE && event.getEntity() instanceof Monster)
                    gotKill = true;
                else if (ConfigParties.KILLS_MOB_NEUTRAL && event.getEntity() instanceof Animals)
                    gotKill = true;
                else if (ConfigParties.KILLS_MOB_PLAYERS && event.getEntity() instanceof Player)
                    gotKill = true;
                if (gotKill) {
                    party.setKills(party.getKills() + 1);
                    party.updateParty();
                    LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_KILL_ADD.replace("{party}", party.getName()).replace("{player}", killer.getName()), true);
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Animals(org.bukkit.entity.Animals) Monster(org.bukkit.entity.Monster) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 4 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class FightListener method onEntityCombustByEntity.

@EventHandler
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
    if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player && event.getCombuster() instanceof Projectile && ((Projectile) event.getCombuster()).getShooter() instanceof Player) {
        Player victim = (Player) event.getEntity();
        Player attacker = (Player) ((Projectile) event.getCombuster()).getShooter();
        // Found right attacker
        if (!victim.getUniqueId().equals(attacker.getUniqueId()) && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(victim.getWorld().getName()))) {
            // Friendly fire not allowed here
            PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
            PartyPlayerEntity ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
            if (!ppVictim.getPartyName().isEmpty() && ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
                // Calling API event
                PartiesCombustFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesCombustFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
                Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
                if (!partiesFriendlyFireEvent.isCancelled()) {
                    // Friendly fire confirmed
                    PartyEntity party = plugin.getPartyManager().getParty(ppVictim.getPartyName());
                    ppAttacker.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
                    party.sendFriendlyFireWarn(ppVictim, ppAttacker);
                    event.setCancelled(true);
                    LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "entity combust").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
                } else
                    LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "entity combust").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesCombustFriendlyFireBlockedEvent(com.alessiodp.partiesapi.events.PartiesCombustFriendlyFireBlockedEvent) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 5 with PartyEntity

use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.

the class ChatListener method onPlayerChat.

@EventHandler(priority = EventPriority.LOW)
public void onPlayerChat(AsyncPlayerChatEvent event) {
    if (!event.isCancelled()) {
        Player p = event.getPlayer();
        PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(p.getUniqueId());
        if (!pp.getPartyName().isEmpty() && pp.isChatParty()) {
            // Make it async
            plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
                if (PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_SENDMESSAGE)) {
                    // Chat allowed
                    boolean mustWait = false;
                    if (ConfigParties.GENERAL_CHAT_CHATCD > 0 && !PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_BYPASSCOOLDOWN)) {
                        Long unixTimestamp = plugin.getPlayerManager().getChatCooldown().get(p.getUniqueId());
                        long unixNow = System.currentTimeMillis() / 1000L;
                        // Check cooldown
                        if (unixTimestamp != null) {
                            pp.sendMessage(Messages.MAINCMD_P_COOLDOWN.replace("%seconds%", String.valueOf(ConfigParties.GENERAL_CHAT_CHATCD - (unixNow - unixTimestamp))));
                            mustWait = true;
                        } else {
                            plugin.getPlayerManager().getChatCooldown().put(p.getUniqueId(), unixNow);
                            new ChatTask(p.getUniqueId(), plugin.getPlayerManager()).runTaskLater(plugin, ConfigParties.GENERAL_CHAT_CHATCD * 20);
                            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_CMD_P_TASK.replace("{value}", Integer.toString(ConfigParties.GENERAL_CHAT_CHATCD * 20)).replace("{player}", p.getName()), true);
                        }
                    }
                    if (!mustWait) {
                        PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
                        // Calling API event
                        PartiesChatEvent partiesChatEvent = new PartiesChatEvent(pp, party, event.getMessage());
                        Bukkit.getServer().getPluginManager().callEvent(partiesChatEvent);
                        String newMessage = partiesChatEvent.getMessage();
                        if (!partiesChatEvent.isCancelled()) {
                            party.sendPlayerMessage(pp, newMessage);
                            if (ConfigMain.STORAGE_LOG_CHAT)
                                LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_P.replace("{party}", party.getName()).replace("{player}", p.getName()).replace("{message}", newMessage), true);
                        } else
                            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_CHATEVENT_DENY.replace("{player}", p.getName()).replace("{message}", event.getMessage()), true);
                    }
                } else
                    pp.sendNoPermission(PartiesPermission.PRIVATE_SENDMESSAGE);
            });
            event.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) ChatTask(com.alessiodp.parties.tasks.ChatTask) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PartiesChatEvent(com.alessiodp.partiesapi.events.PartiesChatEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)67 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)56 Player (org.bukkit.entity.Player)31 EventHandler (org.bukkit.event.EventHandler)11 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)6 Status (com.alessiodp.partiesapi.enums.Status)5 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)5 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)5 UUID (java.util.UUID)5 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)3 Party (com.alessiodp.partiesapi.objects.Party)3 ArrayList (java.util.ArrayList)3 PartiesPlaceholder (com.alessiodp.parties.addons.internal.PartiesPlaceholder)2 ChatTask (com.alessiodp.parties.tasks.ChatTask)2 PartiesChatEvent (com.alessiodp.partiesapi.events.PartiesChatEvent)2 PartiesFriendlyFireBlockedEvent (com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent)2 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 Matcher (java.util.regex.Matcher)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Result (com.alessiodp.parties.addons.external.GriefPreventionHandler.Result)1