API Version 12
The CoreProtect API enables you to log your own block changes, perform lookups, rollbacks, restores, and more.
| API Details | |
|---|---|
| API Version: | 12 |
| Plugin Version: | v24.0+ |
| Maven: | maven.playpro.com |
Upgrading from API v11
The changes from the previous API version are as follows:
- The following event was extended to include immutable action metadata:
CoreProtectPreLogEvent(String user, Location location, CoreProtectPreLogEvent.Action action, int actionId, Material material, EntityType entityType, String message)
- The older constructors remain for backward compatibility:
@Deprecated
CoreProtectPreLogEvent(String user)
CoreProtectPreLogEvent(String user, Location location)
- Added typed block lookup methods:
List<BlockResult> blockLookup(Block block, LookupOptions options)
- Added
BlockResultfor reading block lookup data without parsingString[]lookup rows. - Added typed container lookup methods:
List<ContainerResult> containerLookup(Location location, int time)
List<ContainerResult> containerLookup(LookupOptions options)
- Added
ContainerResultfor reading container transaction data without parsingString[]lookup rows. - Added typed item lookup methods:
List<ItemResult> itemLookup(LookupOptions options)
- Added
ItemResultfor reading world item transaction data without parsingString[]lookup rows. - Added typed inventory lookup methods:
List<InventoryResult> inventoryLookup(LookupOptions options)
- Added
InventoryResultfor reading player inventory transaction data without parsingString[]lookup rows. - Added typed chat and command lookup methods:
List<MessageResult> chatLookup(String user, int time)
List<MessageResult> commandLookup(String user, int time)
- Added
MessageResultfor reading chat and command data without parsingString[]lookup rows. - Added typed sign lookup methods:
List<SignResult> signLookup(Location location, int time)
- Added
SignResultfor reading sign text data without parsingString[]lookup rows. - Added typed session lookup methods:
List<SessionResult> sessionLookup(LookupOptions options)
- Added
SessionResultfor reading login/logout session data without parsingString[]lookup rows. - Added typed username history lookup methods:
List<UsernameResult> usernameLookup(String user, int time)
List<UsernameResult> usernameLookup(LookupOptions options)
- Added
UsernameResultfor reading player username history without parsing command lookup rows. - Added shared typed API helpers:
LookupOptions
CoreProtectResult
CoreProtectAction
containerLookup,itemLookup,inventoryLookup,chatLookup,commandLookup,signLookup,sessionLookup, andusernameLookupnow supportLookupOptionsoverloads for shared user, time, location, radius, and limit options. Username history has no coordinates, so location and radius options are ignored.
Getting Started
Ensure you're using CoreProtect 24.0 or higher. Add it as an external jar to your plugin in your IDE. Alternatively, if using Maven, you can add it via the repository https://maven.playpro.com (net.coreprotect, 24.0).
The first thing you need to do is get access to CoreProtect. You can do this by using code similar to the following:
import net.coreprotect.CoreProtect;
import net.coreprotect.CoreProtectAPI;
private CoreProtectAPI getCoreProtect() {
Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect");
// Check that CoreProtect is loaded
if (plugin == null || !(plugin instanceof CoreProtect)) {
return null;
}
// Check that the API is enabled
CoreProtectAPI CoreProtect = ((CoreProtect) plugin).getAPI();
if (CoreProtect.isEnabled() == false) {
return null;
}
// Check that a compatible version of the API is loaded
if (CoreProtect.APIVersion() < 12) {
return null;
}
return CoreProtect;
}
With this code, you can then access the API with a call like the following:
CoreProtectAPI api = getCoreProtect();
if (api != null){ // Ensure we have access to the API
api.testAPI(); // Will print out "[CoreProtect] API test successful." in the console.
}
Yay, you're now using the CoreProtect API!
API Overview
Available Methods
boolean isEnabled()
void testAPI()
List<String[]> performLookup(int time, List<String> restrict_users, List<String> exclude_users, List<Object> restrict_blocks, List<Object> exclude_blocks, List<Integer> action_list, int radius, Location radius_location)
List<String[]> performRollback(int time, List<String> restrict_users, List<String> exclude_users, List<Object> restrict_blocks, List<Object> exclude_blocks, List<Integer> action_list, int radius, Location radius_location)
List<String[]> performRestore(int time, List<String> restrict_users, List<String> exclude_users, List<Object> restrict_blocks, List<Object> exclude_blocks, List<Integer> action_list, int radius, Location radius_location)
List<String[]> blockLookup(Block block, int time)
List<BlockResult> blockLookup(Block block, LookupOptions options)
List<ContainerResult> containerLookup(Location location, int time)
List<ContainerResult> containerLookup(LookupOptions options)
List<ItemResult> itemLookup(LookupOptions options)
List<InventoryResult> inventoryLookup(LookupOptions options)
List<MessageResult> chatLookup(String user, int time)
List<MessageResult> chatLookup(LookupOptions options)
List<MessageResult> commandLookup(String user, int time)
List<MessageResult> commandLookup(LookupOptions options)
List<SignResult> signLookup(Location location, int time)
List<SignResult> signLookup(LookupOptions options)
List<String[]> sessionLookup(String user, int time)
List<SessionResult> sessionLookup(LookupOptions options)
List<UsernameResult> usernameLookup(String user, int time)
List<UsernameResult> usernameLookup(LookupOptions options)
List<String[]> queueLookup(Block block)
ParseResult parseResult(String[] result)
boolean logChat(Player player, String message)
boolean logCommand(Player player, String command)
boolean logPlacement(String user, BlockState blockState)
boolean logPlacement(String user, Location location, Material type, BlockData blockData)
boolean logRemoval(String user, BlockState blockState)
boolean logRemoval(String user, Location location, Material type, BlockData blockData)
boolean logContainerTransaction(String user, Location location)
boolean logInteraction(String user, Location location)
boolean hasPlaced(String user, Block block, int time, int offset)
boolean hasRemoved(String user, Block block, int time, int offset)
void performPurge(int time)
Available Events
The following events are emitted by CoreProtect.
CoreProtectPreLogEvent
Fired when a CoreProtect logger is about to log an action. Cancellable.
| Property | Description | Mutable |
|---|---|---|
| User | The name of the user under which this action will be logged. | Yes |
| Location | The location where the action will be logged. | Yes |
| Action | The type of CoreProtect action being logged. | No |
| Action ID | The underlying action value for loggers that store one, otherwise -1. |
No |
| Material | The material being logged, when applicable. | No |
| Entity Type | The entity type being logged, when applicable. | No |
| Message | The message being logged, when applicable. | No |
| Cancelled | If cancelled, the action won't be logged to the database. | Yes |
Method Usage
Detailed method information is listed below.
Shared typed API helpers
LookupOptions can be used with typed lookup methods that support shared filters.
LookupOptions options = LookupOptions.builder()
.user("Notch")
.time(60)
.radius(location, 5)
.limit(0, 100)
.build();
- user(String user): Specify the username to perform the lookup on. Use
nullor#globalto search all users. - time(int time): Specify the amount of time to lookup in seconds.
- location(Location location): Search an exact location.
- radius(Location location, int radius): Search around a location in the X/Z plane. Use
0for the exact location. - limit(int offset, int count): Limit the returned result range.
BlockResult, ContainerResult, InventoryResult, ItemResult, MessageResult, SessionResult, SignResult, UsernameResult, and ParseResult implement CoreProtectResult, which provides shared access to player, timestamp, coordinates, world, and action data.
CoreProtectAction provides named constants for lookup filter action IDs while retaining integer action IDs for backward compatibility.
isEnabled()
Calling this will return true if the server has the CoreProtect API enabled, and false if it does not.
testAPI()
Running this will print out "[CoreProtect] API Test Successful." in the server console.
performLookup(int time, List<String> restrict_users, List<String> exclude_users, List<Object> restrict_blocks, List<Object> exclude_blocks, List<Integer> action_list, int radius, Location radius_location)
This will perform a lookup.
- time: Specify the amount of time to search back. "5" would return results from the last 5 seconds.
- restrict_users: Specify any usernames to perform the lookup on. Can be set to "null" if both a radius and a location are specified.
- exclude_users: Specify any usernames to exclude from the lookup. Can be set to "null".
- restrict_blocks: Specify a list of EntityType's or Material's to restrict the search to. Can be set to "null".
- exclude_blocks: Specify a list of EntityType's or Material's to exclude from the search. Can be set to "null".
- action_list: Specify a list of action types to restrict the search to. Can be set to "null"
- radius: Specify a radius to restrict the search to. A location must be specified if using this. Set to "0" to disable.
- radius_location: Specify a location to search around. Can be set to "null" if no radius is specified, and a user is specified.
performRollback(int time, List<String> restrict_users, List<String> exclude_users, List<Object> restrict_blocks, List<Object> exclude_blocks, List<Integer> action_list, int radius, Location radius_location)
This will perform a rollback. Method must be called async.
- time: Specify the amount of time to rollback. "5" would return results from the last 5 seconds.
- restrict_users: Specify any usernames to perform the rollback on. Can be set to "null" if both a radius and a location are specified.
- exclude_users: Specify any usernames to exclude from the rollback. Can be set to "null".
- restrict_blocks: Specify a list of EntityType's or Material's to restrict the rollback to. Can be set to "null".
- exclude_blocks: Specify a list of EntityType's or Material's to exclude from the rollback. Can be set to "null".
- action_list: Specify a list of action types to restrict the rollback to. Can be set to "null"
- radius: Specify a radius to restrict the rollback to. A location must be specified if using this. Set to "0" to disable.
- radius_location: Specify a location to rollback around. Can be set to "null" if no radius is specified, and a user is specified.
performRestore(int time, List<String> restrict_users, List<String> exclude_users, List<Object> restrict_blocks, List<Object> exclude_blocks, List<Integer> action_list, int radius, Location radius_location)
This will perform a restore.
- time: Specify the amount of time to restore. "5" would return results from the last 5 seconds.
- restrict_users: Specify any usernames to perform the restore on. Can be set to "null" if both a radius and a location are specified.
- exclude_users: Specify any usernames to exclude from the restore. Can be set to "null".
- restrict_blocks: Specify a list of EntityType's or Material's to restrict the restore to. Can be set to "null".
- exclude_blocks: Specify a list of EntityType's or Material's to exclude from the restore. Can be set to "null".
- action_list: Specify a list of action types to restrict the restore to. Can be set to "null"
- radius: Specify a radius to restrict the restore to. A location must be specified if using this. Set to "0" to disable.
- radius_location: Specify a location to restore around. Can be set to "null" if no radius is specified, and a user is specified.
blockLookup(Block block, int time)
This will perform a full lookup on a single block.
- block: The block to perform the lookup on.
- time: Specify the amount of time to lookup. "5" would return results from the last 5 seconds.
blockLookup(Block block, LookupOptions options)
This will perform a typed lookup on a single block.
- block: The block to perform the lookup on.
- options: Specify user, time, and limit filters using
LookupOptions. Location and radius options are ignored because the block supplies the exact lookup location.
BlockResult provides the following methods:
- getX(): Get the X coordinate of the block.
- getY(): Get the Y coordinate of the block.
- getZ(): Get the Z coordinate of the block.
- getType(): Get the Material of the block.
- getBlockData(): Get the BlockData of the block.
- getData(): Get the legacy data value.
- getPlayer(): Get the username as a string.
- getTimestamp(): Get the time of the action.
- getActionId(): Get the action ID. (0=removed, 1=placed, 2=interaction)
- getActionString(): Get the action as a string. (break, place, click)
- isRolledBack(): If the block is currently rolled back or not.
- worldName(): The name of the world the block is located in.
containerLookup(Location location, int time)
This will perform a container transaction lookup at a single location.
- location: The location to perform the lookup on.
- time: Specify the amount of time to lookup. "5" would return results from the last 5 seconds.
containerLookup(LookupOptions options)
This will perform a container transaction lookup using shared lookup options.
- options: Specify user, time, location, radius, and limit options.
Both container lookup methods return ContainerResult entries with typed access to the following:
- getX(): Get the X coordinate of the container.
- getY(): Get the Y coordinate of the container.
- getZ(): Get the Z coordinate of the container.
- getType(): Get the Material of the item.
- getData(): Get the item data value.
- getAmount(): Get the item amount.
- getMetadata(): Get a copy of the raw item metadata.
- getPlayer(): Get the username as a string.
- getTimestamp(): Get the time of the transaction.
- getActionId(): Get the action ID. (0=removed, 1=added)
- getActionString(): Get the action as a string. (remove, add)
- isRolledBack(): If the transaction is currently rolled back or not.
- worldName(): The name of the world the container is located in.
itemLookup(LookupOptions options)
This will perform a typed world item transaction lookup, similar to running /co lookup a:item. This returns world item transactions such as drops and pickups. Use inventoryLookup(LookupOptions) for player inventory transactions.
- options: Specify user, time, location, radius, and limit options.
ItemResult provides the following methods:
- getX(): Get the X coordinate of the item transaction.
- getY(): Get the Y coordinate of the item transaction.
- getZ(): Get the Z coordinate of the item transaction.
- getType(): Get the Material of the item.
- getAmount(): Get the item amount.
- getMetadata(): Get a copy of the raw item metadata.
- getPlayer(): Get the username as a string.
- getTimestamp(): Get the time of the transaction.
- getActionId(): Get the item transaction action ID.
- getActionString(): Get the item action as a string. (remove, add, drop, pickup, withdraw, deposit, throw, shoot)
- isRolledBack(): If the transaction is currently rolled back or not.
- worldName(): The name of the world where the item transaction occurred.
inventoryLookup(LookupOptions options)
This will perform a typed player inventory transaction lookup, similar to running /co lookup a:inventory. Inventory lookup can include block, container, and world item transaction sources, normalized around whether the item was added to or removed from the player's inventory.
- options: Specify user, time, location, radius, and limit options.
InventoryResult provides the following methods:
- getX(): Get the X coordinate of the inventory transaction.
- getY(): Get the Y coordinate of the inventory transaction.
- getZ(): Get the Z coordinate of the inventory transaction.
- getType(): Get the Material of the item.
- getData(): Get the legacy item data value.
- getAmount(): Get the item amount.
- getMetadata(): Get a copy of the raw item metadata.
- getPlayer(): Get the username as a string.
- getTimestamp(): Get the time of the transaction.
- getActionId(): Get the normalized inventory action ID. (0=removed from inventory, 1=added to inventory)
- getActionString(): Get the normalized inventory action as a string. (remove, add)
- getTransactionActionId(): Get the underlying transaction action ID.
- getTransactionActionString(): Get the underlying transaction action as a string. (remove, add, drop, pickup, withdraw, deposit, throw, shoot, break, destroy, create, sell, buy)
- getSourceId(): Get the source table ID. (0=block, 1=container, 2=item)
- getSource(): Get the source as a string. (block, container, item)
- isRolledBack(): If the transaction is currently rolled back or not.
- worldName(): The name of the world where the inventory transaction occurred.
chatLookup(String user, int time)
This will perform a chat message lookup for a user. Use null or #global to search all users.
- user: The username to perform the lookup on.
- time: Specify the amount of time to lookup. "5" would return results from the last 5 seconds.
chatLookup(LookupOptions options)
This will perform a chat message lookup using shared lookup options.
- options: Specify user, time, location, radius, and limit options.
commandLookup(String user, int time)
This will perform a command lookup for a user. Use null or #global to search all users.
- user: The username to perform the lookup on.
- time: Specify the amount of time to lookup. "5" would return results from the last 5 seconds.
commandLookup(LookupOptions options)
This will perform a command lookup using shared lookup options.
- options: Specify user, time, location, radius, and limit options.
All chat and command lookup methods return MessageResult entries with typed access to the following:
- getX(): Get the X coordinate of the message or command.
- getY(): Get the Y coordinate of the message or command.
- getZ(): Get the Z coordinate of the message or command.
- getMessage(): Get the message or command text.
- getPlayer(): Get the username as a string.
- getTimestamp(): Get the time of the message or command.
- getActionId(): Get the action ID. (6=chat, 7=command)
- getActionString(): Get the action as a string. (chat, command)
- worldName(): The name of the world where the message or command was logged.
signLookup(Location location, int time)
This will perform a sign text lookup at a single location.
- location: The location to perform the lookup on.
- time: Specify the amount of time to lookup. "5" would return results from the last 5 seconds.
signLookup(LookupOptions options)
This will perform a sign text lookup using shared lookup options.
- options: Specify user, time, location, radius, and limit options.
All sign lookup methods return SignResult entries with typed access to the following:
- getX(): Get the X coordinate of the sign.
- getY(): Get the Y coordinate of the sign.
- getZ(): Get the Z coordinate of the sign.
- getLine(int line): Get a sign line by zero-based line number.
- getLines(): Get a copy of all sign lines.
- getMessage(): Get the written sign side as a single string.
- getPlayer(): Get the username as a string.
- getTimestamp(): Get the time the sign text was logged.
- getActionId(): Get the action ID. (1=placed/written)
- getActionString(): Get the action as a string.
- getColor(): Get the front sign text color.
- getColorSecondary(): Get the back sign text color.
- getData(): Get the raw sign data value.
- isFront(): If the logged text is for the front side.
- isFrontGlowing(): If the front side is glowing.
- isBackGlowing(): If the back side is glowing.
- isWaxed(): If the sign is waxed.
- worldName(): The name of the world where the sign is located.
queueLookup(Block block)
This will search the consumer queue for changes on a block not yet saved in the database.
- block: The block to perform the lookup on.
sessionLookup(String user, int time)
This will perform a session lookup on a single player.
- user: The username to perform the lookup on.
- time: Specify the amount of time to lookup. "5" would return results from the last 5 seconds.
sessionLookup(LookupOptions options)
This will perform a typed session lookup.
- options: Specify user, time, location, radius, and limit filters using
LookupOptions.
SessionResult provides the following methods:
- getX(): Get the X coordinate of the session event.
- getY(): Get the Y coordinate of the session event.
- getZ(): Get the Z coordinate of the session event.
- getPlayer(): Get the username as a string.
- getTimestamp(): Get the time of the action.
- getActionId(): Get the action ID. (0=logout, 1=login)
- getActionString(): Get the action as a string. (logout, login)
- worldName(): The name of the world where the session event occurred.
usernameLookup(String user, int time)
This will perform a typed username history lookup. Use null or #global to search all users.
- user: The username or UUID to perform the lookup on. Historical usernames can also be used.
- time: Specify the amount of time to lookup. "5" would return results from the last 5 seconds.
usernameLookup(LookupOptions options)
This will perform a typed username history lookup.
- options: Specify user, time, and limit filters using
LookupOptions. Location and radius options are ignored because username history has no coordinates.
UsernameResult provides the following methods:
- getUsername(): Get the logged username used by the player UUID.
- getUuid(): Get the player UUID associated with the logged username.
- getPlayer(): Get the current known username for the UUID, or the logged username if no current name is cached.
- getTimestamp(): Get the time the username was logged.
- getActionId(): Get the action ID. (9=username)
- getActionString(): Get the action as a string. (username)
ParseResult parseResult(String[] result)
This will parse results from a lookup. You'll then be able to view the following:
- getX(): Get the X coordinate of the block.
- getY(): Get the Y coordinate of the block.
- getZ(): Get the Z coordinate of the block.
- getType(): Get the Material of the block.
- getBlockData(): Get the BlockData of the block.
- getPlayer(): Get the username as a string.
- getTimestamp(): Get the time of the action.
- getActionId(): Get the action ID. (0=removed, 1=placed, 2=interaction)
- getActionString(): Get the action as a string. (Removal, Placement, Interaction)
- isRolledBack(): If the block is currently rolled back or not.
- worldName(): The name of the world the block is located in.
logPlacement(String user, BlockState blockState)
This will log a block as being placed. (Thread safe)
- user: Specify the username to log as having placed the block.
- blockState: Specify the BlockState of the block you're logging.
logPlacement(String user, Location location, Material type, BlockData blockData)
This will log a block as being placed.
- user: Specify the username to log as having placed the block.
- location: Specify the location of the block you're logging.
- type: Specify the Material of the block you're logging.
- blockData: Specify the BlockData of the block you're logging. Can be set to "null".
logRemoval(String user, BlockState blockState)
This will log a block as being removed/broken. (Thread safe)
- user: Specify the username to log as having removed the block.
- blockState: Specify the BlockState of the block you're logging.
logRemoval(String user, Location location, Material type, BlockData blockData)
This will log a block as being removed/broken, and will log the block's inventory (if applicable).
- user: Specify the username to log as having removed the block.
- location: Specify the location of the block you're logging.
- type: Specify the Material of the block you're logging.
- blockData: Specify the BlockData of the block you're logging. Can be set to "null".
logContainerTransaction(String user, Location location)
This will log any transactions made to a block's inventory immediately after calling the method.
- user: Specify the username to log as having added/removed the items.
- location: Specify the location of the block inventory you're logging.
logInteraction(String user, Location location)
This will log a block as having been interacted with.
- user: Specify the username to log as having caused the interaction.
- location: Specify the location of the interaction you're logging.
hasPlaced(String user, Block block, int time, int offset)
This will return true if a user has already placed a block at the location within the specified time limit.
- user: The username you're checking to see if they've placed a block already.
- block: The block you're checking.
- time: How far back to check. "5" would only check through the last 5 seconds of logged blocks.
- offset: A time offset. "2" would ignore the last 2 seconds of most recently ignored data. (0 = no offset)
hasRemoved(String user, Block block, int time, int offset)
This will return true if a user has already removed a block at the location within the specified time limit.
- user: The username you're checking to see if they've removed a block already.
- block: The block you're checking.
- time: How far back to check. "5" would only check through the last 5 seconds of logged blocks.
- offset: A time offset. "2" would ignore the last 2 seconds of most recently ignored data. (0 = no offset)
performPurge(int time)
This will perform a purge on the CoreProtect database.
- time: Purge any data earlier than this. "120" would purge any data older than 120 seconds (2 minutes).
Examples
- Get the last 60 seconds of block data for the user "Notch".
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
List<String[]> lookup = CoreProtect.performLookup(60, Arrays.asList("Notch"), null, null, null, null, 0, null);
if (lookup != null){
for (String[] result : lookup){
ParseResult parseResult = CoreProtect.parseResult(result);
int x = parseResult.getX();
int y = parseResult.getY();
int z = parseResult.getZ();
// ...
}
}
}
- Get the last 60 seconds of block data for the user "Notch", excluding dirt and grass blocks.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
List<Object> exclude = Arrays.asList(Material.DIRT, Material.GRASS);
List<String[]> lookup = CoreProtect.performLookup(60, Arrays.asList("Notch"), null, null, exclude, null, 0, null);
if (lookup != null){
for (String[] value : lookup){
ParseResult result = CoreProtect.parseResult(value);
int x = result.getX();
int y = result.getY();
int z = result.getZ();
// ...
}
}
}
- Get the last 60 seconds of block data within 5 blocks of a location.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
List<String[]> lookup = CoreProtect.performLookup(60, null, null, null, null, null, 5, location);
if (lookup != null){
for (String[] value : lookup){
ParseResult result = CoreProtect.parseResult(value);
int x = result.getX();
int y = result.getY();
int z = result.getZ();
// ...
}
}
}
- Rollbacks / restores use the same code structure as the above examples. For example:
class BasicThread implements Runnable {
@Override
public void run() {
try {
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
List<String[]> lookup = CoreProtect.performRollback(60, Arrays.asList("Notch"), null, null, null, null, 0, null);
if (lookup != null){
for (String[] value : lookup){
ParseResult result = CoreProtect.parseResult(value);
int x = result.getX();
int y = result.getY();
int z = result.getZ();
// ...
}
}
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
thread.start();
- Check if the user "Notch" has already placed a block at a location within the last 60 seconds.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
boolean hasPlaced = CoreProtect.hasPlaced("Notch", block, 60, 0);
// Search queue for pending changes
if (!hasPlaced){
List<String[]> lookup = CoreProtect.queueLookup(block);
for (String[] result : lookup){
ParseResult parseResult = CoreProtect.parseResult(result);
if (parseResult.getActionId()==1 && parseResult.getPlayer().equals("Notch")){
hasPlaced = true;
break;
}
}
}
}
- Get the last 60 seconds of block data for a specific block.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
LookupOptions options = LookupOptions.builder()
.time(60)
.build();
List<BlockResult> lookup = CoreProtect.blockLookup(block, options);
if (lookup != null){
for (BlockResult result : lookup){
int x = result.getX();
int y = result.getY();
int z = result.getZ();
// ...
}
}
}
- Get the last 60 seconds of container transaction data for a specific location.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
List<ContainerResult> lookup = CoreProtect.containerLookup(location, 60);
if (lookup != null){
for (ContainerResult result : lookup){
int x = result.getX();
int y = result.getY();
int z = result.getZ();
Material type = result.getType();
int amount = result.getAmount();
// ...
}
}
}
- Get the last 60 seconds of container transaction data within 5 blocks of a location.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
LookupOptions options = LookupOptions.builder()
.time(60)
.radius(location, 5)
.build();
List<ContainerResult> lookup = CoreProtect.containerLookup(options);
if (lookup != null){
for (ContainerResult result : lookup){
int x = result.getX();
int y = result.getY();
int z = result.getZ();
Material type = result.getType();
int amount = result.getAmount();
// ...
}
}
}
- Get the last 60 seconds of item transactions within 5 blocks of a location.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
LookupOptions options = LookupOptions.builder()
.time(60)
.radius(location, 5)
.build();
List<ItemResult> lookup = CoreProtect.itemLookup(options);
if (lookup != null){
for (ItemResult result : lookup){
Material type = result.getType();
int amount = result.getAmount();
String action = result.getActionString();
// ...
}
}
}
- Get the last 60 seconds of player inventory transactions within 5 blocks of a location.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
LookupOptions options = LookupOptions.builder()
.time(60)
.radius(location, 5)
.build();
List<InventoryResult> lookup = CoreProtect.inventoryLookup(options);
if (lookup != null){
for (InventoryResult result : lookup){
Material type = result.getType();
int amount = result.getAmount();
String action = result.getActionString();
String source = result.getSource();
// ...
}
}
}
- Get the last 60 seconds of chat messages for the user "Notch".
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
List<MessageResult> lookup = CoreProtect.chatLookup("Notch", 60);
if (lookup != null){
for (MessageResult result : lookup){
String message = result.getMessage();
int x = result.getX();
int y = result.getY();
int z = result.getZ();
// ...
}
}
}
- Get the last 60 seconds of commands within 5 blocks of a location.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
LookupOptions options = LookupOptions.builder()
.time(60)
.radius(location, 5)
.build();
List<MessageResult> lookup = CoreProtect.commandLookup(options);
if (lookup != null){
for (MessageResult result : lookup){
String command = result.getMessage();
String player = result.getPlayer();
// ...
}
}
}
- Get the last 60 seconds of sign text at a specific location.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
List<SignResult> lookup = CoreProtect.signLookup(location, 60);
if (lookup != null){
for (SignResult result : lookup){
String message = result.getMessage();
String[] lines = result.getLines();
// ...
}
}
}
- Get the last 60 seconds of sign text written by the user "Notch" within 5 blocks of a location.
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
LookupOptions options = LookupOptions.builder()
.user("Notch")
.time(60)
.radius(location, 5)
.build();
List<SignResult> lookup = CoreProtect.signLookup(options);
if (lookup != null){
for (SignResult result : lookup){
int x = result.getX();
int y = result.getY();
int z = result.getZ();
// ...
}
}
}
- Get the last 1 day of session data for the user "Notch".
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
LookupOptions options = LookupOptions.builder()
.user("Notch")
.time(24 * 60 * 60)
.build();
List<SessionResult> lookup = CoreProtect.sessionLookup(options);
if (lookup != null){
for (SessionResult result : lookup){
int x = result.getX();
int y = result.getY();
int z = result.getZ();
int action = result.getActionId(); // 0 = logout, 1 = login
// ...
}
}
}
- Get the last 1 day of username history for the user "Notch".
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
List<UsernameResult> lookup = CoreProtect.usernameLookup("Notch", 24 * 60 * 60);
if (lookup != null){
for (UsernameResult result : lookup){
String username = result.getUsername();
String uuid = result.getUuid();
// ...
}
}
}
- Log the placement of a block at a location by the user "Notch".
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
boolean success = CoreProtect.logPlacement("Notch", block.getLocation(), block.getType(), block.getData());
}
- Log adding/remove items in a chest (or some other block inventory).
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
boolean success = CoreProtect.logContainerTransaction("Notch", inventory.getLocation());
// modify your container contents immediately after (e.g. [i]inventory.addItem(itemStack);[/i])
}
- Perform a multi-threaded placement check to see if the user "Notch" has already placed a block at a location within the last 60 seconds. This ignores the most recent 1 second of logged data, to account for the fact that that new block data may have already been logged, depending on your code.
final Block block = null; //Should be an actual block
class BasicThread implements Runnable {
@Override
public void run() {
try {
CoreProtectAPI CoreProtect = getCoreProtect();
if (CoreProtect != null){ // Ensure we have access to the API
boolean hasPlaced = CoreProtect.hasPlaced("Notch", block, 60, 1);
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
thread.start();