Search in sources :

Example 61 with PluginManager

use of org.bukkit.plugin.PluginManager in project CombatLogX by SirBlobman.

the class Expansion method checkDependency.

protected final boolean checkDependency(String pluginName, boolean checkEnabled) {
    PluginManager pluginManager = Bukkit.getPluginManager();
    Logger logger = getLogger();
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin == null) {
        logger.warning("A dependency is not installed on the server: " + pluginName);
        return false;
    }
    if (checkEnabled && !plugin.isEnabled()) {
        logger.warning("A dependency was found but it was not enabled: " + pluginName);
        return false;
    }
    PluginDescriptionFile description = plugin.getDescription();
    String fullName = description.getFullName();
    logger.info("Successfully found a dependency: " + fullName);
    return true;
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) Logger(java.util.logging.Logger) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 62 with PluginManager

use of org.bukkit.plugin.PluginManager in project CombatLogX by SirBlobman.

the class CombatManager method untag.

@Override
public void untag(Player player, UntagReason untagReason) {
    Validate.notNull(player, "player must not be null!");
    Validate.notNull(untagReason, "untagReason must not be null!");
    if (!isInCombat(player))
        return;
    UUID uuid = player.getUniqueId();
    this.combatMap.remove(uuid);
    ITimerManager timerManager = this.plugin.getTimerManager();
    timerManager.remove(player);
    LivingEntity previousEnemy = this.enemyMap.remove(uuid);
    PlayerUntagEvent event = new PlayerUntagEvent(player, untagReason, previousEnemy);
    PluginManager pluginManager = Bukkit.getPluginManager();
    pluginManager.callEvent(event);
}
Also used : ITimerManager(com.github.sirblobman.combatlogx.api.manager.ITimerManager) LivingEntity(org.bukkit.entity.LivingEntity) PluginManager(org.bukkit.plugin.PluginManager) PlayerUntagEvent(com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent) UUID(java.util.UUID)

Example 63 with PluginManager

use of org.bukkit.plugin.PluginManager in project CombatLogX by SirBlobman.

the class CombatManager method failsPreTagEvent.

private boolean failsPreTagEvent(Player player, LivingEntity enemy, TagType tagType, TagReason tagReason) {
    PlayerPreTagEvent event = new PlayerPreTagEvent(player, enemy, tagType, tagReason);
    PluginManager pluginManager = Bukkit.getPluginManager();
    pluginManager.callEvent(event);
    return event.isCancelled();
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PlayerPreTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerPreTagEvent)

Example 64 with PluginManager

use of org.bukkit.plugin.PluginManager in project CombatLogX by SirBlobman.

the class CombatManager method tag.

@Override
public boolean tag(Player player, LivingEntity enemy, TagType tagType, TagReason tagReason, long customEndMillis) {
    Validate.notNull(player, "player must not be null!");
    Validate.notNull(tagType, "tagType must not be null!");
    Validate.notNull(tagReason, "tagReason must not be null!");
    if (player.hasMetadata("NPC")) {
        return false;
    }
    if (failsPreTagEvent(player, enemy, tagType, tagReason)) {
        this.plugin.printDebug("The PlayerPreTagEvent was cancelled.");
        return false;
    }
    boolean alreadyInCombat = isInCombat(player);
    this.plugin.printDebug("Previous Combat Status: " + alreadyInCombat);
    PluginManager pluginManager = Bukkit.getPluginManager();
    if (alreadyInCombat) {
        PlayerReTagEvent event = new PlayerReTagEvent(player, enemy, tagType, tagReason, customEndMillis);
        pluginManager.callEvent(event);
        if (event.isCancelled()) {
            return false;
        }
        customEndMillis = event.getEndTime();
    } else {
        PlayerTagEvent event = new PlayerTagEvent(player, enemy, tagType, tagReason, customEndMillis);
        pluginManager.callEvent(event);
        customEndMillis = event.getEndTime();
        sendTagMessage(player, enemy, tagType, tagReason);
    }
    UUID uuid = player.getUniqueId();
    this.combatMap.put(uuid, customEndMillis);
    if (enemy != null) {
        this.enemyMap.put(uuid, enemy);
    }
    String playerName = player.getName();
    this.plugin.printDebug("Successfully put player '" + playerName + "' into combat.");
    return true;
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PlayerReTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerReTagEvent) PlayerTagEvent(com.github.sirblobman.combatlogx.api.event.PlayerTagEvent) UUID(java.util.UUID)

Example 65 with PluginManager

use of org.bukkit.plugin.PluginManager 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)

Aggregations

PluginManager (org.bukkit.plugin.PluginManager)148 Plugin (org.bukkit.plugin.Plugin)33 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)20 Permission (org.bukkit.permissions.Permission)16 MetricsWrapper (com.earth2me.essentials.metrics.MetricsWrapper)14 Player (org.bukkit.entity.Player)14 Test (org.junit.Test)13 SimplePluginManager (org.bukkit.plugin.SimplePluginManager)12 Map (java.util.Map)11 File (java.io.File)9 IOException (java.io.IOException)9 World (org.bukkit.World)9 PluginCommand (org.bukkit.command.PluginCommand)9 Command (org.bukkit.command.Command)8 Listener (org.bukkit.event.Listener)8 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)8 HashMap (java.util.HashMap)7 EventHandler (org.bukkit.event.EventHandler)7 ArrayList (java.util.ArrayList)6 Bukkit (org.bukkit.Bukkit)6