Search in sources :

Example 36 with PartyEntity

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

the class ApiHandler method createParty.

@Override
public Status createParty(PartyPlayer paramPartyPlayer, String paramPartyName) {
    Status ret = Status.ALREADYINPARTY;
    // Get an instance of PartyPlayerEntity, used to save same player
    PartyPlayerEntity player = null;
    if (paramPartyPlayer instanceof PartyPlayerEntity) {
        player = (PartyPlayerEntity) paramPartyPlayer;
    } else {
        player = (PartyPlayerEntity) getPartyPlayer(paramPartyPlayer.getPlayerUUID());
    }
    if (player.getPartyName().isEmpty()) {
        if (!plugin.getPartyManager().existParty(paramPartyName)) {
            PartyEntity party = new PartyEntity(paramPartyName, plugin);
            party.getMembers().add(player.getPlayerUUID());
            Player p = player.getPlayer();
            if (p != null)
                party.getOnlinePlayers().add(p);
            party.setLeader(player.getPlayerUUID());
            plugin.getPartyManager().getListParties().put(party.getName().toLowerCase(), party);
            player.setRank(ConfigParties.RANK_SET_HIGHER);
            player.setPartyName(party.getName());
            party.updateParty();
            player.updatePlayer();
            party.callChange();
            return Status.SUCCESS;
        } else
            ret = Status.ALREADYEXISTPARTY;
    }
    return ret;
}
Also used : Status(com.alessiodp.partiesapi.enums.Status) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 37 with PartyEntity

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

the class BMHook method onPlayerBan.

@EventHandler(ignoreCancelled = true)
public void onPlayerBan(PlayerBannedEvent event) {
    PlayerData pl = event.getBan().getPlayer();
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(pl.getUUID());
    // Spy listener
    if (pp.isSpy())
        plugin.getSpyManager().removeSpy(pp.getPlayerUUID());
    // Party checking
    if (!pp.getPartyName().isEmpty()) {
        PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
        if (party != null) {
            PartyPlayerEntity kickerPp = plugin.getPlayerManager().getPlayer(event.getBan().getActor().getUUID());
            // Calling API event
            PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(pp, party, true, kickerPp);
            Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
            if (!partiesLeaveEvent.isCancelled()) {
                if (party.getLeader().equals(pl.getUUID())) {
                    // Calling Pre API event
                    PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.BAN, pp, kickerPp);
                    Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
                    if (!partiesPreDeleteEvent.isCancelled()) {
                        party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_DISBANDED);
                        party.removeParty();
                        // Calling Post API event
                        PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.BAN, pp, kickerPp);
                        Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
                        LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_LIB_BANMANAGER_BAN.replace("{party}", party.getName()).replace("{player}", pl.getName()), true, ConsoleColor.CYAN);
                    } else {
                        // Event is cancelled, block ban chain
                        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY_GENERIC.replace("{party}", party.getName()), true);
                        return;
                    }
                } else {
                    party.getMembers().remove(pl.getUUID());
                    party.getOnlinePlayers().remove(pl.getPlayer());
                    party.sendBroadcast(pp, Messages.MAINCMD_KICK_BROADCAST);
                    party.updateParty();
                }
            } else
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{player}", pl.getName()).replace("{party}", party.getName()), true);
        }
        pp.cleanupPlayer(true);
    }
}
Also used : PartiesPartyPostDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPartyPreDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PartiesPlayerLeaveEvent(com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent) PlayerData(me.confuser.banmanager.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 38 with PartyEntity

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

the class PAPIHook method onPlaceholderRequest.

@Override
public String onPlaceholderRequest(Player p, String identifier) {
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(p.getUniqueId());
    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
    PartiesPlaceholder ph = PartiesPlaceholder.getPlaceholder(identifier);
    return ph != null ? ph.formatPlaceholder(pp, party) : "";
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPlaceholder(com.alessiodp.parties.addons.internal.PartiesPlaceholder) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Example 39 with PartyEntity

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

the class CrackShotHandler method onWeaponDamageEntity.

@EventHandler
public void onWeaponDamageEntity(WeaponDamageEntityEvent event) {
    if (active && ConfigParties.FRIENDLYFIRE_ENABLE) {
        if (event.getVictim() instanceof Player) {
            PartyPlayerEntity shooterPp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
            Player victim = (Player) event.getVictim();
            if (!victim.getUniqueId().equals(shooterPp.getPlayerUUID()) && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(victim.getWorld().getName()))) {
                PartyPlayerEntity victimPp = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
                if (!shooterPp.getPartyName().isEmpty() && shooterPp.getPartyName().equalsIgnoreCase(victimPp.getPartyName())) {
                    // Calling API event
                    PartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesFriendlyFireBlockedEvent(victimPp, shooterPp, null);
                    Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
                    if (!partiesFriendlyFireEvent.isCancelled()) {
                        // Friendly fire confirmed
                        PartyEntity party = plugin.getPartyManager().getParty(victimPp.getPartyName());
                        shooterPp.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
                        party.sendFriendlyFireWarn(victimPp, shooterPp);
                        event.setCancelled(true);
                        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "entity combust").replace("{player}", shooterPp.getName()).replace("{victim}", victim.getName()), true);
                    } else
                        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "entity combust").replace("{player}", shooterPp.getName()).replace("{victim}", victim.getName()), true);
                }
            }
        }
    }
}
Also used : PartiesFriendlyFireBlockedEvent(com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent) Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 40 with PartyEntity

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

the class FightListener method onPlayerHit.

@EventHandler
public void onPlayerHit(EntityDamageByEntityEvent event) {
    if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player) {
        Player victim = (Player) event.getEntity();
        Player attacker = null;
        // 0=Basic, 1=Arrow, 2=EnderPearl, 3=Snowball
        DamageType type = DamageType.UNSUPPORTED;
        if (event.getDamager() instanceof Player)
            type = DamageType.PLAYER;
        else if (event.getDamager() instanceof Arrow)
            type = DamageType.ARROW;
        else if (event.getDamager() instanceof EnderPearl)
            type = DamageType.ENDERPEARL;
        else if (event.getDamager() instanceof Snowball)
            type = DamageType.SNOWBALL;
        if (!type.equals(DamageType.UNSUPPORTED)) {
            ProjectileSource shooterSource;
            switch(type) {
                case PLAYER:
                    attacker = (Player) event.getDamager();
                    break;
                case ARROW:
                    shooterSource = ((Arrow) event.getDamager()).getShooter();
                    if (shooterSource instanceof Player)
                        attacker = (Player) shooterSource;
                    break;
                case ENDERPEARL:
                    shooterSource = ((EnderPearl) event.getDamager()).getShooter();
                    if (shooterSource instanceof Player)
                        attacker = (Player) shooterSource;
                    break;
                case SNOWBALL:
                    shooterSource = ((Snowball) event.getDamager()).getShooter();
                    if (shooterSource instanceof Player)
                        attacker = (Player) shooterSource;
                    break;
                case UNSUPPORTED:
            }
            if (attacker != null) {
                // 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
                        PartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesFriendlyFireBlockedEvent(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}", type.name()).replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
                        } else
                            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", type.name()).replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
                    }
                }
            }
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) PartiesFriendlyFireBlockedEvent(com.alessiodp.partiesapi.events.PartiesFriendlyFireBlockedEvent) Snowball(org.bukkit.entity.Snowball) Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) EnderPearl(org.bukkit.entity.EnderPearl) ProjectileSource(org.bukkit.projectiles.ProjectileSource) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) 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