1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Pterodactyl - Panel |
4
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in all |
14
|
|
|
* copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Pterodactyl\Observers; |
26
|
|
|
|
27
|
|
|
use Pterodactyl\Events; |
28
|
|
|
use Pterodactyl\Models\Subuser; |
29
|
|
|
use Pterodactyl\Notifications\AddedToServer; |
30
|
|
|
use Pterodactyl\Notifications\RemovedFromServer; |
31
|
|
|
|
32
|
|
|
class SubuserObserver |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Listen to the Subuser creating event. |
36
|
|
|
* |
37
|
|
|
* @param \Pterodactyl\Models\Subuser $subuser |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function creating(Subuser $subuser) |
41
|
|
|
{ |
42
|
|
|
event(new Events\Subuser\Creating($subuser)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Listen to the Subuser created event. |
47
|
|
|
* |
48
|
|
|
* @param \Pterodactyl\Models\Subuser $subuser |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function created(Subuser $subuser) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
event(new Events\Subuser\Created($subuser)); |
54
|
|
|
|
55
|
|
|
$subuser->user->notify((new AddedToServer([ |
56
|
|
|
'user' => $subuser->user->name_first, |
57
|
|
|
'name' => $subuser->server->name, |
58
|
|
|
'uuidShort' => $subuser->server->uuidShort, |
59
|
|
|
]))); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Listen to the Subuser deleting event. |
64
|
|
|
* |
65
|
|
|
* @param \Pterodactyl\Models\Subuser $subuser |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function deleting(Subuser $subuser) |
69
|
|
|
{ |
70
|
|
|
event(new Events\Subuser\Deleting($subuser)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Listen to the Subuser deleted event. |
75
|
|
|
* |
76
|
|
|
* @param \Pterodactyl\Models\Subuser $subuser |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function deleted(Subuser $subuser) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
event(new Events\Subuser\Deleted($subuser)); |
82
|
|
|
|
83
|
|
|
$subuser->user->notify((new RemovedFromServer([ |
84
|
|
|
'user' => $subuser->user->name_first, |
85
|
|
|
'name' => $subuser->server->name, |
86
|
|
|
]))); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.