Search in sources :

Example 41 with PartyPlayerEntity

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

the class MoveListener method onPlayerMove.

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    if (ConfigParties.HOME_MOVING) {
        // Make it async
        plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
            if (plugin.getPlayerManager().getHomeCounts() != 0) {
                if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
                    // Player moved
                    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
                    if (pp.getHomeTask() != -1) {
                        if (pp.getHomeFrom().distance(event.getTo()) > ConfigParties.HOME_DISTANCE) {
                            // Cancel home
                            plugin.getServer().getScheduler().cancelTask(pp.getHomeTask());
                            plugin.getPlayerManager().remHomeCount();
                            pp.setHomeTask(-1);
                            pp.sendMessage(Messages.ADDCMD_HOME_TELEPORTDENIED);
                            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_HOME_DENIED_MOVING.replace("{player}", pp.getName()), true);
                        }
                    }
                }
            }
        });
    }
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) EventHandler(org.bukkit.event.EventHandler)

Example 42 with PartyPlayerEntity

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

the class MoveListener method onPlayerGotHit.

@EventHandler
public void onPlayerGotHit(EntityDamageByEntityEvent event) {
    if (event.getEntity() instanceof Player && ConfigParties.HOME_HIT) {
        // Make it async
        plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
            if (plugin.getPlayerManager().getHomeCounts() != 0) {
                PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getEntity().getUniqueId());
                if (pp.getHomeTask() != -1) {
                    plugin.getServer().getScheduler().cancelTask(pp.getHomeTask());
                    plugin.getPlayerManager().remHomeCount();
                    pp.setHomeTask(-1);
                    pp.sendMessage(Messages.ADDCMD_HOME_TELEPORTDENIED);
                    LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_HOME_DENIED_FIGHT.replace("{player}", pp.getName()), true);
                }
            }
        });
    }
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) EventHandler(org.bukkit.event.EventHandler)

Example 43 with PartyPlayerEntity

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

the class TabCompleterHandler method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (sender instanceof Player) {
        if (cmd.getName().equalsIgnoreCase(ConfigMain.COMMANDS_CMD_PARTY)) {
            if (args.length == 1) {
                PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(((Player) sender).getUniqueId());
                LinkedHashMap<String, String> commands = pp.getAllowedCommands();
                List<String> list = new ArrayList<String>();
                for (String str : commands.keySet()) {
                    if (str.equalsIgnoreCase(ConfigMain.COMMANDS_CMD_P))
                        continue;
                    list.add(str);
                }
                for (Iterator<String> iterator = list.iterator(); iterator.hasNext(); ) {
                    String str = iterator.next();
                    if (!str.startsWith(args[0]))
                        iterator.remove();
                }
                return list;
            }
        }
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) ArrayList(java.util.ArrayList)

Example 44 with PartyPlayerEntity

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

the class EssentialsChatHandler method onChatPlayer.

@EventHandler
public void onChatPlayer(AsyncPlayerChatEvent event) {
    String old = event.getFormat();
    if (old.toLowerCase().contains("{parties_")) {
        // Bypass useless checks if parties doesn't exist
        boolean somethingChanged = false;
        PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
        PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
        Pattern pat = Pattern.compile("\\{parties_([a-z\\_]+)\\}", Pattern.CASE_INSENSITIVE);
        Matcher mat = pat.matcher(old);
        while (mat.find()) {
            String base = mat.group(0);
            String identifier = mat.group(1);
            if (identifier != null) {
                PartiesPlaceholder ph = PartiesPlaceholder.getPlaceholder(identifier);
                if (ph != null) {
                    old = old.replace(base, ph.formatPlaceholder(pp, party));
                    somethingChanged = true;
                }
            }
        }
        if (somethingChanged)
            event.setFormat(old);
    }
}
Also used : Pattern(java.util.regex.Pattern) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPlaceholder(com.alessiodp.parties.addons.internal.PartiesPlaceholder) Matcher(java.util.regex.Matcher) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 45 with PartyPlayerEntity

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

the class BungeeService method onPluginMessageReceived.

public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    if (!channel.equals(partiesChannel)) {
        return;
    }
    ByteArrayInputStream stream = new ByteArrayInputStream(message);
    DataInputStream in = new DataInputStream(stream);
    // Load entities
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
    try {
        // Get packet in input
        Packet packet = new Packet(in);
        if (packet.getVersion().equals(plugin.getDescription().getVersion())) {
            // Does the player have a party
            if (party != null) {
                // Check for rank needed to follow
                if (pp.getRank() < packet.getRankNeeded())
                    return;
                // Preparing a list that contains the name of each player to teleport
                List<String> list = new ArrayList<String>();
                for (Player pl : party.getOnlinePlayers()) {
                    UUID pUuid = pl.getUniqueId();
                    if (!pUuid.equals(player.getUniqueId())) {
                        // Have the player the minimum rank to follow?
                        if (plugin.getPlayerManager().getPlayer(pUuid).getRank() >= packet.getRankMinimum()) {
                            list.add(pUuid.toString());
                        }
                    }
                }
                // Set the info list
                packet.setInfo(list);
                // Set the message for the user
                packet.setMessage(ChatColor.translateAlternateColorCodes('&', Messages.OTHER_FOLLOW_SERVER.replace("%server%", packet.getServer())));
                // Send the output
                ByteArrayOutputStream outstream = new ByteArrayOutputStream();
                DataOutputStream out = new DataOutputStream(outstream);
                packet.write(out);
                try {
                    Player p = Bukkit.getServer().getOnlinePlayers().iterator().next();
                    if (p != null) {
                        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_BUNGEE_REPLY, true);
                        p.sendPluginMessage(plugin, partiesChannel, outstream.toByteArray());
                    }
                } catch (Exception ex) {
                // Server empty
                }
            }
        } else {
            LoggerManager.printError(Constants.DEBUG_BUNGEE_VERSIONMISMATCH.replace("{packet}", packet.getVersion()));
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
Also used : Packet(com.alessiodp.parties.bungeecord.utils.Packet) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) UUID(java.util.UUID)

Aggregations

PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)92 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)56 Player (org.bukkit.entity.Player)53 EventHandler (org.bukkit.event.EventHandler)13 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)9 UUID (java.util.UUID)8 ArrayList (java.util.ArrayList)6 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)4 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)4 OfflinePlayer (org.bukkit.OfflinePlayer)4 Status (com.alessiodp.partiesapi.enums.Status)3 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)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 PartiesPlayerJoinEvent (com.alessiodp.partiesapi.events.PartiesPlayerJoinEvent)2 Rank (com.alessiodp.partiesapi.interfaces.Rank)2 Matcher (java.util.regex.Matcher)2 Result (com.alessiodp.parties.addons.external.GriefPreventionHandler.Result)1