# ServerUserEvent events

> 3 FeatherPanel plugin events on ServerUserEvent (1 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/server-user/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions. 2 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `ServerUserEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\ServerUserEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ServerUserEvent::onServerUserUpdated(), function ($userUuid, $serverUuid): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:updated ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `ServerUserEvent::onServerUserDeleted()`

- Name: `featherpanel:user:server:deleted`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerUserEvent.php#L36)

Docblock: string server uuid.

```php
$event->on(ServerUserEvent::onServerUserDeleted(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:deleted ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `ServerUserEvent::onServerUserError()`

- Name: `featherpanel:user:server:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerUserEvent.php#L45)

Docblock: string error message, array context.

```php
$event->on(ServerUserEvent::onServerUserError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:error ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `ServerUserEvent::onServerUserUpdated()`

- Name: `featherpanel:user:server:updated`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerUserEvent.php#L28)

Docblock: string server uuid, array updated data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `server_uuid` | `$serverUuid` | `array`from docblock |

When it fires (1 site)

-   [`ServerUserController::updateServer`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/ServerUserController.php#L1704)[`PUT /api/user/servers/{uuidShort}`](https://featherpanel.com/docs/api/reference/user/server/core/#put-user-servers-uuidShort)

```php
$event->on(ServerUserEvent::onServerUserUpdated(), function ($userUuid, $serverUuid): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:updated ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid]));
});
```
