Search in sources :

Example 41 with ICombatLogX

use of com.github.sirblobman.combatlogx.api.ICombatLogX in project CombatLogX by SirBlobman.

the class ExpansionManager method enableExpansion.

public void enableExpansion(Expansion expansion) {
    State state = expansion.getState();
    if (state == State.ENABLED)
        return;
    ICombatLogX plugin = getPlugin();
    Logger logger = plugin.getLogger();
    try {
        ExpansionDescription description = expansion.getDescription();
        String fullName = description.getFullName();
        logger.info("Enabling expansion '" + fullName + "'...");
        expansion.setState(State.ENABLED);
        expansion.onEnable();
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "An error occurred while enabling an expansion:", ex);
    }
}
Also used : State(com.github.sirblobman.combatlogx.api.expansion.Expansion.State) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Logger(java.util.logging.Logger) IOException(java.io.IOException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 42 with ICombatLogX

use of com.github.sirblobman.combatlogx.api.ICombatLogX in project CombatLogX by SirBlobman.

the class ExpansionManager method disableExpansion.

public void disableExpansion(Expansion expansion) {
    State state = expansion.getState();
    if (state != State.ENABLED)
        return;
    ICombatLogX plugin = getPlugin();
    Logger logger = plugin.getLogger();
    try {
        ExpansionDescription description = expansion.getDescription();
        String fullName = description.getFullName();
        logger.info("Disabling expansion '" + fullName + "'...");
        List<Listener> listenerList = expansion.getListeners();
        listenerList.forEach(HandlerList::unregisterAll);
        listenerList.clear();
        expansion.setState(State.DISABLED);
        expansion.onDisable();
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "An error occurred while enabling an expansion:", ex);
    }
}
Also used : HandlerList(org.bukkit.event.HandlerList) Listener(org.bukkit.event.Listener) State(com.github.sirblobman.combatlogx.api.expansion.Expansion.State) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Logger(java.util.logging.Logger) IOException(java.io.IOException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 43 with ICombatLogX

use of com.github.sirblobman.combatlogx.api.ICombatLogX in project CombatLogX by SirBlobman.

the class RegionExpansion method onEnable.

@Override
public final void onEnable() {
    ICombatLogX plugin = getPlugin();
    if (!checkDependencies()) {
        Logger logger = getLogger();
        logger.info("Some dependencies for this expansion are missing!");
        ExpansionManager expansionManager = plugin.getExpansionManager();
        expansionManager.disableExpansion(this);
        return;
    }
    new RegionMoveListener(this).register();
    new RegionVulnerableListener(this).register();
    this.enabledSuccessfully = true;
    afterEnable();
}
Also used : ExpansionManager(com.github.sirblobman.combatlogx.api.expansion.ExpansionManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Logger(java.util.logging.Logger)

Example 44 with ICombatLogX

use of com.github.sirblobman.combatlogx.api.ICombatLogX in project CombatLogX by SirBlobman.

the class RegionHandler method sendEntryDeniedMessage.

public final void sendEntryDeniedMessage(Player player, LivingEntity enemy) {
    if (player == null)
        return;
    TagType tagType = getTagType(enemy);
    String messagePath = getEntryDeniedMessagePath(tagType);
    if (messagePath == null)
        return;
    UUID playerId = player.getUniqueId();
    if (this.cooldownMap.containsKey(playerId)) {
        long expireMillis = this.cooldownMap.getOrDefault(playerId, 0L);
        long systemMillis = System.currentTimeMillis();
        if (systemMillis < expireMillis)
            return;
    }
    ICombatLogX plugin = this.expansion.getPlugin();
    String message = plugin.getMessageWithPrefix(player, messagePath, null, true);
    plugin.sendMessage(player, message);
    long cooldownSeconds = getEntryDeniedMessageCooldown();
    long cooldownMillis = TimeUnit.SECONDS.toMillis(cooldownSeconds);
    long systemMillis = System.currentTimeMillis();
    long expireMillis = (systemMillis + cooldownMillis);
    this.cooldownMap.put(playerId, expireMillis);
}
Also used : TagType(com.github.sirblobman.combatlogx.api.object.TagType) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) UUID(java.util.UUID)

Example 45 with ICombatLogX

use of com.github.sirblobman.combatlogx.api.ICombatLogX in project CombatLogX by SirBlobman.

the class RegionMoveListener method onMove.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onMove(PlayerMoveEvent e) {
    Location toLocation = e.getTo();
    if (toLocation == null) {
        return;
    }
    Player player = e.getPlayer();
    ICombatLogX combatLogX = getCombatLogX();
    ICombatManager combatManager = combatLogX.getCombatManager();
    if (!combatManager.isInCombat(player)) {
        return;
    }
    LivingEntity enemy = combatManager.getEnemy(player);
    TagType tagType = getTagType(enemy);
    RegionHandler regionHandler = getRegionHandler();
    if (regionHandler.isSafeZone(player, toLocation, tagType)) {
        Location fromLocation = e.getFrom();
        if (!regionHandler.isSafeZone(player, fromLocation, tagType)) {
            regionHandler.preventEntry(e, player, fromLocation, toLocation);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) TagType(com.github.sirblobman.combatlogx.api.object.TagType) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)96 ExpansionManager (com.github.sirblobman.combatlogx.api.expansion.ExpansionManager)24 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)19 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)19 Player (org.bukkit.entity.Player)18 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)14 LivingEntity (org.bukkit.entity.LivingEntity)13 LanguageManager (com.github.sirblobman.api.language.LanguageManager)12 Logger (java.util.logging.Logger)11 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)10 MultiVersionHandler (com.github.sirblobman.api.nms.MultiVersionHandler)9 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)8 Expansion (com.github.sirblobman.combatlogx.api.expansion.Expansion)8 List (java.util.List)8 Replacer (com.github.sirblobman.api.language.Replacer)6 EntityHandler (com.github.sirblobman.api.nms.EntityHandler)5 State (com.github.sirblobman.combatlogx.api.expansion.Expansion.State)5 Collections (java.util.Collections)5 EventHandler (org.bukkit.event.EventHandler)5 NewbieHelperExpansion (combatlogx.expansion.newbie.helper.NewbieHelperExpansion)4