Class WorldGroup

java.lang.Object
de.Keyle.MyPet.api.WorldGroup

public class WorldGroup extends Object
A named set of worlds that share pets. A pet belongs to exactly one group, so a player can keep a different pet in each. The ---DISABLED--- group marks worlds where MyPet does not run at all.
  • Field Details

    • DEFAULT_GROUP

      public static final WorldGroup DEFAULT_GROUP
      The group every world falls into unless the config says otherwise.
    • DISABLED_GROUP

      public static final WorldGroup DISABLED_GROUP
      The group for worlds MyPet is switched off in.
  • Constructor Details

    • WorldGroup

      public WorldGroup(String groupName, boolean disabled)
      Creates a group and registers it. A group whose name is already taken is not registered again.
      Parameters:
      groupName - the group's name; lower-cased on the way in
      disabled - true to switch MyPet off in this group's worlds
  • Method Details

    • getWorlds

      public List<String> getWorlds()
      The worlds in this group.
      Returns:
      the world names in this group; a read-only view, empty if the group is no longer registered
    • getGroups

      public static Collection<WorldGroup> getGroups()
      Returns all available world groups
      Returns:
      Collection<WorldGroup>
    • getGroupByWorld

      public static WorldGroup getGroupByWorld(String name)
      Returns the group the world is in
      Parameters:
      name - the world's name
      Returns:
      the world's group, or DISABLED_GROUP if no group claims the world (never null)
    • getGroupByWorld

      public static WorldGroup getGroupByWorld(World world)
      Returns the group the world is in
      Parameters:
      world - the world
      Returns:
      the world's group, or DISABLED_GROUP if no group claims the world (never null)
    • getGroupByName

      public static WorldGroup getGroupByName(String name)
      Returns the group by name. Group names are stored lower-cased, so the lookup ignores case.
      Parameters:
      name - the group's name
      Returns:
      the group, or DISABLED_GROUP if there is no group with that name (never null)
    • clearGroups

      public static void clearGroups()
      Removes all worlds from the groups and then deletes the groups, leaving only the default and disabled groups.
    • loadGroups

      public static void loadGroups(File f)
      Reads every group from the given YAML file, then puts any world not mentioned into the default group. The new groups are built on the side and replace the old ones in a single step, so lookups running on other threads during a reload never see a half-loaded state. If reading fails, the old groups stay.
      Parameters:
      f - the world-groups configuration file
    • addWorld

      public boolean addWorld(String world)
      Adds a world to this group, unless another group already claims it.
      Parameters:
      world - the world name to add
      Returns:
      true if the world was added
    • containsWorld

      public boolean containsWorld(String worldName)
      Checks whether a world group contains the world
      Parameters:
      worldName - The name of the checked world
      Returns:
      boolean
    • getName

      public String getName()
      This group's name, lower-cased.
      Returns:
      the group name
    • isDisabled

      public boolean isDisabled()
      Whether MyPet is switched off in this group's worlds.
      Returns:
      true if pets are disabled here