v1.3.1: NBT preservation, GUI previews, and global placement toggle
This commit is contained in:
59
oyeOwner/src/main/java/party/cybsec/OyeOwnerAPI.java
Normal file
59
oyeOwner/src/main/java/party/cybsec/OyeOwnerAPI.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package party.cybsec;
|
||||
|
||||
import net.coreprotect.CoreProtectAPI;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class OyeOwnerAPI {
|
||||
|
||||
private final OyeOwner plugin;
|
||||
|
||||
public OyeOwnerAPI(OyeOwner plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the owner (player who placed) of a block.
|
||||
* Searches back 60 days.
|
||||
*
|
||||
* @param block The block to check.
|
||||
* @return The username of the player who placed the block, or null if not
|
||||
* found/error.
|
||||
*/
|
||||
public String getBlockOwner(Block block) {
|
||||
CoreProtectAPI api = plugin.getCoreProtectHook().getCoreProtect();
|
||||
if (api == null || block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 60 days in seconds
|
||||
int time = 60 * 24 * 60 * 60;
|
||||
|
||||
List<String[]> lookup = api.blockLookup(block, time);
|
||||
if (lookup == null || lookup.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (String[] result : lookup) {
|
||||
CoreProtectAPI.ParseResult parsed = api.parseResult(result);
|
||||
// Action ID 1 is "Placement"
|
||||
if (parsed.getActionId() == 1) {
|
||||
return parsed.getPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the owner of a block asynchronously.
|
||||
*
|
||||
* @param block The block to check.
|
||||
* @return A CompletableFuture containing the username or null.
|
||||
*/
|
||||
public CompletableFuture<String> getBlockOwnerAsync(Block block) {
|
||||
return CompletableFuture.supplyAsync(() -> getBlockOwner(block));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user