Search in sources :

Example 1 with ChannelsHandler

use of com.epicnicity322.channelshandler.ChannelsHandler in project PlayMoreSounds by Epicnicity322.

the class EssentialsChatHook method onStart.

@Override
protected void onStart() {
    Logger logger = PlayMoreSounds.getConsoleLogger();
    PluginManager pm = Bukkit.getPluginManager();
    ess = (IEssentials) pm.getPlugin("Essentials");
    if (ess == null || !pm.isPluginEnabled("EssentialsChat")) {
        logger.log("[EssentialsChat Hook] Addon could not be started because EssentialsChat plugin failed to enable.", ConsoleLogger.Level.ERROR);
        PlayMoreSounds.getAddonManager().stopAddon(this);
        return;
    }
    for (RegisteredListener registeredListener : HandlerList.getRegisteredListeners(pm.getPlugin("EssentialsChat"))) {
        Listener listener = registeredListener.getListener();
        if (listener instanceof EssentialsChatPlayerListenerLowest) {
            try {
                Field chatStoreField = listener.getClass().getSuperclass().getDeclaredField("chatStorage");
                chatStoreField.setAccessible(true);
                chatStore = (Map<?, ?>) chatStoreField.get(listener);
            } catch (Exception e) {
                PlayMoreSoundsCore.getErrorHandler().report(e, "EssentialsChat Hook Addon Error - Could not get field using reflection:");
            }
            break;
        }
    }
    if (chatStore == null) {
        logger.log("[EssentialsChat Hook] Failed to get EssentialsChat's chatStorage map.", ConsoleLogger.Level.ERROR);
        PlayMoreSounds.getAddonManager().stopAddon(this);
        return;
    }
    handler = new ChannelsHandler("EssentialsChat", this, new ChannelsHandler.ChannelSoundPreventer() {

        @Override
        protected boolean preventReceivingSound(@NotNull Player receiver, @NotNull Player chatter, @NotNull String channel) {
            return ess.getUser(receiver).isIgnoredPlayer(ess.getUser(chatter));
        }
    });
    // Appending defaults to channels.yml
    if (!ChannelsHandlerAddon.CHANNELS_CONFIG.getConfiguration().contains("EssentialsChat")) {
        int defaultRadius = ess.getSettings().getChatRadius();
        String data = "\n\nEssentialsChat:\n" + "  local: # This is the default channel everyone talks.\n" + "    Enabled: true\n" + "    Sounds:\n" + "      '1':\n" + "        Options:\n" + "          # If you have assigned a radius to local channel in essentials config, make sure to put\n" + "          #the right radius here.\n" + "          Radius: " + (defaultRadius <= 0 ? "-1" : defaultRadius) + // Essentials use radius 0 for global.
        "\n" + "          # Essentials makes so only players with this permission receives the message.\n" + "          Permission To Listen: 'essentials.chat.receive.local'\n" + "        Sound: ENTITY_ITEM_PICKUP\n" + "    Chat Words: # Like for VentureChat, you can assign a sound to a word aswell.\n" + "      pling:\n" + "        Enabled: true\n" + "        Sounds:\n" + "          '1':\n" + "            Sound: BLOCK_NOTE_BLOCK_PLING\n";
        if (defaultRadius > 0) {
            data = data + "      can you hear me: # A useful sound so players can know if they are near each other.\n" + "        Enabled: true\n" + "        Prevent Other Sounds: # Like in VentureChat you can prevent Chat Sound and Other Chat Words sounds.\n" + "          Chat Sound: true\n" + "        Sounds:\n" + "          '1':\n" + "            Options:\n" + "              Radius: " + (defaultRadius / 2.0) + "\n" + "            Pitch: 1.3\n" + "            Sound: ENTITY_VILLAGER_TRADE\n";
        }
        data = data + "\n" + "  shout: # When players send messages starting with !, this channel is heard by everyone.\n" + "    Enabled: true\n" + "    Sounds:\n" + "      '1':\n" + "        Options:\n" + "          Radius: -1\n" + "          Permission To Listen: 'essentials.chat.receive.shout'\n" + "        Sound: ENTITY_ITEM_PICKUP\n" + "\n" + "  question: # When players send messages starting with ?, this channel is heard by everyone.\n" + "    Enabled: true\n" + "    Sounds:\n" + "      '1':\n" + "        Options:\n" + "          Radius: -1\n" + "          Permission To Listen: 'essentials.chat.receive.question'\n" + "        Sound: ENTITY_VILLAGER_TRADE\n";
        try {
            PathUtils.write(data, ChannelsHandlerAddon.CHANNELS_CONFIG.getPath());
            logger.log("&eAdded default EssentialsChat sound to channels.yml");
            Configurations.getConfigurationLoader().loadConfigurations();
        } catch (IOException e) {
            logger.log("[EssentialsChat Hook] Failed to add defaults to channels.yml configuration. You can find a tutorial on how to set a channel sound in PlayMoreSounds's forums: https://playmoresounds.freeforums.net/thread/27/essentialschat-hook", ConsoleLogger.Level.WARN);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Listener(org.bukkit.event.Listener) RegisteredListener(org.bukkit.plugin.RegisteredListener) EssentialsChatPlayerListenerLowest(com.earth2me.essentials.chat.EssentialsChatPlayerListenerLowest) IOException(java.io.IOException) Logger(com.epicnicity322.epicpluginlib.bukkit.logger.Logger) ConsoleLogger(com.epicnicity322.epicpluginlib.core.logger.ConsoleLogger) NotNull(org.jetbrains.annotations.NotNull) IOException(java.io.IOException) PluginManager(org.bukkit.plugin.PluginManager) Field(java.lang.reflect.Field) ChannelsHandler(com.epicnicity322.channelshandler.ChannelsHandler) RegisteredListener(org.bukkit.plugin.RegisteredListener)

Example 2 with ChannelsHandler

use of com.epicnicity322.channelshandler.ChannelsHandler in project PlayMoreSounds by Epicnicity322.

the class UltimateChatHook method onStart.

@Override
protected void onStart() {
    Logger logger = PlayMoreSounds.getConsoleLogger();
    if (!Bukkit.getPluginManager().isPluginEnabled("UltimateChat")) {
        logger.log("[UltimateChat Hook] Addon could not be started because UltimateChat plugin failed to enable.", ConsoleLogger.Level.ERROR);
        PlayMoreSounds.getAddonManager().stopAddon(this);
        return;
    }
    handler = new ChannelsHandler("UltimateChat", this, new ChannelsHandler.ChannelSoundPreventer() {

        @Override
        protected boolean preventReceivingSound(@NotNull Player receiver, @NotNull Player chatter, @NotNull String channel) {
            Set<CommandSender> receiverSet = receivers.get(chatter);
            if (receiverSet == null)
                return false;
            return !receiverSet.contains(receiver);
        }
    });
    // Appending defaults to channels.yml
    if (!ChannelsHandlerAddon.CHANNELS_CONFIG.getConfiguration().contains("UltimateChat")) {
        String data = "\n\nUltimateChat:\n" + "  Local: # This is the local channel, only people nearby can hear it.\n" + "    Enabled: true\n" + "    Cancellable: true # Other plugins might cancel the chat event.\n" + "    Sounds:\n" + "      '1':\n" + "        Options:\n" + "          Radius: 40\n" + "        Sound: ENTITY_ITEM_PICKUP\n" + "    Chat Words: # Like for VentureChat, you can assign a sound to a word as well.\n" + "      pling:\n" + "        Enabled: true\n" + "        Cancellable: true\n" + "        Sounds:\n" + "          '1':\n" + "            Options:\n" + "              Radius: 40\n" + "            Sound: BLOCK_NOTE_BLOCK_PLING\n" + "      can you hear me: # A useful sound so players can know if they are near each other.\n" + "        Enabled: true\n" + "        Cancellable: true\n" + "        Prevent Other Sounds: # Like in VentureChat you can prevent Chat Sound and Other Chat Words sounds.\n" + "          Chat Sound: true\n" + "        Sounds:\n" + "          '1':\n" + "            Options:\n" + "              Radius: 20\n" + "            Sound: ENTITY_VILLAGER_TRADE\n" + "\n" + "  Global:\n" + "    Enabled: true\n" + "    Cancellable: true\n" + "    Sounds:\n" + "      '1':\n" + "        Options:\n" + "          Radius: -1\n" + "        Sound: ENTITY_ITEM_PICKUP";
        try {
            PathUtils.write(data, ChannelsHandlerAddon.CHANNELS_CONFIG.getPath());
            logger.log("&eAdded default UltimateChat sound to channels.yml");
            Configurations.getConfigurationLoader().loadConfigurations();
        } catch (IOException e) {
            logger.log("[UltimateChat Hook] Failed to add defaults to channels.yml configuration. You can find a tutorial on how to set a channel sound in PlayMoreSounds's forums: https://playmoresounds.freeforums.net/thread/30/ultimatechat-hook", ConsoleLogger.Level.WARN);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ChannelsHandler(com.epicnicity322.channelshandler.ChannelsHandler) CommandSender(org.bukkit.command.CommandSender) IOException(java.io.IOException) ConsoleLogger(com.epicnicity322.epicpluginlib.core.logger.ConsoleLogger) Logger(com.epicnicity322.epicpluginlib.bukkit.logger.Logger) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ChannelsHandler

use of com.epicnicity322.channelshandler.ChannelsHandler in project PlayMoreSounds by Epicnicity322.

the class VentureChatHook method onStart.

@Override
protected void onStart() {
    if (!Bukkit.getPluginManager().isPluginEnabled("VentureChat")) {
        PlayMoreSounds.getConsoleLogger().log("[VentureChat Hook] Addon could not be started because VentureChat plugin failed to enable.", ConsoleLogger.Level.ERROR);
        PlayMoreSounds.getAddonManager().stopAddon(this);
        return;
    }
    handler = new ChannelsHandler("VentureChat", this, new ChannelsHandler.ChannelSoundPreventer() {

        @Override
        protected boolean preventReceivingSound(@NotNull Player receiver, @NotNull Player chatter, @NotNull String channel) {
            MineverseChatPlayer mcp = MineverseChatAPI.getMineverseChatPlayer(receiver);
            return !mcp.isListening(channel) || mcp.getIgnores().contains(chatter.getUniqueId());
        }
    });
}
Also used : MineverseChatPlayer(mineverse.Aust1n46.chat.api.MineverseChatPlayer) Player(org.bukkit.entity.Player) ChannelsHandler(com.epicnicity322.channelshandler.ChannelsHandler) MineverseChatPlayer(mineverse.Aust1n46.chat.api.MineverseChatPlayer) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ChannelsHandler (com.epicnicity322.channelshandler.ChannelsHandler)3 Player (org.bukkit.entity.Player)3 NotNull (org.jetbrains.annotations.NotNull)3 Logger (com.epicnicity322.epicpluginlib.bukkit.logger.Logger)2 ConsoleLogger (com.epicnicity322.epicpluginlib.core.logger.ConsoleLogger)2 IOException (java.io.IOException)2 EssentialsChatPlayerListenerLowest (com.earth2me.essentials.chat.EssentialsChatPlayerListenerLowest)1 Field (java.lang.reflect.Field)1 MineverseChatPlayer (mineverse.Aust1n46.chat.api.MineverseChatPlayer)1 CommandSender (org.bukkit.command.CommandSender)1 Listener (org.bukkit.event.Listener)1 PluginManager (org.bukkit.plugin.PluginManager)1 RegisteredListener (org.bukkit.plugin.RegisteredListener)1