Add a toggleable report sound (#64)
* add a toggleable report sound * use audience variable in ReportAnnouncer
This commit is contained in:
parent
e3cd39ad39
commit
a402c02d52
|
@ -55,8 +55,7 @@ import tc.oc.commons.bukkit.nick.PlayerOrder;
|
|||
import tc.oc.commons.bukkit.nick.PlayerOrderCache;
|
||||
import tc.oc.commons.bukkit.punishment.PunishmentManifest;
|
||||
import tc.oc.commons.bukkit.raindrops.RaindropManifest;
|
||||
import tc.oc.commons.bukkit.report.ReportAnnouncer;
|
||||
import tc.oc.commons.bukkit.report.ReportCommands;
|
||||
import tc.oc.commons.bukkit.report.ReportManifest;
|
||||
import tc.oc.commons.bukkit.respack.ResourcePackCommands;
|
||||
import tc.oc.commons.bukkit.respack.ResourcePackListener;
|
||||
import tc.oc.commons.bukkit.respack.ResourcePackManager;
|
||||
|
@ -110,6 +109,7 @@ public final class CommonsBukkitManifest extends HybridManifest {
|
|||
install(new LocalizationManifest());
|
||||
install(new NavigatorManifest());
|
||||
install(new RaindropManifest());
|
||||
install(new ReportManifest());
|
||||
install(new TokenManifest());
|
||||
install(new StatsManifest());
|
||||
install(new PunishmentManifest());
|
||||
|
@ -169,8 +169,6 @@ public final class CommonsBukkitManifest extends HybridManifest {
|
|||
facets.register(PlayerFreezer.class);
|
||||
facets.register(PlayerOrderCache.class);
|
||||
facets.register(PlayerServerChanger.class);
|
||||
facets.register(ReportAnnouncer.class);
|
||||
facets.register(ReportCommands.class);
|
||||
facets.register(ResourcePackCommands.class);
|
||||
facets.register(ResourcePackCommands.Parent.class);
|
||||
facets.register(ResourcePackListener.class);
|
||||
|
|
|
@ -4,7 +4,12 @@ import java.util.List;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import me.anxuiz.settings.Setting;
|
||||
import me.anxuiz.settings.SettingBuilder;
|
||||
import me.anxuiz.settings.types.BooleanType;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import tc.oc.api.docs.Report;
|
||||
import tc.oc.api.docs.Server;
|
||||
import tc.oc.api.message.MessageListener;
|
||||
|
@ -12,12 +17,23 @@ import tc.oc.api.message.MessageQueue;
|
|||
import tc.oc.api.message.types.ModelUpdate;
|
||||
import tc.oc.commons.bukkit.channels.AdminChannel;
|
||||
import tc.oc.commons.bukkit.chat.Audiences;
|
||||
import tc.oc.commons.bukkit.chat.BukkitSound;
|
||||
import tc.oc.commons.bukkit.settings.SettingManagerProvider;
|
||||
import tc.oc.commons.core.chat.Audience;
|
||||
import tc.oc.commons.core.plugin.PluginFacet;
|
||||
import tc.oc.minecraft.scheduler.MainThreadExecutor;
|
||||
|
||||
@Singleton
|
||||
public class ReportAnnouncer implements PluginFacet, MessageListener {
|
||||
|
||||
static final Setting SOUND_SETTING = new SettingBuilder()
|
||||
.name("ReportSound").alias("rs")
|
||||
.summary("Hear a sound when someone sends a report")
|
||||
.type(new BooleanType())
|
||||
.defaultValue(true).get();
|
||||
|
||||
private static final BukkitSound REPORT_SOUND = new BukkitSound(Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1, 2);
|
||||
|
||||
private final ReportConfiguration config;
|
||||
private final ReportFormatter reportFormatter;
|
||||
private final MessageQueue primaryQueue;
|
||||
|
@ -25,8 +41,9 @@ public class ReportAnnouncer implements PluginFacet, MessageListener {
|
|||
private final Server localServer;
|
||||
private final AdminChannel adminChannel;
|
||||
private final Audiences audiences;
|
||||
private final SettingManagerProvider settings;
|
||||
|
||||
@Inject ReportAnnouncer(ReportConfiguration config, ReportFormatter reportFormatter, MessageQueue primaryQueue, MainThreadExecutor executor, Server localServer, AdminChannel adminChannel, Audiences audiences) {
|
||||
@Inject ReportAnnouncer(ReportConfiguration config, ReportFormatter reportFormatter, MessageQueue primaryQueue, MainThreadExecutor executor, Server localServer, AdminChannel adminChannel, Audiences audiences, SettingManagerProvider settings) {
|
||||
this.config = config;
|
||||
this.reportFormatter = reportFormatter;
|
||||
this.primaryQueue = primaryQueue;
|
||||
|
@ -34,6 +51,7 @@ public class ReportAnnouncer implements PluginFacet, MessageListener {
|
|||
this.localServer = localServer;
|
||||
this.adminChannel = adminChannel;
|
||||
this.audiences = audiences;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +78,13 @@ public class ReportAnnouncer implements PluginFacet, MessageListener {
|
|||
final List<? extends BaseComponent> formatted = reportFormatter.format(message.document(), true, false);
|
||||
adminChannel.viewers()
|
||||
.filter(viewer -> viewer.hasPermission(ReportPermissions.RECEIVE))
|
||||
.forEach(viewer -> audiences.get(viewer).sendMessages(formatted));
|
||||
.forEach(viewer -> {
|
||||
Audience audience = audiences.get(viewer);
|
||||
audience.sendMessages(formatted);
|
||||
if (viewer instanceof Player && (boolean)settings.getManager((Player)viewer).getValue(SOUND_SETTING)) {
|
||||
audience.playSound(REPORT_SOUND);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package tc.oc.commons.bukkit.report;
|
||||
|
||||
import tc.oc.commons.bukkit.settings.SettingBinder;
|
||||
import tc.oc.commons.core.inject.HybridManifest;
|
||||
import tc.oc.commons.core.plugin.PluginFacetBinder;
|
||||
|
||||
public class ReportManifest extends HybridManifest {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
new SettingBinder(publicBinder())
|
||||
.addBinding()
|
||||
.toInstance(ReportAnnouncer.SOUND_SETTING);
|
||||
|
||||
final PluginFacetBinder facets = new PluginFacetBinder(binder());
|
||||
facets.register(ReportCommands.class);
|
||||
facets.register(ReportAnnouncer.class);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue