Solved How to detect an advancement.

Discussion in 'Spigot Plugin Development' started by xTimDevx, Jun 17, 2018.

  1. Hey, I am making a plugin that detects when an advancement is given.

    My question is how to do you get the name of an advancement so you can detect it using the PlayerAdvancementDoneEvent, this is my code so far:
    Code (Java):
     @EventHandler
        public void onAch(PlayerAdvancementDoneEvent event){
            Player player = (Player) event.getPlayer();
            User user = User.get(player);
            Advancement advancement = event.getAdvancement();
            String name = advancement.getKey().getKey();
            if(name.equalsIgnoreCase("minecraft:end/dragon_breath")) {
                if(user.getFile().get("ADVMINT") == true) {
                    return;
                }

                user.getFile().set("ADVMINT", true);
                user.getFile().set("ChallengesComp", user.getFile().getInt("ChallengesComp") + 1);
                user.saveFile();

                Bukkit.broadcastMessage("§8[§bChallenges§8]: §b" + player.getName() + " §fCompleted the §bDragon Hunter §fchallenge.");
                player.sendMessage("§8§m-----------------------------------------");
                player.sendMessage("§a§lCONGRATS!");
                player.sendMessage("§fYou completed the §bDragon Hunter §fchallenge.");
                player.sendMessage("§fYou have completed §b" + user.getFile().getInt("ChallengesComp") + "§8/§b11 §fchallenges.");
                player.sendMessage("§8§m-----------------------------------------");
            }
        }
     
     
  2. I remember this thread from a while back - https://www.spigotmc.org/threads/checking-and-awarding-advancements.241636/
    It discusses the use of the NamespacedKey. (The thing that you're getting with the advancement.getKey() getter).

    Not sure if this will help your progress. Another suggestion would be to log some of the objects into your console, so you can see what
    Code (Java):
    String name = advancement.getKey().getKey();
    actually returns.
     
  3. I already fixed it, thanks for helping.