1
1
package com .eternalcode .check ;
2
2
3
+ import com .eternalcode .check .caller .EventCaller ;
4
+ import com .eternalcode .check .command .CommandConfiguration ;
3
5
import com .eternalcode .check .command .argument .CheckedUserArgument ;
4
6
import com .eternalcode .check .command .argument .PlayerArgument ;
7
+ import com .eternalcode .check .command .configurator .CommandConfigurator ;
8
+ import com .eternalcode .check .command .handler .NotificationHandler ;
5
9
import com .eternalcode .check .command .implementation .AdmitCommand ;
6
- import com .eternalcode .check .command .implementation .CheckCommand ;
7
- import com .eternalcode .check .command .message .InvalidUseMessage ;
8
- import com .eternalcode .check .command .message .PermissionMessage ;
10
+ import com .eternalcode .check .command .implementation .CheckBanCommand ;
11
+ import com .eternalcode .check .command .implementation .CheckEndCommand ;
12
+ import com .eternalcode .check .command .implementation .CheckReloadCommand ;
13
+ import com .eternalcode .check .command .implementation .CheckSetLocationCommand ;
14
+ import com .eternalcode .check .command .implementation .CheckStartCommand ;
15
+ import com .eternalcode .check .command .handler .InvalidUsageHandler ;
16
+ import com .eternalcode .check .command .handler .PermissionHandler ;
9
17
import com .eternalcode .check .config .ConfigManager ;
10
18
import com .eternalcode .check .config .implementation .CheckedUserDataConfig ;
11
19
import com .eternalcode .check .config .implementation .MessagesConfig ;
12
20
import com .eternalcode .check .config .implementation .PluginConfig ;
13
- import com .eternalcode .check .controller .CheckedUserChatController ;
14
- import com .eternalcode .check .controller .CheckedUserCommandController ;
15
- import com .eternalcode .check .controller .CheckedUserLogoutPunishmentController ;
16
- import com .eternalcode .check .controller .CheckedUserMoveController ;
21
+ import com .eternalcode .check .notification .Notification ;
22
+ import com .eternalcode .check .notification .NotificationAnnouncer ;
23
+ import com .eternalcode .check .updater .UpdaterNotificationController ;
24
+ import com .eternalcode .check .updater .UpdaterService ;
25
+ import com .eternalcode .check .user .controller .CheckedUserChatController ;
26
+ import com .eternalcode .check .user .controller .CheckedUserCommandController ;
27
+ import com .eternalcode .check .user .controller .CheckedUserLogoutPunishmentController ;
28
+ import com .eternalcode .check .user .controller .CheckedUserMoveController ;
17
29
import com .eternalcode .check .shared .legacy .LegacyColorProcessor ;
18
30
import com .eternalcode .check .user .CheckedUser ;
19
31
import com .eternalcode .check .user .CheckedUserService ;
20
32
import dev .rollczi .litecommands .LiteCommands ;
21
33
import dev .rollczi .litecommands .bukkit .LiteBukkitFactory ;
22
34
import dev .rollczi .litecommands .bukkit .tools .BukkitOnlyPlayerContextual ;
35
+ import dev .rollczi .litecommands .command .permission .RequiredPermissions ;
36
+ import dev .rollczi .litecommands .schematic .Schematic ;
23
37
import net .kyori .adventure .platform .AudienceProvider ;
24
38
import net .kyori .adventure .platform .bukkit .BukkitAudiences ;
25
39
import net .kyori .adventure .text .minimessage .MiniMessage ;
34
48
35
49
public final class EternalCheck extends JavaPlugin {
36
50
37
- private static EternalCheck instance ;
38
-
39
51
private ConfigManager configManager ;
40
- private PluginConfig config ;
52
+ private CheckedUserDataConfig checkedUserDataConfig ;
53
+ private CommandConfiguration commandConfig ;
41
54
private MessagesConfig messages ;
42
- private CheckedUserDataConfig data ;
55
+ private PluginConfig config ;
43
56
44
57
private AudienceProvider audienceProvider ;
45
58
private MiniMessage miniMessage ;
@@ -48,80 +61,101 @@ public final class EternalCheck extends JavaPlugin {
48
61
49
62
private CheckedUserService checkedUserService ;
50
63
64
+ private EventCaller eventCaller ;
65
+
66
+ private UpdaterService updaterService ;
67
+
51
68
private LiteCommands <CommandSender > liteCommands ;
52
69
53
70
@ Override
54
71
public void onEnable () {
55
- instance = this ;
56
-
57
72
Server server = this .getServer ();
58
73
59
74
this .configManager = new ConfigManager (this .getDataFolder ());
60
75
76
+ this .checkedUserDataConfig = new CheckedUserDataConfig ();
77
+ this .commandConfig = new CommandConfiguration ();
61
78
this .config = new PluginConfig ();
62
79
this .messages = new MessagesConfig ();
63
- this .data = new CheckedUserDataConfig ();
64
80
65
81
this .configManager .load (this .config );
66
82
this .configManager .load (this .messages );
67
- this .configManager .load (this .data );
68
-
69
- Metrics metrics = new Metrics (this , 15964 );
70
- metrics .addCustomChart (new SingleLineChart ("checked_users" , () -> this .data .getCheckedUsers ()));
83
+ this .configManager .load (this .checkedUserDataConfig );
84
+ this .configManager .load (this .commandConfig );
71
85
72
86
this .audienceProvider = BukkitAudiences .create (this );
73
87
this .miniMessage = MiniMessage .builder ()
74
88
.postProcessor (new LegacyColorProcessor ())
75
89
.build ();
76
90
77
- this .notificationAnnouncer = new NotificationAnnouncer (this .audienceProvider , this .miniMessage );
91
+ this .notificationAnnouncer = new NotificationAnnouncer (this .audienceProvider , this .miniMessage , this . config , server );
78
92
79
93
this .checkedUserService = new CheckedUserService ();
80
94
95
+ this .eventCaller = new EventCaller (server );
96
+
97
+ this .updaterService = new UpdaterService (this .getDescription ());
98
+
81
99
this .liteCommands = LiteBukkitFactory .builder (this .getServer (), "eternalcheck" )
82
100
.argument (Player .class , new PlayerArgument (this .messages , server ))
83
- .argument (CheckedUser .class , new CheckedUserArgument (this .messages , this .checkedUserService , server ))
101
+ .argument (CheckedUser .class , new CheckedUserArgument (this .checkedUserService , this .messages , server ))
84
102
85
- .contextualBind (Player .class , new BukkitOnlyPlayerContextual ( " " ))
103
+ .contextualBind (Player .class , new BukkitOnlyPlayerContextual <>( "Only players can use this command! " ))
86
104
87
- .permissionHandler (new PermissionMessage (this .messages , this .notificationAnnouncer ))
88
- .invalidUsageHandler (new InvalidUseMessage (this .messages , this .notificationAnnouncer ))
105
+ .resultHandler (RequiredPermissions .class , new PermissionHandler (this .notificationAnnouncer , this .messages ))
106
+ .resultHandler (Schematic .class , new InvalidUsageHandler (this .messages , this .notificationAnnouncer ))
107
+ .resultHandler (Notification .class , new NotificationHandler (this .notificationAnnouncer ))
89
108
90
- .commandInstance (new AdmitCommand (this .messages , this .config , this .checkedUserService , server , this .notificationAnnouncer ))
91
- .commandInstance (new CheckCommand (this .configManager , this .messages , this .config , this .checkedUserService , server , this .notificationAnnouncer , data ))
109
+ .commandInstance (
110
+ new AdmitCommand (this .messages , this .config , this .checkedUserService , server , this .notificationAnnouncer , this .eventCaller ),
111
+ new CheckBanCommand (this .checkedUserService , this .notificationAnnouncer , this .messages , this .eventCaller , this .config , server ),
112
+ new CheckEndCommand (this .checkedUserService , this .notificationAnnouncer , this .eventCaller , this .messages , server ),
113
+ new CheckReloadCommand (this .notificationAnnouncer , this .configManager , this .messages ),
114
+ new CheckSetLocationCommand (this .notificationAnnouncer , this .configManager , this .messages , this .config ),
115
+ new CheckStartCommand (this .checkedUserDataConfig , this .checkedUserService , this .notificationAnnouncer , this .configManager , this .messages , this .eventCaller , this .config )
116
+ )
117
+
118
+ .commandGlobalEditor (new CommandConfigurator (this .commandConfig ))
92
119
93
120
.register ();
94
121
122
+ Metrics metrics = new Metrics (this , 15964 );
123
+ metrics .addCustomChart (new SingleLineChart ("checked_users" , () -> this .checkedUserDataConfig .getCheckedUsers ()));
124
+
95
125
Stream .of (
96
- new CheckedUserChatController (this .config , this .checkedUserService ),
97
- new CheckedUserCommandController (this .messages , this .config , this .checkedUserService , this .notificationAnnouncer ),
98
- new CheckedUserMoveController (this .config , this .checkedUserService ),
99
- new CheckedUserLogoutPunishmentController (this .messages , this .config , this .checkedUserService , server , this .notificationAnnouncer )
126
+ new CheckedUserChatController (this .checkedUserService , this .config ),
127
+ new CheckedUserCommandController (this .checkedUserService , this .notificationAnnouncer , this .messages , this .config ),
128
+ new CheckedUserMoveController (this .checkedUserService , this .config ),
129
+ new CheckedUserLogoutPunishmentController (this .checkedUserService , this .notificationAnnouncer , this .messages , this .config , eventCaller , server ),
130
+ new UpdaterNotificationController (this .notificationAnnouncer , this .updaterService , this .config )
100
131
).forEach (listener -> server .getPluginManager ().registerEvents (listener , this ));
101
132
102
- if (!this .config .settings .runnable .enabled ) {
103
- return ;
133
+ if (this .config .settings .runnable .enabled ) {
134
+ server .getScheduler ().runTaskTimerAsynchronously (
135
+ this ,
136
+ new CheckNotificationTask (this .checkedUserService , this .notificationAnnouncer , this .messages , server ),
137
+ 20L ,
138
+ 20L * this .config .settings .runnable .interval );
104
139
}
105
-
106
- server .getScheduler ().runTaskTimerAsynchronously (this ,
107
- new CheckNotificationTask (this .messages , this .config , this .checkedUserService , this .notificationAnnouncer ),
108
- 0L , 20L * this .config .settings .runnable .interval );
109
-
110
140
}
111
141
112
142
@ Override
113
143
public void onDisable () {
114
144
this .liteCommands .getPlatform ().unregisterAll ();
115
145
}
116
146
117
- public static EternalCheck getInstance () {
118
- return instance ;
119
- }
120
-
121
147
public ConfigManager getConfigManager () {
122
148
return this .configManager ;
123
149
}
124
150
151
+ public CheckedUserDataConfig getDataConfig () {
152
+ return this .checkedUserDataConfig ;
153
+ }
154
+
155
+ public CommandConfiguration getCommandConfig () {
156
+ return this .commandConfig ;
157
+ }
158
+
125
159
public PluginConfig getPluginConfig () {
126
160
return this .config ;
127
161
}
@@ -130,10 +164,6 @@ public MessagesConfig getMessagesConfig() {
130
164
return this .messages ;
131
165
}
132
166
133
- public CheckedUserDataConfig getDataConfig () {
134
- return this .data ;
135
- }
136
-
137
167
public AudienceProvider getAudienceProvider () {
138
168
return this .audienceProvider ;
139
169
}
@@ -150,6 +180,14 @@ public CheckedUserService getUserService() {
150
180
return this .checkedUserService ;
151
181
}
152
182
183
+ public EventCaller getEventCaller () {
184
+ return this .eventCaller ;
185
+ }
186
+
187
+ public UpdaterService getUpdaterService () {
188
+ return this .updaterService ;
189
+ }
190
+
153
191
public LiteCommands <CommandSender > getLiteCommands () {
154
192
return this .liteCommands ;
155
193
}
0 commit comments