Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 93fed4d

Browse files
authored
GH-80 Refactor notification system, add new events and more (#80)
* Refactor notification system, add new events and more * Resolve rollczi conversation * Resolve martin & jakub conversation * Resolve jakub conversation * Resolve Martin conversation * Remove badly usage of creating new list. * Update discord invite link
1 parent 31bfd8d commit 93fed4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1261
-456
lines changed

build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ dependencies {
3030
implementation("net.kyori:adventure-text-minimessage:4.12.0")
3131

3232
// LiteCommands
33-
implementation("dev.rollczi.litecommands:bukkit:2.8.2")
33+
implementation("dev.rollczi.litecommands:bukkit:2.8.4")
3434

3535
// CDN
36-
implementation("net.dzikoysk:cdn:1.14.3")
36+
implementation("net.dzikoysk:cdn:1.14.4")
3737

3838
// bStats
3939
implementation("org.bstats:bstats-bukkit:3.0.0")
40+
41+
// gitcheck
42+
implementation("com.eternalcode:gitcheck:1.0.0")
4043
}
4144

4245
tasks.withType<JavaCompile> {

src/main/java/com/eternalcode/check/CheckNotificationTask.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,43 @@
11
package com.eternalcode.check;
22

33
import com.eternalcode.check.config.implementation.MessagesConfig;
4-
import com.eternalcode.check.config.implementation.PluginConfig;
4+
import com.eternalcode.check.notification.Notification;
5+
import com.eternalcode.check.notification.NotificationAnnouncer;
56
import com.eternalcode.check.user.CheckedUser;
67
import com.eternalcode.check.user.CheckedUserService;
8+
import org.bukkit.Server;
9+
import org.bukkit.entity.Player;
710
import panda.utilities.text.Formatter;
811

9-
import java.time.Duration;
10-
import java.util.UUID;
11-
1212
public final class CheckNotificationTask implements Runnable {
1313

14-
private final MessagesConfig messages;
15-
private final PluginConfig config;
1614
private final CheckedUserService checkedUserService;
1715
private final NotificationAnnouncer announcer;
16+
private final MessagesConfig messages;
17+
private final Server server;
1818

19-
private final Duration stay, fadeOut, fadeIn;
20-
21-
public CheckNotificationTask(MessagesConfig messages, PluginConfig config, CheckedUserService checkedUserService, NotificationAnnouncer announcer) {
22-
this.messages = messages;
23-
this.config = config;
19+
public CheckNotificationTask(CheckedUserService checkedUserService, NotificationAnnouncer announcer, MessagesConfig messages, Server server) {
2420
this.checkedUserService = checkedUserService;
2521
this.announcer = announcer;
26-
27-
this.stay = this.config.settings.title.stay;
28-
this.fadeOut = this.config.settings.title.fadeOut;
29-
this.fadeIn = this.config.settings.title.fadeIn;
22+
this.messages = messages;
23+
this.server = server;
3024
}
3125

3226
@Override
3327
public void run() {
34-
for (CheckedUser user : this.checkedUserService.getUsers()) {
35-
UUID userUniqueId = user.getUniqueId();
28+
for (CheckedUser user : this.checkedUserService.checkedUsers()) {
29+
Player player = this.server.getPlayer(user.getUniqueId());
30+
31+
if (player == null) {
32+
continue;
33+
}
3634

3735
Formatter formatter = new Formatter()
3836
.register("{PLAYER}", user.getName())
3937
.register("{ADMIN}", user.getChecker());
4038

41-
if (this.config.settings.title.taskTitleMessageEnabled) {
42-
this.announcer.announceTitle(userUniqueId, this.messages.check.task.title, this.messages.check.task.subTitle, this.stay, this.fadeOut, this.fadeIn);
43-
}
44-
45-
if (this.config.settings.taskActionBarEnabled) {
46-
this.announcer.announceActionBar(userUniqueId, this.messages.check.task.actionBar);
47-
}
48-
49-
if (this.config.settings.taskMessageEnabled) {
50-
this.messages.check.task.message.forEach(message -> this.announcer.announceMessage(userUniqueId, formatter.format(message)));
39+
for (Notification notification : this.messages.check.taskMessages) {
40+
this.announcer.sendAnnounce(player, notification, formatter);
5141
}
5242
}
5343
}

src/main/java/com/eternalcode/check/EternalCheck.java

Lines changed: 82 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
package com.eternalcode.check;
22

3+
import com.eternalcode.check.caller.EventCaller;
4+
import com.eternalcode.check.command.CommandConfiguration;
35
import com.eternalcode.check.command.argument.CheckedUserArgument;
46
import com.eternalcode.check.command.argument.PlayerArgument;
7+
import com.eternalcode.check.command.configurator.CommandConfigurator;
8+
import com.eternalcode.check.command.handler.NotificationHandler;
59
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;
917
import com.eternalcode.check.config.ConfigManager;
1018
import com.eternalcode.check.config.implementation.CheckedUserDataConfig;
1119
import com.eternalcode.check.config.implementation.MessagesConfig;
1220
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;
1729
import com.eternalcode.check.shared.legacy.LegacyColorProcessor;
1830
import com.eternalcode.check.user.CheckedUser;
1931
import com.eternalcode.check.user.CheckedUserService;
2032
import dev.rollczi.litecommands.LiteCommands;
2133
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
2234
import dev.rollczi.litecommands.bukkit.tools.BukkitOnlyPlayerContextual;
35+
import dev.rollczi.litecommands.command.permission.RequiredPermissions;
36+
import dev.rollczi.litecommands.schematic.Schematic;
2337
import net.kyori.adventure.platform.AudienceProvider;
2438
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
2539
import net.kyori.adventure.text.minimessage.MiniMessage;
@@ -34,12 +48,11 @@
3448

3549
public final class EternalCheck extends JavaPlugin {
3650

37-
private static EternalCheck instance;
38-
3951
private ConfigManager configManager;
40-
private PluginConfig config;
52+
private CheckedUserDataConfig checkedUserDataConfig;
53+
private CommandConfiguration commandConfig;
4154
private MessagesConfig messages;
42-
private CheckedUserDataConfig data;
55+
private PluginConfig config;
4356

4457
private AudienceProvider audienceProvider;
4558
private MiniMessage miniMessage;
@@ -48,80 +61,101 @@ public final class EternalCheck extends JavaPlugin {
4861

4962
private CheckedUserService checkedUserService;
5063

64+
private EventCaller eventCaller;
65+
66+
private UpdaterService updaterService;
67+
5168
private LiteCommands<CommandSender> liteCommands;
5269

5370
@Override
5471
public void onEnable() {
55-
instance = this;
56-
5772
Server server = this.getServer();
5873

5974
this.configManager = new ConfigManager(this.getDataFolder());
6075

76+
this.checkedUserDataConfig = new CheckedUserDataConfig();
77+
this.commandConfig = new CommandConfiguration();
6178
this.config = new PluginConfig();
6279
this.messages = new MessagesConfig();
63-
this.data = new CheckedUserDataConfig();
6480

6581
this.configManager.load(this.config);
6682
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);
7185

7286
this.audienceProvider = BukkitAudiences.create(this);
7387
this.miniMessage = MiniMessage.builder()
7488
.postProcessor(new LegacyColorProcessor())
7589
.build();
7690

77-
this.notificationAnnouncer = new NotificationAnnouncer(this.audienceProvider, this.miniMessage);
91+
this.notificationAnnouncer = new NotificationAnnouncer(this.audienceProvider, this.miniMessage, this.config, server);
7892

7993
this.checkedUserService = new CheckedUserService();
8094

95+
this.eventCaller = new EventCaller(server);
96+
97+
this.updaterService = new UpdaterService(this.getDescription());
98+
8199
this.liteCommands = LiteBukkitFactory.builder(this.getServer(), "eternalcheck")
82100
.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))
84102

85-
.contextualBind(Player.class, new BukkitOnlyPlayerContextual(""))
103+
.contextualBind(Player.class, new BukkitOnlyPlayerContextual<>("Only players can use this command!"))
86104

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))
89108

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))
92119

93120
.register();
94121

122+
Metrics metrics = new Metrics(this, 15964);
123+
metrics.addCustomChart(new SingleLineChart("checked_users", () -> this.checkedUserDataConfig.getCheckedUsers()));
124+
95125
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)
100131
).forEach(listener -> server.getPluginManager().registerEvents(listener, this));
101132

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);
104139
}
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-
110140
}
111141

112142
@Override
113143
public void onDisable() {
114144
this.liteCommands.getPlatform().unregisterAll();
115145
}
116146

117-
public static EternalCheck getInstance() {
118-
return instance;
119-
}
120-
121147
public ConfigManager getConfigManager() {
122148
return this.configManager;
123149
}
124150

151+
public CheckedUserDataConfig getDataConfig() {
152+
return this.checkedUserDataConfig;
153+
}
154+
155+
public CommandConfiguration getCommandConfig() {
156+
return this.commandConfig;
157+
}
158+
125159
public PluginConfig getPluginConfig() {
126160
return this.config;
127161
}
@@ -130,10 +164,6 @@ public MessagesConfig getMessagesConfig() {
130164
return this.messages;
131165
}
132166

133-
public CheckedUserDataConfig getDataConfig() {
134-
return this.data;
135-
}
136-
137167
public AudienceProvider getAudienceProvider() {
138168
return this.audienceProvider;
139169
}
@@ -150,6 +180,14 @@ public CheckedUserService getUserService() {
150180
return this.checkedUserService;
151181
}
152182

183+
public EventCaller getEventCaller() {
184+
return this.eventCaller;
185+
}
186+
187+
public UpdaterService getUpdaterService() {
188+
return this.updaterService;
189+
}
190+
153191
public LiteCommands<CommandSender> getLiteCommands() {
154192
return this.liteCommands;
155193
}

src/main/java/com/eternalcode/check/NotificationAnnouncer.java

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.eternalcode.check.caller;
2+
3+
import com.eternalcode.check.user.event.CheckedUserEvent;
4+
import org.bukkit.Server;
5+
6+
public final class EventCaller {
7+
8+
private final Server server;
9+
10+
public EventCaller(Server server) {
11+
this.server = server;
12+
}
13+
14+
public <T extends CheckedUserEvent> T callEvent(T event) {
15+
this.server.getPluginManager().callEvent(event);
16+
17+
return event;
18+
}
19+
}

0 commit comments

Comments
 (0)