Extra Data Parameter / Rollback Event
Slazmaz opened this issue ยท 3 comments
I'm looking to add an extraData parameter to the API logging methods. Such a parameter is already used for storing the mob type of a spawner; I wish to expand that to accept multiple values. To accommodate this I will also want to add an event for rollbacks in order to obtain the data.
This will be to support plugins that store data in blocks and require that data to be retained upon rollback. In my case specifically I stack spawners (one spawner block can contain multiple spawners), but as things are now that data would be lost upon rollback. E.g. breaking a spawner block that contains 5 spawners and then rollbacking it, then it would no longer have the data that lets it act as 5 spawners.
Would this contribution be approved?
Can you please provide an example of the exact type of extra data you'd like logged? (In code)
Also note that magic values are deprecated, and logging data values is no longer supported by the CoreProtect API.
I think storing a string would prove most versatile, of course in my particular case I only need to store a single integer.
@EventHandler
void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if (block.getType() !== Material.SPAWNER) return;
String name = event.getPlayer().getName();
Location location = block.getLocation();
BlockData blockData = block.getBlockData();
Integer spawnCount = block.getState().getSpawnCount(); // <--- This is what I need stored
// logRemoval(String user, Location location, Material type, BlockData blockData, String extraData)
api.logRemoval(name, location, Material.SPAWNER, blockData, spawnCount.toString());
}
Then, upon a rollback I would need to listen to something like this
@EventHandler
void onBlockRollBack(CoreProtectBlockRollbackEvent event) {
Block block = event.getBlock();
if (block.getType() !== Material.SPAWNER || !event.getExtraData()) return;
String extraData = event.getExtraData();
int spawnCount = Integer.parseInt(extraData);
if (!spawnCount) return;
CreatureSpawner spawner = block.getState();
spawner.setSpawnCount(spawnCount);
spawner.update();
}