Solved Chat Spammed in my plugin

Discussion in 'Spigot Plugin Help' started by commandROD, Jun 14, 2021.

Thread Status:
Not open for further replies.
  1. Hey everyone,
    My chat is getting spammed when I stand on a gold block because of the following code.

    Code (Text):
    @EventHandler
    public void onMove(PlayerMoveEvent e){
        Player p = e.getPlayer();
        Location loc = p.getLocation();
        if(p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.GOLD_BLOCK) {
            p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1, 1);
            p.sendMessage(Utils.color("&6Checkpoint set!"));
        }
    }
    Is there any other event that I can use so the chat wont get spammed with "Checkpoint set"?
     
  2. SteelPhoenix

    Moderator

    Just set it once and once a player has said checkpoint don't do anything?
     
    • Agree Agree x 1
  3. I would imagine you're going to be saving that checkpoint somewhere such as a hashmap, just use that to check if the player has already hit the checkpoint, if so then don't send the message or sound, etc.

    sniped
     
    • Agree Agree x 1
  4. You can do a List with all the players that already hit the chekpoint. Then you do something like this:

    Code (Text):
    private List<Player> list = new ArrayList<>();

    @EventHandler
    public void onMove(PlayerMoveEvent e){
        Player p = e.getPlayer();
        if (list.contains(player)) return;
        Location loc = p.getLocation();
        if(p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.GOLD_BLOCK) {
            p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1, 1);
            p.sendMessage(Utils.color("&6Checkpoint set!"));
            list.add(player);
        }
    }
     
  5. Thanks! idk how I didn't even notice it lol
     
Thread Status:
Not open for further replies.