Java 类org.bukkit.plugin.messaging.PluginMessageRecipient 实例源码

项目:HCFCore    文件:LivesReviveArgument.java   
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label));
        return true;
    }

    OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); // TODO: breaking

    if (!target.hasPlayedBefore() && !target.isOnline()) {
        sender.sendMessage(ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[1] + ChatColor.GOLD + "' not found.");
        return true;
    }

    UUID targetUUID = target.getUniqueId();
    FactionUser factionTarget = plugin.getUserManager().getUser(targetUUID);
    Deathban deathban = factionTarget.getDeathban();

    if (deathban == null || !deathban.isActive()) {
        sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned.");
        return true;
    }

    Relation relation = Relation.ENEMY;
    if (sender instanceof Player) {
        if (!sender.hasPermission(REVIVE_BYPASS_PERMISSION)) {
            if (plugin.getEotwHandler().isEndOfTheWorld()) {
                sender.sendMessage(ChatColor.RED + "You cannot revive players during EOTW.");
                return true;
            }
        }

        Player player = (Player) sender;
        UUID playerUUID = player.getUniqueId();
        int selfLives = plugin.getDeathbanManager().getLives(playerUUID);

        if (selfLives <= 0) {
            sender.sendMessage(ChatColor.RED + "You do not have any lives.");
            return true;
        }

        plugin.getDeathbanManager().setLives(playerUUID, selfLives - 1);
        PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player);
        relation = playerFaction == null ? Relation.ENEMY : playerFaction.getFactionRelation(plugin.getFactionManager().getPlayerFaction(targetUUID));
        sender.sendMessage(ChatColor.YELLOW + "You have used a life to revive " + relation.toChatColour() + target.getName() + ChatColor.YELLOW + '.');
    } else {
        sender.sendMessage(ChatColor.YELLOW + "You have revived " + SettingsYML.ENEMY_COLOUR + target.getName() + ChatColor.YELLOW + '.');
    }

    if (sender instanceof PluginMessageRecipient) {
        // NOTE: This server needs at least 1 player online.
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Message");
        out.writeUTF(args[1]);

        String serverDisplayName = ChatColor.GREEN + "HCF"; // TODO: Non hard-coded server display name.
        out.writeUTF(relation.toChatColour() + sender.getName() + ChatColor.GOLD + " has just revived you from " + serverDisplayName + ChatColor.GOLD + '.');
        ((PluginMessageRecipient) sender).sendPluginMessage(plugin, PROXY_CHANNEL_NAME, out.toByteArray());
    }

    factionTarget.removeDeathban();
    return true;
}
项目:HCFCore    文件:LivesReviveArgument.java   
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label));
        return true;
    }

    OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); // TODO: breaking

    if (!target.hasPlayedBefore() && !target.isOnline()) {
        sender.sendMessage(ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[1] + ChatColor.GOLD + "' not found.");
        return true;
    }

    UUID targetUUID = target.getUniqueId();
    FactionUser factionTarget = plugin.getUserManager().getUser(targetUUID);
    Deathban deathban = factionTarget.getDeathban();

    if (deathban == null || !deathban.isActive()) {
        sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned.");
        return true;
    }

    Relation relation = Relation.ENEMY;
    if (sender instanceof Player) {
        if (!sender.hasPermission(REVIVE_BYPASS_PERMISSION)) {
            if (plugin.getEotwHandler().isEndOfTheWorld()) {
                sender.sendMessage(ChatColor.RED + "You cannot revive players during EOTW.");
                return true;
            }
        }

        Player player = (Player) sender;
        UUID playerUUID = player.getUniqueId();
        int selfLives = plugin.getDeathbanManager().getLives(playerUUID);

        if (selfLives <= 0) {
            sender.sendMessage(ChatColor.RED + "You do not have any lives.");
            return true;
        }

        plugin.getDeathbanManager().setLives(playerUUID, selfLives - 1);
        PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player);
        relation = playerFaction == null ? Relation.ENEMY : playerFaction.getFactionRelation(plugin.getFactionManager().getPlayerFaction(targetUUID));
        sender.sendMessage(ChatColor.YELLOW + "You have used a life to revive " + relation.toChatColour() + target.getName() + ChatColor.YELLOW + '.');
    } else {
        sender.sendMessage(ChatColor.YELLOW + "You have revived " + SettingsYML.ENEMY_COLOUR + target.getName() + ChatColor.YELLOW + '.');
    }

    if (sender instanceof PluginMessageRecipient) {
        // NOTE: This server needs at least 1 player online.
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Message");
        out.writeUTF(args[1]);

        String serverDisplayName = ChatColor.GREEN + "HCF"; // TODO: Non hard-coded server display name.
        out.writeUTF(relation.toChatColour() + sender.getName() + ChatColor.GOLD + " has just revived you from " + serverDisplayName + ChatColor.GOLD + '.');
        ((PluginMessageRecipient) sender).sendPluginMessage(plugin, PROXY_CHANNEL_NAME, out.toByteArray());
    }

    factionTarget.removeDeathban();
    return true;
}