• Forums

Navigation

  • Home
  • Style Guide
  • Getting Started
    • Home
    • Structuring Your Mod
    • Forge Update Checker
    • Dependency Management
    • Debug Profiler
  • Concepts
    • Sides
    • Resources
    • Registries
    • The Fingerprint Violation Event
    • Internationalization and localization
  • Blocks
    • Home
    • Intro to Blockstates
    • Interaction
  • Animation API
    • Intro to the Animation API
    • Armatures
    • Animation State Machines
    • Using the API
  • Tile Entities
    • Home
    • Special Renderer
  • Items
    • Home
    • Loot Tables
  • Models
    • Intro to Models
    • Model Files
    • Blockstates
      • Intro to Blockstate JSONs
      • Forge Blockstate JSON
    • Connecting Blocks and Items to Models
    • Coloring Textures
    • Item Property Overrides
    • Advanced Models
      • Intro to Advanced Models
      • IModel
      • IModelState and IModelPart
      • IBakedModel
      • Extended Blockstates
      • Perspective
      • ItemOverrideList
      • ICustomModelLoader
  • Rendering
    • TileEntityItemStackRenderer
  • Events
    • Basic Usage
  • Networking
    • Home
    • Overview
    • SimpleImpl
    • Entities
  • Data Storage
    • Capabilities
    • World Saved Data
    • Extended Entity Properties
    • Config Annotations
  • Utilities
    • Recipes
    • OreDictionary
    • PermissionAPI
      • How to use the PermissionAPI
      • DefaultPermissionLevel
      • Permission node
      • Making your own implementation of the PermissionHandler
  • Effects
    • Sounds
  • Conventions
    • Versioning
    • Locations
    • Loading Stages
  • Contributing to Forge
    • Getting Started
    • PR Guidelines

PermissionAPI

The PermissionAPI is a very basic implementation of a permission system. Its default implementation doesn’t add an advanced permission handling (like we know it for example from PEX), but instead it has 3 permission levels, (ALL = all players, OP = operators, NONE = neither normal players nor operators). This behaviour can be changed by mods which implement their own PermissionHandler.

How to use the PermissionAPI

For basic support you just need to call PermissionAPI.hasPermission(EntityPlayer player, String node), though by default this is going to return always false, as the default implementation uses the permission level NONE So if we want that all players, or just OP’s to be able to use this we also need to register our permission node. Achieving this is as simple as checking for permissions: PermissionAPI.registerNode(String node, DefaultPermissionLevel level, String description), though this has to be done in Init or Later.

Note

The PermissionAPI isn’t restricted to be used for commands, you could also use it for other things, like restricting access to a GUI.

Also, you need to check if your ICommandSender is a player if you use it in combination with commands!

DefaultPermissionLevel

The DefaultPermissionLevel has 3 Values: * ALL =all players got this permission * OP = only operators got this permission * NONE = neither normal players nor operators got this permission

Permission node

While there are technically no rules for the permission nodes, the best practice is to be of the form modid.subgroup.permission_id It is recommended to use this naming scheme as other implementations may have stricter rules.

Making your own implementation of the PermissionHandler

By default the PermissionHandler is very basic, which is usually enough for most users, but you might want more control over the permissions for things like a big server. This can be achieved by creating a custom PermissionHandler.

How it works and what is capable of, is totally up to you, for example you could make a simple implementation just saving a file per player. Or you could make it as advanced as PEX, having database support and many other functions.

Note

Not every mod that wants to use the PermissionAPI should change the PermissionHandler as there can be only 1 at the same time!

First off, how you implement your own PermissionHandler is completely up to you, you can use files, a database or whatever you want. All you need to do is create your own implementation of the interface IPermissionHandler. After that is done, you also need to register it using: PermissionAPI.setPermissionHandler(IPermissionHandler handler)

Note

You’ve got to set the Handler during PreInit! It is also recommended to check if it wasn’t already replaced by another mod.

Built with MkDocs using a custom theme. Hosted by Read the Docs.
Enable Dark Theme