Solved 1.15 Disable advancements in one world?

Discussion in 'Spigot Plugin Development' started by MartinOdum, Jan 1, 2020.

  1. I have searched for quite some time now and I cannot find an answer, I have a survival and a creative world, when people enter the creative world I don't want them to be able earn advancements of any kind while they are in that world, my current approach is the following and I fear that it may not be the best

    Code (Java):
        @EventHandler
        public void Advancementdone(PlayerAdvancementDoneEvent event){
            if(event.getPlayer().getWorld().getName().equalsIgnoreCase("creative")){
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "advancement revoke " + event.getPlayer().getName() + " only " + event.getAdvancement().getKey().getKey());
            }
        }
    I also have seen people say to use (/gamerule announceAdvancements false) but just from using common sense I can assume that does not block advancements from being earned but simply mutes notifications for them in that world, if anyone has any ideas on how I can achieve this I would appreciate the help thanks!
     
  2. Since the event isn't cancellable, you'd have to manually remove the advancement after it has been made. This alone won't stop the advancement from being broadcasted though obviously, so you'd still have to set that gamerule to false.
    After looking through the documentation for a bit, I was able to come up with the following method (not tested):

    Code (Java):

        @EventHandler
        public void onAdvancement(PlayerAdvancementDoneEvent e){
            Player player = e.getPlayer();
            Advancement advancement = e.getAdvancement();
         
            for (String criteria : advancement.getCriteria()) {
                player.getAdvancementProgress(advancement).revokeCriteria(criteria);
            }
        }
     
    • Like Like x 3
  3. Awesome! I gave it a quick test and seems to work like a charm, with the gamerule set to false it works exactly how I need it, thanks a ton!
     
    • Friendly Friendly x 3