mirror of
https://github.com/NamelessMC/Nameless
synced 2026-08-18 06:29:04 -04:00
36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
|
|
class SyncMinecraftGroupsEndpoint extends KeyAuthEndpoint {
|
|
|
|
public function __construct() {
|
|
$this->_route = 'minecraft/{user}/sync-groups';
|
|
$this->_module = 'Core';
|
|
$this->_description = 'Update a users groups based on added or removed groups from the Minecraft server';
|
|
$this->_method = 'POST';
|
|
}
|
|
|
|
public function execute(Nameless2API $api, User $user): void {
|
|
$api->validateParams($_POST, ['server_id']);
|
|
|
|
$server_id = $_POST['server_id'];
|
|
$integration = Integrations::getInstance()->getIntegration('Minecraft');
|
|
|
|
if (!$integration || $server_id != Settings::get('group_sync_mc_server')) {
|
|
$api->returnArray(['message' => $api->getLanguage()->get('api', 'groups_updates_ignored')]);
|
|
}
|
|
|
|
$log = GroupSyncManager::getInstance()->broadcastGroupChange(
|
|
$user,
|
|
MinecraftGroupSyncInjector::class,
|
|
$_POST['add'] ?? [],
|
|
$_POST['remove'] ?? [],
|
|
);
|
|
|
|
Log::getInstance()->log(Log::Action('mc_group_sync/role_set'), json_encode($log), $user->data()->id);
|
|
|
|
$api->returnArray([
|
|
'message' => $api->getLanguage()->get('api', 'groups_updates_successfully'),
|
|
'log' => $log,
|
|
]);
|
|
}
|
|
}
|