diff --git a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java index 0e8a7d234..570319d79 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/slack/SlackAPI.java @@ -9,6 +9,9 @@ import java.net.URL; import java.net.URLEncoder; import com.google.gson.JsonObject; + +import org.bukkit.Bukkit; + import mineplex.core.thread.ThreadPool; /** @@ -36,7 +39,7 @@ public class SlackAPI */ public void sendMessage(SlackTeam team, String channel, SlackMessage message, boolean customTitle) { - ThreadPool.ASYNC.execute(() -> + Runnable send = () -> { // Set message title. if (!customTitle) @@ -51,7 +54,15 @@ public class SlackAPI // Run the call. runWebCall(team, msg); - }); + }; + + if (Bukkit.isPrimaryThread()) + { + ThreadPool.ASYNC.execute(send); + } else + { + send.run(); + } } /** diff --git a/Plugins/Mineplex.Core/src/mineplex/core/sound/SoundNotifier.java b/Plugins/Mineplex.Core/src/mineplex/core/sound/SoundNotifier.java new file mode 100644 index 000000000..d77491002 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/sound/SoundNotifier.java @@ -0,0 +1,58 @@ +package mineplex.core.sound; + +import com.mineplex.spigot.MissingSoundEvent; + +import org.bukkit.event.EventHandler; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.slack.SlackAPI; +import mineplex.core.slack.SlackMessage; +import mineplex.core.slack.SlackTeam; +import mineplex.core.thread.ThreadPool; +import mineplex.serverdata.Region; +import mineplex.serverdata.redis.atomic.RedisStringRepository; +import mineplex.serverdata.servers.ServerManager; + +/** + * Notifies #pc-sound-logging when we detect a bad sound mapping + * @author Dan + */ +@ReflectivelyCreateMiniPlugin +public class SoundNotifier extends MiniPlugin +{ + private RedisStringRepository _repo; + + private SoundNotifier() + { + super("Sound Notifier"); + + _repo = new RedisStringRepository( + ServerManager.getMasterConnection(), + ServerManager.getSlaveConnection(), + Region.ALL, + "missingSounds" + ); + } + + @EventHandler + public void onMissingSound(MissingSoundEvent event) + { + final String message = event.getMessage(); + + ThreadPool.ASYNC.execute(() -> + { + if (_repo.get(message) == null) + { + sendSlackMessage(event.getMessage()); + _repo.set(message, "sent"); + } + }); + } + + private void sendSlackMessage(String message) + { + SlackMessage slackMsg = new SlackMessage("Sound Bot", "notes", message); + SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, "#pc-sound-logging", slackMsg, true); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 543dbacc8..ceaecd3e2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -55,6 +55,7 @@ import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; import mineplex.core.resourcepack.ResourcePackManager; import mineplex.core.serverConfig.ServerConfiguration; +import mineplex.core.sound.SoundNotifier; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; import mineplex.core.teamspeak.TeamspeakManager; @@ -204,6 +205,7 @@ public class Hub extends JavaPlugin implements IRelation require(TeamspeakManager.class); new WebsiteLinkManager(this, clientManager); require(TwitchIntegrationFix.class); + require(SoundNotifier.class); new AdminCommands(); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 7d6a76e22..2a7774134 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -69,6 +69,7 @@ import mineplex.core.recharge.Recharge; import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; import mineplex.core.serverConfig.ServerConfiguration; +import mineplex.core.sound.SoundNotifier; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; import mineplex.core.teleport.Teleport; @@ -227,6 +228,7 @@ public class Arcade extends JavaPlugin AprilFoolsManager.getInstance(); require(CustomItemFrames.class); + require(SoundNotifier.class); //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);