Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
feat(inject): change the way of injecting the dependencies of the con…
Browse files Browse the repository at this point in the history
…figuration files and also the message manager making it more comfortable and more flexible.

refactor(identation): apply code style from editorconfig rules
  • Loading branch information
jonakls committed Jun 3, 2023
1 parent cea85f0 commit 502a406
Showing 1 changed file with 41 additions and 52 deletions.
93 changes: 41 additions & 52 deletions src/main/java/me/jonakls/miniannouncer/module/PluginModule.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package me.jonakls.miniannouncer.module;

import me.clip.placeholderapi.PlaceholderAPI;
import me.jonakls.miniannouncer.BukkitConfiguration;
import me.jonakls.miniannouncer.MiniAnnouncer;
import me.jonakls.miniannouncer.MiniAnnouncerPlugin;
import me.jonakls.miniannouncer.announce.AnnounceService;
import me.jonakls.miniannouncer.announce.AnnouncementManager;
import me.jonakls.miniannouncer.message.MessageHandler;
import me.jonakls.miniannouncer.message.MessageInterceptor;
import me.jonakls.miniannouncer.module.submodules.CommandModule;
import me.jonakls.miniannouncer.service.CommandService;
import me.jonakls.miniannouncer.service.Service;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.slf4j.Logger;
import team.unnamed.inject.AbstractModule;
import team.unnamed.inject.Provides;
Expand All @@ -20,51 +16,44 @@

public class PluginModule extends AbstractModule {

private final MiniAnnouncer plugin;

public PluginModule(MiniAnnouncer plugin) {
this.plugin = plugin;
}

@Singleton
@Provides
public Logger logger(MiniAnnouncer plugin) {
return plugin.getSLF4JLogger();
}

@Override
protected void configure() {
bind(MiniAnnouncer.class).toInstance(plugin);

BukkitConfiguration config = new BukkitConfiguration(plugin, "config");
bind(BukkitConfiguration.class)
.toInstance(config);

MessageHandler messageHandler = new MessageHandler(config);

if (Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {

messageHandler.addInterceptor((sender, message) -> {
if (sender instanceof Player) {
return PlaceholderAPI.setPlaceholders((Player) sender, message);
}
return message;
});
}

messageHandler.addInterceptor(MessageInterceptor.CHAT_COLOR_INTERCEPTOR);

bind(MessageHandler.class)
.toInstance(messageHandler);

multibind(Service.class)
.asSet()
.to(AnnounceService.class)
.to(CommandService.class)
.singleton();

bind(AnnouncementManager.class).singleton();

install(new CommandModule(plugin));
}
private final MiniAnnouncerPlugin plugin;

public PluginModule(MiniAnnouncerPlugin plugin) {
this.plugin = plugin;
}

@Singleton
@Provides
public Logger logger(MiniAnnouncerPlugin plugin) {
return plugin.getSLF4JLogger();
}

@Singleton
@Provides
public BukkitConfiguration configurationProvides(MiniAnnouncerPlugin plugin) {
return BukkitConfiguration.of(plugin, "config");
}

@Singleton
@Provides
public MessageHandler messageHandlerProvides(BukkitConfiguration config) {
return MessageHandler.create(config);
}

@Override
protected void configure() {
super.bind(MiniAnnouncerPlugin.class)
.toInstance(plugin);

super.multibind(Service.class)
.asSet()
.to(AnnounceService.class)
.to(CommandService.class)
.singleton();

super.bind(AnnouncementManager.class)
.singleton();

super.install(new CommandModule(plugin));
}
}

0 comments on commit 502a406

Please sign in to comment.