Solved Problem Registering new flags to WorldGuard

Discussion in 'Spigot Plugin Development' started by Justin393, Jul 26, 2018.

  1. I am trying to register a handfull of flags to WorldGuard via my plugin, but I keep getting the error
    I know the issue lies here: "java.lang.IllegalStateException: New flags cannot be registered at this time 26.07 09:55:39 [Server] INFO"

    I know that the registering of flags to WorldGuard is very picky and requires a very specific loading scheme, but I can't seem to get it right. WorldGuard documentation explains it here: "Make sure that you have added WorldGuard as a As a Dependency first. The order of registration is very important, so WorldGuard must load before your plugin for this to work."

    Located at: https://media.readthedocs.org/pdf/worldguard/latest/worldguard.pdf page 69.

    My plugin.yml :
    Code (YAML):
    name: MinecraftPlanetEarth
    main
    : jjbat_000.minecraftplanetearth.Core
    version
    : 1.0
    depend
    : [WorldGuard, WGRegionEvents]
    commands
    :
      minecraftplanetearth
    :
          description
    : MinecraftPlanetEarth Core command.
          aliases
    : [mcpe]
      map
    :
          description
    : Display a link to our DynMap.
          usage
    : /map
      wiki
    :
          description
    : Display a link to our Wiki.
          usage
    : /wiki
      vip
    :
          description
    : Display donation information.
          usage
    : /vip
      vote
    :
          description
    : Display voting information.
          usage
    : /vote
      web
    :
          description
    : Display website information.
          usage
    : /web
    Section of my onEnable where I register the flags:
    Code (Java):
    // WorldGuard Hook
            loadFlags();
    #loadFlags():
    Code (Java):
    private void loadFlags() {
            FlagRegistry registry = getWorldGuard().getFlagRegistry();
            try {
                registry.register(UTC_12);
                registry.register(UTC_11);
                registry.register(UTC_10);
                registry.register(UTC_9);
                registry.register(UTC_8);
                registry.register(UTC_7);
                registry.register(UTC_6);
                registry.register(UTC_5);
                registry.register(UTC_4);
                registry.register(UTC_3);
                registry.register(UTC_2);
                registry.register(UTC_1);
                registry.register(UTC_0);
                registry.register(UTC_N1);
                registry.register(UTC_N2);
                registry.register(UTC_N3);
                registry.register(UTC_N4);
                registry.register(UTC_N5);
                registry.register(UTC_N6);
                registry.register(UTC_N7);
                registry.register(UTC_N8);
                registry.register(UTC_N9);
                registry.register(UTC_N10);
                registry.register(UTC_N11);
             
             
            } catch (FlagConflictException e) {
                e.printStackTrace();
            }
        }
    #getWorldGuard():
    Code (Java):
    private WorldGuardPlugin getWorldGuard() {
            Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
            if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
            log("WorldGuard not enabled.");
            }
            return (WorldGuardPlugin) plugin;
            }
    and of course I'm declaring the Flags above everything else:
    Code (Java):
    public static final Flag UTC_12 = new StateFlag("utc-12", true);
        public static final Flag UTC_11 = new StateFlag("utc-11", true);
        public static final Flag UTC_10 = new StateFlag("utc-10", true);
        public static final Flag UTC_9 = new StateFlag("utc-9", true);
        public static final Flag UTC_8 = new StateFlag("utc-8", true);
        public static final Flag UTC_7 = new StateFlag("utc-7", true);
        public static final Flag UTC_6 = new StateFlag("utc-6", true);
        public static final Flag UTC_5 = new StateFlag("utc-5", true);
        public static final Flag UTC_4 = new StateFlag("utc-4", true);
        public static final Flag UTC_3 = new StateFlag("utc-3", true);
        public static final Flag UTC_2 = new StateFlag("utc-2", true);
        public static final Flag UTC_1 = new StateFlag("utc-1", true);
        public static final Flag UTC_0 = new StateFlag("utc0", true);
        public static final Flag UTC_N1 = new StateFlag("utc-n1", true);
        public static final Flag UTC_N2 = new StateFlag("utc-n2", true);
        public static final Flag UTC_N3 = new StateFlag("utc-n3", true);
        public static final Flag UTC_N4 = new StateFlag("utc-n4", true);
        public static final Flag UTC_N5 = new StateFlag("utc-n5", true);
        public static final Flag UTC_N6 = new StateFlag("utc-n6", true);
        public static final Flag UTC_N7 = new StateFlag("utc-n7", true);
        public static final Flag UTC_N8 = new StateFlag("utc-n8", true);
        public static final Flag UTC_N9 = new StateFlag("utc-n9", true);
        public static final Flag UTC_N10 = new StateFlag("utc-n10", true);
        public static final Flag UTC_N11 = new StateFlag("utc-n11", true);
    So if anyone has any idea, it would be very appreciated as I am currently stumped.
     
  2. Does anyone know?
     
  3. I think you need to do it in onLoad, not onEnable.
     
    • Useful Useful x 1
  4. That is a very good point, I completely forgot that there was a difference. Thank you!
     
    • Friendly Friendly x 1