Developer API/Flag Class

Working with Flags

Retrieving Flags

To make our flags actually useful we need to write an event handler to manage it's effects. In order to do that, we need to be able to retrieve the flag state. But first we need to know how to read information from the users about your newly created flag. You may have simply stored the object returned by register method above, but if you did not we can get an instance of the flag if we remember the name using the registrar.

Example:

Registrar flagsRegistrar = FlagsAPI.getRegistrar();
Flag myFlag = flagsRegistrar.getFlag(myFlagName);

//This one is significantly less efficient.
//Use it sparingly, preferably not in rapid events.
Flag myFlag = flagsRegistrar.getFlagIgnoreCase(myFlagName);

Permissions

Now that we have a flag we can retrieve all the information we gave it when it was registered (name, group, description, etc), we can also retrieve permissions that have been automatically assigned to the flag.

Example:

Permission perm = myFlag.getPermission();

There is no need to test the wildcard permissions directly, it is automatic. These permissions govern setting and removing flags, however what will be more useful to your event handler is determining bypass permissions (players that are allowed to ignore the flag's effects). The same utility method exists for bypass permissions. It is up to you to implement the Bypass permission, Flags does not use it at all!

Example:

Permission bperm = myFlag.getBypassPermission();

Prices

We can also see if the user has set a price for players to buy the flag or message and even alter that price of the flag or message.

Example:

double flagPrice = myFlag.getPrice(EconomyPurchaseType.FLAG);
myFlag.setPrice(EconomyPurchaseType.FLAG, 100.0);

double flagMessagePrice = myFlag.getPrice(EconomyPurchaseType.MESSAGE);
myFlag.setPrice(EconomyPurchaseType.MESSAGE, 100.0);

Comments

Posts Quoted:
Reply
Clear All Quotes