-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathRedisChat.java
More file actions
392 lines (344 loc) · 16.7 KB
/
RedisChat.java
File metadata and controls
392 lines (344 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package dev.unnm3d.redischat;
import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import de.exlll.configlib.ConfigLib;
import de.exlll.configlib.ConfigurationException;
import de.exlll.configlib.YamlConfigurationProperties;
import de.exlll.configlib.YamlConfigurations;
import dev.jorel.commandapi.CommandAPICommand;
import dev.unnm3d.redischat.api.DataManager;
import dev.unnm3d.redischat.channels.ChannelCommand;
import dev.unnm3d.redischat.channels.ChannelManager;
import dev.unnm3d.redischat.chat.ComponentProvider;
import dev.unnm3d.redischat.chat.PlaceholderManager;
import dev.unnm3d.redischat.chat.RedisChatPAPI;
import dev.unnm3d.redischat.chat.listeners.ChatListenerWithPriority;
import dev.unnm3d.redischat.chat.listeners.JoinQuitManager;
import dev.unnm3d.redischat.chat.listeners.UtilsListener;
import dev.unnm3d.redischat.commands.*;
import dev.unnm3d.redischat.datamanagers.RedisDataManager;
import dev.unnm3d.redischat.datamanagers.sqlmanagers.MySQLDataManager;
import dev.unnm3d.redischat.datamanagers.sqlmanagers.SQLiteDataManager;
import dev.unnm3d.redischat.discord.DiscordWebhook;
import dev.unnm3d.redischat.discord.IDiscordHook;
import dev.unnm3d.redischat.discord.SpicordHook;
import dev.unnm3d.redischat.integrations.*;
import dev.unnm3d.redischat.mail.MailGUIManager;
import dev.unnm3d.redischat.mail.MailUniformCommand;
import dev.unnm3d.redischat.moderation.MuteCommand;
import dev.unnm3d.redischat.moderation.SpyChatCommand;
import dev.unnm3d.redischat.moderation.SpyManager;
import dev.unnm3d.redischat.moderation.StaffChatCommand;
import dev.unnm3d.redischat.permission.LuckPermsProvider;
import dev.unnm3d.redischat.permission.PermissionProvider;
import dev.unnm3d.redischat.permission.VaultPermissionProvider;
import dev.unnm3d.redischat.settings.Config;
import dev.unnm3d.redischat.settings.FiltersConfig;
import dev.unnm3d.redischat.settings.GuiSettings;
import dev.unnm3d.redischat.settings.Messages;
import dev.unnm3d.redischat.task.AnnouncerManager;
import dev.unnm3d.redischat.utils.AdventureWebuiEditorAPI;
import dev.unnm3d.redischat.utils.Metrics;
import lombok.Getter;
import net.william278.uniform.paper.PaperUniform;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public final class RedisChat extends JavaPlugin {
@Getter
private static RedisChat instance;
@Getter
private static TaskScheduler scheduler;
private List<CommandAPICommand> registeredCommands;
public GuiSettings guiSettings;
@Getter
private DataManager dataManager;
@Getter
private PlayerListManager playerListManager;
@Getter
private ChannelManager channelManager;
@Getter
private AnnouncerManager announcerManager;
@Getter
private SpyManager spyManager;
@Getter
private PlaceholderManager placeholderManager;
@Getter
private ComponentProvider componentProvider;
@Getter
private AdventureWebuiEditorAPI webEditorAPI;
@Getter
private JoinQuitManager joinQuitManager;
@Getter
private PermissionProvider permissionProvider;
@Getter
private IDiscordHook discordHook;
@Getter
private ExecutorService executorService;
@Getter
private MailGUIManager mailGUIManager;
public Config config;
public FiltersConfig filterSettings;
public Messages messages;
@Override
public void onEnable() {
instance = this;
registeredCommands = new ArrayList<>();
scheduler = UniversalScheduler.getScheduler(this);
try {
loadYML();
} catch (ConfigurationException e) {
getLogger().severe("config.yml or messages.yml or guis.yml is invalid! Please regenerate them (starting from config.yml: " + e.getMessage());
}
this.executorService = Executors.newFixedThreadPool(config.chatThreads);
//Redis section
this.dataManager = switch (config.getDataType()) {
case REDIS -> RedisDataManager.startup(this);
case MYSQL -> new MySQLDataManager(this);
case SQLITE -> new SQLiteDataManager(this);
};
//Permission section
if (getServer().getPluginManager().getPlugin("LuckPerms") != null) {
getLogger().info("LuckPerms found, enabling integration");
this.permissionProvider = new LuckPermsProvider();
} else if (getServer().getPluginManager().getPlugin("Vault") != null) {
getLogger().info("Vault found, enabling integration");
this.permissionProvider = new VaultPermissionProvider();
} else {
this.permissionProvider = new PermissionProvider() {
};
}
//Chat section
this.componentProvider = new ComponentProvider(this);
ChatListenerWithPriority listenerWithPriority;
try {
listenerWithPriority = ChatListenerWithPriority.valueOf(config.listeningPriority);
} catch (IllegalArgumentException e) {
getLogger().warning("Invalid listening priority, using NORMAL");
listenerWithPriority = ChatListenerWithPriority.NORMAL;
}
getServer().getPluginManager().registerEvents(listenerWithPriority.getListener(), this);
if (config.enableStaffChat)
loadUniformCommand(new StaffChatCommand());
this.channelManager = new ChannelManager(this);
loadCommandAPICommand(new ChannelCommand(this).getCommand());
//loadUniformCommand(new ChannelUniformCommand(this));
final TalkOnCommand talkOnCommand = new TalkOnCommand(this);
loadCommand("talkon", talkOnCommand, talkOnCommand);
if (config.enableQuitJoinMessages) {
if (config.getDataType() == Config.DataType.REDIS) {
this.joinQuitManager = new JoinQuitManager(this);
getServer().getPluginManager().registerEvents(this.joinQuitManager, this);
} else {
getLogger().warning("Join/Quit messages are not supported with SQLite or MySQL");
}
}
//Update active channel on join and spy listener
getServer().getPluginManager().registerEvents(new UtilsListener(this), this);
//Mail section
if (config.enableMails) {
this.mailGUIManager = new MailGUIManager(this);
loadUniformCommand(new MailUniformCommand(this));
}
//Announce feature
this.announcerManager = new AnnouncerManager(this);
loadCommandAPICommand(new AnnounceCommand(this, this.announcerManager).getCommand());
this.playerListManager = new PlayerListManager(this);
this.webEditorAPI = new AdventureWebuiEditorAPI(config.webEditorUrl);
//Commands section
loadCommandAPICommand(new MainCommand(this, this.webEditorAPI).getCommand());
//loadUniformCommand(new UniformMsgCommand());
loadCommandAPICommand(new MsgCommand(this).getCommand());
//loadUniformCommand(new UniformReplyCommand());
loadCommandAPICommand(new ReplyCommand(this).getCommand());
loadCommandAPICommand(new ChatAsCommand(this).getCommand());
final BroadcastCommand broadcastCommand = new BroadcastCommand(this);
loadCommandAPICommand(broadcastCommand.getBroadcastCommand());
loadCommandAPICommand(broadcastCommand.getBroadcastRawCommand());
if (config.dataMedium.equals(Config.DataType.REDIS.toString())) {
loadCommandAPICommand(new MuteCommand(this).getMuteCommand());
loadCommandAPICommand(new MuteCommand(this).getUnMuteCommand());
} else {
getLogger().warning("Mute command is currently not supported with SQLite or MySQL");
getLogger().warning("UnMute command is currently not supported with SQLite or MySQL");
}
//Old command API
SetItemCommand setItemCommand = new SetItemCommand(this);
loadCommand("redischat-setitem", setItemCommand, setItemCommand);
this.spyManager = new SpyManager(this);
loadCommand("spychat", new SpyChatCommand(this), null);
IgnoreCommand ignoreCommand = new IgnoreCommand(this);
loadCommand("ignore", ignoreCommand, ignoreCommand);
loadCommandAPICommand(new IgnoreWhitelistCommand(this).getCommand());
loadCommand("clearchat", new ClearChatCommand(this), null);
//RedisChat Placeholders
this.placeholderManager = new PlaceholderManager(this);
final ChatColorCommand chatColorCommand = new ChatColorCommand(this);
loadCommand("chatcolor", chatColorCommand, chatColorCommand);
final SetPlaceholderCommand placeholderCommand = new SetPlaceholderCommand(this);
loadCommand("setchatplaceholder", placeholderCommand, placeholderCommand);
//InvShare part
loadCommand("invshare", new InvShareCommand(this), null);
new Metrics(this, 17678);
//Integration section
if (getServer().getPluginManager().getPlugin("Oraxen") != null) {
getLogger().info("Oraxen found, enabling integration");
componentProvider.addResolverIntegration(new OraxenTagResolver());
}
if (getServer().getPluginManager().getPlugin("PremiumVanish") != null) {
getLogger().info("PremiumVanish found, enabling integration");
playerListManager.addVanishIntegration(new PremiumVanishIntegration(this));
}
if (getServer().getPluginManager().getPlugin("SuperVanish") != null) {
getLogger().info("SuperVanish found, enabling integration");
playerListManager.addVanishIntegration(new SuperVanishIntegration(this));
}
if (getServer().getPluginManager().getPlugin("Essentials") != null) {
getLogger().info("SuperVanish found, enabling integration");
playerListManager.addVanishIntegration(new EssentialsVanishIntegration(this));
}
if (getServer().getPluginManager().getPlugin("SayanVanish") != null) {
getLogger().info("SayanVanish found, enabling integration");
playerListManager.addVanishIntegration(new SayanVanishIntegration());
}
if (getServer().getPluginManager().getPlugin("Spicord") != null && config.spicord.enabled()) {
getLogger().info("Spicord found, enabling integration");
this.discordHook = new SpicordHook(this);
} else {
getLogger().info("Spicord not found, using default DiscordWebhook");
this.discordHook = new DiscordWebhook(this);
}
//PlaceholderAPI is always enabled as it is a dependency
new RedisChatPAPI(this).register();
new UpdateCheck(this).getVersion(version -> {
if (!this.getDescription().getVersion().equalsIgnoreCase(version)) {
getLogger().info("§k*******§r §6New version available: " + version + " §k*******");
getLogger().info("Check it on https://www.spigotmc.org/resources/redischat%E2%9A%A1simple-intuitive-chat-suite%E2%9A%A1cross-server-support.111015/");
}
});
}
public void loadYML() throws ConfigurationException {
Path configFile = new File(getDataFolder(), "config.yml").toPath();
this.config = YamlConfigurations.update(
configFile,
Config.class,
YamlConfigurationProperties.newBuilder()
.header("RedisChat config")
.footer("Authors: Unnm3d")
.charset(StandardCharsets.UTF_8)
.build()
);
if (this.config.validateConfig())
YamlConfigurations.save(configFile, Config.class, this.config);
Path filtersFile = new File(getDataFolder(), "filters.yml").toPath();
this.filterSettings = YamlConfigurations.update(
filtersFile,
FiltersConfig.class,
YamlConfigurationProperties.newBuilder()
.header("""
How to configure filters:
enabled: true/false # If the filter is enabled at all
priority: 1 # The priority of the filter
audienceWhitelist: # The audience type of the filter (who is the target of the filter)
- DISCORD
- PLAYER #Private messages
- CHANNEL #Channel messages
channelWhitelist: [] # Which channels are affected by the filter, leave empty for all channels
""")
.charset(StandardCharsets.UTF_8)
.build()
);
Path messagesFile = new File(getDataFolder(), "messages.yml").toPath();
this.messages = YamlConfigurations.update(
messagesFile,
Messages.class,
YamlConfigurationProperties.newBuilder()
.header("RedisChat messages")
.footer("Authors: Unnm3d")
.charset(StandardCharsets.UTF_8)
.build()
);
Path guiSettingsFile = new File(getDataFolder(), "guis.yml").toPath();
this.guiSettings = YamlConfigurations.update(
guiSettingsFile,
GuiSettings.class,
ConfigLib.BUKKIT_DEFAULT_PROPERTIES.toBuilder()
.header("RedisChat guis")
.footer("Authors: Unnm3d")
.charset(StandardCharsets.UTF_8)
.build()
);
if (this.guiSettings.validateConfig())
YamlConfigurations.save(guiSettingsFile, GuiSettings.class, this.guiSettings);
}
public void saveMessages() {
YamlConfigurations.save(
new File(this.getDataFolder(), "messages.yml").toPath(),
Messages.class,
messages,
YamlConfigurationProperties.newBuilder()
.header("RedisChat messages")
.footer("Authors: Unnm3d")
.build());
}
public void saveGuiSettings() {
YamlConfigurations.save(
new File(this.getDataFolder(), "guis.yml").toPath(),
GuiSettings.class,
guiSettings,
ConfigLib.BUKKIT_DEFAULT_PROPERTIES.toBuilder()
.header("RedisChat guis")
.footer("Authors: Unnm3d")
.build());
}
@Override
public void onDisable() {
getLogger().warning("RedisChat is disabling...");
if (this.dataManager != null)
this.dataManager.clearInvShareCache();
PaperUniform.getInstance(this).shutdown();
// Commands are unregistered automatically by CommandAPI plugin
registeredCommands.clear();
if (this.playerListManager != null)
this.playerListManager.stop();
if (this.dataManager != null)
this.dataManager.close();
if (this.announcerManager != null)
this.announcerManager.cancelAll();
}
private void loadCommand(@NotNull String cmdName, @NotNull CommandExecutor executor, @Nullable TabCompleter tabCompleter) {
if (config.disabledCommands.contains(cmdName)) {
getLogger().warning("Command " + cmdName + " is disabled in the config.yml file!");
return;
}
PluginCommand cmd = getServer().getPluginCommand(cmdName);
if (cmd != null) {
cmd.setExecutor(executor);
cmd.setTabCompleter(tabCompleter);
} else {
getLogger().warning("Command " + cmdName + " not found!");
}
}
private void loadCommandAPICommand(CommandAPICommand commandAPICommand) {
if (config.disabledCommands.contains(commandAPICommand.getName())) {
getLogger().warning("Command " + commandAPICommand.getName() + " is disabled in the config.yml file!");
return;
}
commandAPICommand.register();
registeredCommands.add(commandAPICommand);
getLogger().info("Command " + commandAPICommand.getName() + " registered on CommandAPI!");
}
public void loadUniformCommand(RedisChatCommand command) {
PaperUniform.getInstance(this, false).register(command.getCommand());
}
}