Developer API

Developer API

Working with Flags

All operations with flags are handled through the Flag class. In the flag class there is a Type enumeration which will be used to determine the flag type to work with. To start, create an instance of the Flag class and set the type of flag. This can be done in one of three ways.

//Creating a Flag instance declaring the type
Flag flag1 = new Flag(Type.Pvp);

//Creating a Flag instance setting the type at a later time.
Flag flag2 = new Flag(); // Defaults to Type.AllowEntry
flag2.setType(Type.NotifyExit);

//Creating a Flag instance setting the type using a String.
Flag flag3 = new Flag(); // Defaults to Type.AllowEntry
boolean success = flag3.setType("spawnmob");

Once you have created the flag instance and set it's type, it's operations become available to you using the Bukkit Player class and the Grief Prevention Claim class.

// Retrieve the previously set type
Type flagtype = flag.getType();

// Retrieve the current global value for the flag type
// (null if not set)
Boolean value = flag.getValue(world);

// Retrieve the value of the current flag for the specified claim
// (null if not set)
Boolean value = flag.getValue(claim);

// Retrieve the current unclaimed value for the flag type (null if not set)
Boolean value = flag.getUnclaimedValue(world);

// Retrieve the effective value of the flag for the claim
// If the claim flag has not been set, global will be returned
// If global has not been set the plug-in default is returned.
boolean value = flag.isAllowed(claim);

// Retrieve the effective value of the flag for the world
// The global will be returned.
// If global has not been set the plug-in default is returned.
boolean value = flag.isAllowed(world);

// Retrieve the effective value of the flag for 
// the unclaimed area of the world
// If unclaimed flag has not been set the
// plug-in default is returned.
boolean value = flag.isUnclaimedAllowed(world);

// Change the value of a global flag
flag.setValue(world, true, null);

// Change the value of a claim flag
flag.setValue(claim, true, null)

// Change the value of a unclaimed flag
flag.setUnclaimedValue(world, true, null);;

// Return the flag's global value to the default.
flag.removeValue(world, null);

//Return the flag's claim value to use the global or default.
flag.removeValue(claim, null);

// Return the flag's unclaimed value to the default.
flag.removeUnclaimedValue(world, null);

// Change the value of a flag and tell the resulting event who did it.
// Works using either Player or CommandSender for all 
// setValue and removeValue overloads.
// Player may be null, but should be provided when available.
flag.setValue(claim, true, player);

// Find out if a player has permission to set this flag.
// Both hasPermission and hasBypassPermission
// automatically handle isOp(), gpflags.*, and either
// gpflags.flags.* or gpflags.bypass.*
boolean perm = flag.hasPermission(player);

// Find out if a player has permission to ignore the flag's effect.
// Note that although GriefPreventionFlags may not use them,
// All flags have a bypass permission that can be set, and
// used by 3rd party plug-ins.
boolean perm = flag.hasBypassPermission(claim, player);

// Get the customizable message associated with the flag.
// If the message has not been set, the flags.yml message is returned.
// Note that although GriefPreventionFlags may not use them,
// All flags have a customizable message that can be set, and
// used by 3rd party plug-ins.
// All string instances of "<0>" should be replaced by the player 
// who's actions invoked the request for the message.
// Instances of "<1>" will be replaced for you with the claim owner name
// automatically by the plugin.
String message = flag.getMessage(claim);

// Set the message 
// Player may be null, but should be provided when available,
// it is used to tell the event who made the change.
flag.setMessage(claim, "Hello!", player);

// Remove the message
// Player may be null, but should be provided when available,
// it is used to tell the event who made the change.
flag.removeMessage(claim, player);

// Get the trust list for the flag.
// Note that although GriefPreventionFlags may not use them,
// All flags have a trust that can be set, and
// used by 3rd party plug-ins.
// There is no global trust list, bypass permissions are used instead
List<String> trustList = flag.getTrustList(claim);

// Add a trustee to the list
// Trustee is a string, there is no player verification.
// You can add a string even if a player with that name
// has never logged into the server.
// Player should be provided for the event, but may be null.
flag.setTrust(claim, trustee, player);

// Remove a trustee from the list
// Player should be provided for the event, but may be null.
flag.removeTrust(claim, trustee, player);

Working with Flag Types

The flag type enumeration has abilities of it's own:

// Get the fixed name of the flag type
String name = Type.Pvp.getName();

// Get a localized name for the flag type.
String name = Type.Pvp.getLocalName();

// Get a localized description of the flag type
String desc = Type.Pvp.getDescription();

// Get the permission node of the flag type
// i.e. gpflags.flags.pvp
String perm = Type.Pvp.getFlagPermission();

// Get the bypass permission node of the flag type
String perm = Type.Pvp.getBypassPermission();

//Get the plug-in default value for the flag type.
boolean def = Type.Pvp.getDefault();

// Get the localized flag message
String message = Type.AllowEntry.getMessage();

Clusters

You can use the Cluster class to retrieve information about clusters.

// Find out if a cluster exists by the given name.
boolean exists = isCluster("notify");

// Get the flags in the cluster
List<String> cluster = getCluster("notify");

// Get a list of all cluster names defined
Set<String> clusters = getClusterNames();

Claim Manager

The ClaimManager class contains a set of utility functions for retrieving claim information

// Find out if a claim exists at a specified Bukkit Location
boolean exists = isClaimAtLocation(location);

// Get the claim at a specified Bukkit Location.
Claim claim = getClaimAtLocation(location);

// Find out if a user has permission to set flags at a location 
// This is flag type independent, does not check global.
// (gpflags.setflag.others, gpflags.setflag.admin, etc.)
boolean permission = hasPermission(claim, player);

// Find out if a user has permission to set clusters at a location 
// This is cluster type independent, does not check global.
// (gpflags.setcluster.others, gpflags.setcluster.admin, etc.)
boolean permission = hasClusterPermission(claim, player);

// Retrieve a set of all flags set for the claim
Set<String> claimFlags = getFlags(claim, true)

// Retrieve a set of all flags that have a value that differs from
// the default value (i.e. alters Minecraft behavior)
Set<String> claimFlags = getFlags(claim, false)

// This function has been left public due to the internal
// workings of the plug-in.  This function should not be used.
// In most cases, using this function would be malicious.
// It removes all data for the specified claim the GPFlag data store.
// It has no event and logs only to the console.
// This may be removed in the future.
removeClaim(claim);

Messages

You may retrieve the localized (non-flag) messages the plugin uses from the Messages enumeration. Placeholders <#> will not be replaced with their dynamic content for you.

String message = Messages.NoClaimError.get();

Events

The following events are available:

FlagDeleteEvent - Event that occurs before flag is explicitly removed. Does not fire if a flag is merely turned off. Can occur even if there is nothing to remove.

FlagSetEvent - Event that occurs before a flag value is changed. This does not fire if a flag is removed, however it does fire if an attempt is made to change a flag to the same value that it already is.

GlobalFlagDeleteEvent - Same as FlagDeleteEvent for global flags.

GlobalFlagSetEvent - Same as FlagSetEvent for global flags.

UnclaimedFlagDeleteEvent - Same as FlagDeleteEvent for unclaimed flags.

UnclaimedFlagSetEvent - Same as FlagSetEvent for unclaimed flags

TrustChangedEvent - Event that occurs before a player is added or removed from a trust list.

MessageChangedEvent - Event that occurs before a custom message is set, changed, or removed from a flag. Can occur even if there is nothing to remove or the message being set is the same as the message already set.

PlayerEnterClaimEvent - Event that occurs before a player crosses the border of a claim to enter it.

PlayerLeaveClaimEvent - Event that occurs before a player crosses the border of a claim to exit it.