Blocking out user Chat

Discussion in 'Plugin Development' started by InkzzzMC, Jan 23, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    InkzzzMC

    How would I block out people chatting on the server, but not blocking the messages sent by the console / plugin.

    I also don't understand how I would implement it, so an example would be great!As I have an event here already, and I need it to block the message for 2 minutes or so, when a new play joins the game!

    Code:
    Code:
      
        @EventHandler()
        public void OnJoinEvent(final PlayerJoinEvent e) {
            final Player player = e.getPlayer();
    
             if(!player.hasPlayedBefore()){
               
                this.getServer().getScheduler()
                        .scheduleSyncRepeatingTask(this, new Runnable() {
    
                            public void run() {
    
                                if (number != -1) {
    
                                }
    
                                if (number != 0) {
    
                                }
                                if (number == 40) {
                                  
                                    for (int i = 0; i <= 120; i++) {
                                        player.sendMessage(" ");
                                    }
    
                                    String ServerName = getConfig().getString(
                                            "Server-Name");
                                    String WelcomeMSG = getConfig().getString(
                                            "Welcome-Message");
    
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor
                                            .translateAlternateColorCodes('&',
                                                    ServerName)
                                            + " "
                                            + ChatColor
                                                    .translateAlternateColorCodes(
                                                            '&', WelcomeMSG));
                                    player.sendMessage(RED
                                            + "Prisons was developed by " + GRAY
                                            + "" + BOLD + "›› " + WHITE + "Inkzzz"
                                            + GRAY + " || " + WHITE + "@Inkzzz_");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
    
                                    String w = getConfig().getString("bank-world");
                                    double x = getConfig()
                                            .getDouble("Bank-Spawn.X");
                                    double y = getConfig()
                                            .getDouble("Bank-Spawn.Y");
                                    double z = getConfig()
                                            .getDouble("Bank-Spawn.Z");
                                    double yaw = getConfig().getDouble(
                                            "bank-spawn.yaw");
                                    double pitch = getConfig().getDouble(
                                            "bank-spawn.pitch");
                                    Location bank = new Location(getServer()
                                            .getWorld(w), x, y, z, (float) yaw,
                                            (float) pitch);
                                    player.teleport(bank);
    
                                    player.playSound(player.getLocation(),
                                            Sound.NOTE_PIANO, 1, 0);
    
                                    ItemStack Diamond = new ItemStack(
                                            Material.DIAMOND, 3584);
                                    ItemMeta DiamondMeta = Diamond.getItemMeta();
                                    DiamondMeta.setDisplayName(GREEN + "$50,000");
    
                                    Diamond.setItemMeta(DiamondMeta);
    
                                    player.getInventory().addItem(Diamond);
    
                                    number = number - 5;
                                    return;
                                }
    
                                if (number == 35) {
    
                                    final String PoliceMSG = getConfig().getString(
                                            "Police-Message");
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor
                                            .translateAlternateColorCodes('&',
                                                    PoliceMSG)
                                            + "");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.playSound(player.getLocation(),
                                            Sound.NOTE_PIANO, 1, 0);
                                    number = number - 5;
                                    return;
                                }
    
                                if (number == 30) {
                                    String RobberMSG = getConfig().getString(
                                            "Robber-Message");
                                    String PlayerNameColor = getConfig().getString(
                                            "Robber-Name-Color");
                                    String Robber = e.getPlayer().getName();
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor
                                            .translateAlternateColorCodes('&',
                                                    PlayerNameColor)
                                            + Robber
                                            + ""
                                            + (ChatColor
                                                    .translateAlternateColorCodes(
                                                            '&', RobberMSG) + " "));
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.playSound(player.getLocation(),
                                            Sound.NOTE_PIANO, 1, 0);
    
                                    number = number - 5;
                                    return;
                                }
                                if (number == 25) {
    
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(RED
                                            + "Police "
                                            + GRAY
                                            + ""
                                            + BOLD
                                            + "››"
                                            + WHITE
                                            + " Does anyone have a clear shot on the target?");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.playSound(player.getLocation(),
                                            Sound.NOTE_PIANO, 1, 0);
    
                                    number = number - 5;
                                    return;
                                }
                                if (number == 20) {
    
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(RED + "Police " + GRAY + ""
                                            + BOLD + "››" + WHITE + " I do sir!");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.playSound(player.getLocation(),
                                            Sound.NOTE_PIANO, 1, 0);
    
                                    number = number - 5;
                                    return;
                                }
    
                                if (number == 15) {
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(RED + "Police " + GRAY + ""
                                            + BOLD + "››" + WHITE
                                            + " Take the shot!");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.playSound(player.getLocation(),
                                            Sound.NOTE_PIANO, 1, 0);
    
                                    number = number - 5;
                                    return;
                                }
                                if (number == 10) {
                                    player.getInventory().clear();
                                    e.getPlayer().setHealth(0.0D);
    
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(RED + "Police" + GRAY + ""
                                            + BOLD + " ›› " + WHITE
                                            + "Target Neutralised! " + RED
                                            + "Over & Out!");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(" ");
                                    player.sendMessage(ChatColor.DARK_GRAY
                                            + ""
                                            + ChatColor.BOLD
                                            + "========================================");
                                    player.playSound(player.getLocation(),
                                            Sound.HURT_FLESH, 10, 0);
    
                                    if (player.isDead()) {
                                        try {
                                            Object nmsPlayer = player.getClass()
                                                    .getMethod("getHandle")
                                                    .invoke(player);
                                            Object packet = Class
                                                    .forName(
                                                            nmsPlayer.getClass()
                                                                    .getPackage()
                                                                    .getName()
                                                                    + ".PacketPlayInClientCommand")
                                                    .newInstance();
                                            Class<?> enumClass = Class
                                                    .forName(nmsPlayer.getClass()
                                                            .getPackage().getName()
                                                            + ".EnumClientCommand");
    
                                            for (Object ob : enumClass
                                                    .getEnumConstants()) {
                                                if (ob.toString().equals(
                                                        "PERFORM_RESPAWN")) {
                                                    packet = packet
                                                            .getClass()
                                                            .getConstructor(
                                                                    enumClass)
                                                            .newInstance(ob);
                                                }
                                            }
    
                                            Object con = nmsPlayer.getClass()
                                                    .getField("playerConnection")
                                                    .get(nmsPlayer);
                                            con.getClass()
                                                    .getMethod("a",
                                                            packet.getClass())
                                                    .invoke(con, packet);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
    
                                        String w1 = getConfig().getString(
                                                "spawn-world");
                                        double x1 = getConfig()
                                                .getDouble("Spawn.X");
                                        double y1 = getConfig()
                                                .getDouble("Spawn.Y");
                                        double z1 = getConfig()
                                                .getDouble("Spawn.Z");
                                        double yaw1 = getConfig().getDouble(
                                                "spawn.yaw");
                                        double pitch1 = getConfig().getDouble(
                                                "spawn.pitch");
                                        Location spawn = new Location(getServer()
                                                .getWorld(w1), x1, y1, z1,
                                                (float) yaw1, (float) pitch1);
    
                                        player.teleport(spawn);
    
                                        player.sendMessage(ChatColor.DARK_GRAY
                                                + ""
                                                + ChatColor.BOLD
                                                + "========================================");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(RED
                                                + "Warp"
                                                + GRAY
                                                + ""
                                                + BOLD
                                                + " ›› "
                                                + WHITE
                                                + "You have woken up after a long comer, to be stuck in a small, disgusting prison!");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(ChatColor.DARK_GRAY
                                                + ""
                                                + ChatColor.BOLD
                                                + "========================================");
                                        player.playSound(player.getLocation(),
                                                Sound.NOTE_PIANO, 1, 0);
    
                                        number = number - 5;
                                        return;
                                    }
    
                                    if (number == 5) {
    
                                        player.sendMessage(ChatColor.DARK_GRAY
                                                + ""
                                                + ChatColor.BOLD
                                                + "========================================");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(RED
                                                + "Warp"
                                                + GRAY
                                                + ""
                                                + BOLD
                                                + " ›› "
                                                + WHITE
                                                + "You have woken up after a long comer, to be stuck in a small, disgusting prison!");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(" ");
                                        player.sendMessage(ChatColor.DARK_GRAY
                                                + ""
                                                + ChatColor.BOLD
                                                + "========================================");
                                        player.playSound(player.getLocation(),
                                                Sound.NOTE_PIANO, 1, 0);
    
                                        player.getInventory().clear();
    
                                        number = number - 5;
                                        return;
                                    }
    
                                }
                            }
    
                        }, 0L, 100L);
     
  2. Offline

    SuchSwegMuchWow

    @InkzzzMC

    AsyncPlayerChatEvent should do the trick
     
  3. Offline

    InkzzzMC

    I understand that that would do it, but how would I implement it as there is already a event there. As I have an event here already, and I need it to block the message for 2 minutes or so, when a new play joins the game!
     
  4. Offline

    mythbusterma

    @InkzzzMC

    You can have more than one EventHandler annotated method per class?
     
  5. Offline

    InkzzzMC

    @mythbusterma But how would I implement it into my runnable?
     
  6. Offline

    Antybarrel

    You could make a taskID like so:

    Code:
     taskID = this.getServer().getScheduler().scheduleSyncRepeatingTask()
    Then in an AsyncPlayerChatEvent use:

    Code:
    Bukkit.getScheduler().isCurrentlyRunning(taskID);
     
  7. Offline

    InkzzzMC

    I get an error for taskID
     
  8. Offline

    teej107

    That's a bummer! Because we have know idea what kind of error it is. Could it be that because I don't own billions of dollars?

    In short: Specify the error
     
  9. Offline

    SuchSwegMuchWow

    @InkzzzMC

    Have a boolean and if the boolean is true then cancel chat. And when someone joins, make the boolean true and have a delayed task and toggle boolean back to false
     
  10. Offline

    567legodude

    @InkzzzMC According to what I see, you want the player not to see chat for 2 minutes when they join. But still able to see other stuff.

    The basic idea would be:

    listen for player join.
    When join add them to list and start timer.
    after timer remove from list.

    listen for player chat.
    remove players in the list so they will not get messages.
     
Thread Status:
Not open for further replies.

Share This Page