Class FlagCalculator
java.lang.Object
me.tayebyassine.homestead.flags.FlagCalculator
Utility class for bitwise flag operations.
Provides methods for combining, removing, and checking bitwise flags.
Includes type-safe overloads for PlayerFlag, WorldFlag, and ControlFlag
enums to prevent mixing different flag types.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic longaddFlag(long... flags) Combines multiple bitwise flags into a single value.static longaddFlag(ControlFlag... flags) Combines multiple control flags into a single bitmask.static longaddFlag(PlayerFlag... flags) Combines multiple player flags into a single bitmask.static longCombines multiple world flags into a single bitmask.static booleanareAllFlagsSet(long flags, long... requiredFlags) Checks if all specified flags are set in a combined bitmask.static booleanareAllFlagsSet(long flags, ControlFlag... requiredFlags) Checks if all specified control flags are set.static booleanareAllFlagsSet(long flags, PlayerFlag... requiredFlags) Checks if all specified player flags are set.static booleanareAllFlagsSet(long flags, WorldFlag... requiredFlags) Checks if all specified world flags are set.static intcountFlagsSet(long flags, long... flagsToCheck) Counts how many of the specified flags are set in a combined bitmask.static List<ControlFlag> getSetControlFlags(long flags) Returns a list of ControlFlag enums that are set in the given bitmask.static List<PlayerFlag> getSetPlayerFlags(long flags) Returns a list of PlayerFlag enums that are set in the given bitmask.getSetWorldFlags(long flags) Returns a list of WorldFlag enums that are set in the given bitmask.static List<ControlFlag> getUnsetControlFlags(long flags) Returns a list of ControlFlag enums that are NOT set in the given bitmask.static List<PlayerFlag> getUnsetPlayerFlags(long flags) Returns a list of PlayerFlag enums that are NOT set in the given bitmask.getUnsetWorldFlags(long flags) Returns a list of WorldFlag enums that are NOT set in the given bitmask.static booleanisAnyFlagSet(long flags, long... flagsToCheck) Checks if any of the specified flags are set in a combined bitmask.static booleanisAnyFlagSet(long flags, ControlFlag... flagsToCheck) Checks if any of the specified control flags are set.static booleanisAnyFlagSet(long flags, PlayerFlag... flagsToCheck) Checks if any of the specified player flags are set.static booleanisAnyFlagSet(long flags, WorldFlag... flagsToCheck) Checks if any of the specified world flags are set.static booleanisFlagSet(long flags, long flag) Checks if a specific flag is set in a combined bitmask.static booleanisFlagSet(long flags, ControlFlag flag) Checks if a control flag is set in a combined bitmask.static booleanisFlagSet(long flags, PlayerFlag flag) Checks if a player flag is set in a combined bitmask.static booleanChecks if a world flag is set in a combined bitmask.static longremoveFlag(long flags, long flag) Removes a flag from a combined bitmask.static longremoveFlag(long flags, ControlFlag flag) Removes a control flag from a combined bitmask.static longremoveFlag(long flags, PlayerFlag flag) Removes a player flag from a combined bitmask.static longremoveFlag(long flags, WorldFlag flag) Removes a world flag from a combined bitmask.static longremoveFlags(long flags, long... flagsToRemove) Returns a new bitmask with the specified flags removed.static longtoBitmask(ControlFlag... flags) Converts an array of ControlFlags to a combined bitmask.static longtoBitmask(PlayerFlag... flags) Converts an array of PlayerFlags to a combined bitmask.static longConverts an array of WorldFlags to a combined bitmask.static longtoggleFlag(long flags, long flag) Toggles a flag in a combined bitmask (adds if not present, removes if present).static longtoggleFlag(long flags, ControlFlag flag) Toggles a control flag in a combined bitmask.static longtoggleFlag(long flags, PlayerFlag flag) Toggles a player flag in a combined bitmask.static longtoggleFlag(long flags, WorldFlag flag) Toggles a world flag in a combined bitmask.
-
Method Details
-
addFlag
public static long addFlag(long... flags) Combines multiple bitwise flags into a single value.Do not mix
PlayerFlag,WorldFlag, andControlFlagin the same operation as they use overlapping bit positions.- Parameters:
flags- the flags to combine- Returns:
- the combined bitmask
-
removeFlag
public static long removeFlag(long flags, long flag) Removes a flag from a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the flag to remove- Returns:
- the bitmask with the flag removed
-
isFlagSet
public static boolean isFlagSet(long flags, long flag) Checks if a specific flag is set in a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the flag to check- Returns:
- true if the flag is set, false otherwise
-
areAllFlagsSet
public static boolean areAllFlagsSet(long flags, long... requiredFlags) Checks if all specified flags are set in a combined bitmask.- Parameters:
flags- the combined bitmaskrequiredFlags- the flags that must all be present- Returns:
- true if all required flags are set
-
isAnyFlagSet
public static boolean isAnyFlagSet(long flags, long... flagsToCheck) Checks if any of the specified flags are set in a combined bitmask.- Parameters:
flags- the combined bitmaskflagsToCheck- the flags to check for- Returns:
- true if at least one flag is set
-
countFlagsSet
public static int countFlagsSet(long flags, long... flagsToCheck) Counts how many of the specified flags are set in a combined bitmask.- Parameters:
flags- the combined bitmaskflagsToCheck- the flags to count- Returns:
- the number of flags that are set
-
toggleFlag
public static long toggleFlag(long flags, long flag) Toggles a flag in a combined bitmask (adds if not present, removes if present).- Parameters:
flags- the combined bitmaskflag- the flag to toggle- Returns:
- the new bitmask with the flag toggled
-
removeFlags
public static long removeFlags(long flags, long... flagsToRemove) Returns a new bitmask with the specified flags removed.- Parameters:
flags- the combined bitmaskflagsToRemove- the flags to remove- Returns:
- the bitmask with flags removed
-
addFlag
Combines multiple player flags into a single bitmask.- Parameters:
flags- the player flags to combine- Returns:
- the combined bitmask
-
removeFlag
Removes a player flag from a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the player flag to remove- Returns:
- the bitmask with the flag removed
-
isFlagSet
Checks if a player flag is set in a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the player flag to check- Returns:
- true if the flag is set
-
areAllFlagsSet
Checks if all specified player flags are set.- Parameters:
flags- the combined bitmaskrequiredFlags- the player flags that must all be present- Returns:
- true if all are set
-
isAnyFlagSet
Checks if any of the specified player flags are set.- Parameters:
flags- the combined bitmaskflagsToCheck- the player flags to check- Returns:
- true if at least one is set
-
toggleFlag
Toggles a player flag in a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the player flag to toggle- Returns:
- the new bitmask
-
addFlag
Combines multiple world flags into a single bitmask.- Parameters:
flags- the world flags to combine- Returns:
- the combined bitmask
-
removeFlag
Removes a world flag from a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the world flag to remove- Returns:
- the bitmask with the flag removed
-
isFlagSet
Checks if a world flag is set in a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the world flag to check- Returns:
- true if the flag is set
-
areAllFlagsSet
Checks if all specified world flags are set.- Parameters:
flags- the combined bitmaskrequiredFlags- the world flags that must all be present- Returns:
- true if all are set
-
isAnyFlagSet
Checks if any of the specified world flags are set.- Parameters:
flags- the combined bitmaskflagsToCheck- the world flags to check- Returns:
- true if at least one is set
-
toggleFlag
Toggles a world flag in a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the world flag to toggle- Returns:
- the new bitmask
-
addFlag
Combines multiple control flags into a single bitmask.- Parameters:
flags- the control flags to combine- Returns:
- the combined bitmask
-
removeFlag
Removes a control flag from a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the control flag to remove- Returns:
- the bitmask with the flag removed
-
isFlagSet
Checks if a control flag is set in a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the control flag to check- Returns:
- true if the flag is set
-
areAllFlagsSet
Checks if all specified control flags are set.- Parameters:
flags- the combined bitmaskrequiredFlags- the control flags that must all be present- Returns:
- true if all are set
-
isAnyFlagSet
Checks if any of the specified control flags are set.- Parameters:
flags- the combined bitmaskflagsToCheck- the control flags to check- Returns:
- true if at least one is set
-
toggleFlag
Toggles a control flag in a combined bitmask.- Parameters:
flags- the combined bitmaskflag- the control flag to toggle- Returns:
- the new bitmask
-
toBitmask
Converts an array of PlayerFlags to a combined bitmask.- Parameters:
flags- the player flags- Returns:
- the combined bitmask
-
toBitmask
Converts an array of WorldFlags to a combined bitmask.- Parameters:
flags- the world flags- Returns:
- the combined bitmask
-
toBitmask
Converts an array of ControlFlags to a combined bitmask.- Parameters:
flags- the control flags- Returns:
- the combined bitmask
-
getSetPlayerFlags
Returns a list of PlayerFlag enums that are set in the given bitmask.- Parameters:
flags- the combined bitmask- Returns:
- list of set PlayerFlag enums
-
getSetWorldFlags
-
getSetControlFlags
Returns a list of ControlFlag enums that are set in the given bitmask.- Parameters:
flags- the combined bitmask- Returns:
- list of set ControlFlag enums
-
getUnsetPlayerFlags
Returns a list of PlayerFlag enums that are NOT set in the given bitmask.- Parameters:
flags- the combined bitmask- Returns:
- list of unset PlayerFlag enums
-
getUnsetWorldFlags
-
getUnsetControlFlags
Returns a list of ControlFlag enums that are NOT set in the given bitmask.- Parameters:
flags- the combined bitmask- Returns:
- list of unset ControlFlag enums
-