Test if a Gamerule is true

Discussion in 'Plugin Development' started by sschr15, Apr 20, 2020.

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

    sschr15

    I'm currently developing a plugin that checks the announceAdvancements gamerule to determine whether the code should run. However, I'm unsure of how to do that as apparently I can't cast a GameRule<Boolean> to Boolean. That means I'm currently stuck.

    Here is my current code:
    Code:
        @EventHandler
        public void onAdvancement(PlayerAdvancementDoneEvent event) {
            GameRule<Boolean> announceAdvancements = (GameRule<Boolean>) GameRule.getByName("announce_advancements");
            if (announceAdvancements) {
    //            . . .
                }
            }
        }
    I think I actually figured out what to do, but I don't know how to close the thread...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 20, 2020
  2. Offline

    KarimAKL

    @sschr15 You can check it like this:
    Code:Java
    1. // Get the value of the GameRule in the player's world
    2. Boolean value = event.getPlayer().getWorld().getGameRuleValue(GameRule.ANNOUNCE_ADVANCEMENTS);
    3.  
    4. // Check if the value is true
    5. if (value) {
    6. // Your code here
    7. }
     
Thread Status:
Not open for further replies.

Share This Page