Skip to content

Commit

Permalink
Add support for CMI and checking its API for AFK
Browse files Browse the repository at this point in the history
  • Loading branch information
Staartvin committed Dec 2, 2019
1 parent 744d274 commit c435bf7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@
<version>2.5.3</version>
</dependency>

<dependency>
<groupId>com.Zrips.CMI</groupId>
<artifactId>CMI</artifactId>
<version>7.1.3.0</version>
</dependency>


<!-- Test dependencies -->

Expand Down
4 changes: 3 additions & 1 deletion src/me/staartvin/plugins/pluginlibrary/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public enum Library {
QUESTS_ALTERNATIVE("Quests", new QuestsAlternative(), "LMBishop", "com.leonardobishop.quests.Quests"),
SAVAGE_FACTIONS("Factions", "SavageFactions", new SavageFactionsHook(), "ProSavage", "com.massivecraft.factions.SavageFactions"),
PLAYERPOINTS("PlayerPoints", new PlayerPointsHook(), "Blackixx"),
NUVOTIFIER("Votifier", "NuVotifier", new NuVotifierHook(), "Ichbinjoe", "com.vexsoftware.votifier.NuVotifierBukkit");
NUVOTIFIER("Votifier", "NuVotifier", new NuVotifierHook(), "Ichbinjoe", "com.vexsoftware.votifier" +
".NuVotifierBukkit"),
CMI("CMI", new CMIHook(), "Zrips");

private String internalPluginName, humanPluginName, authorName, mainClass;
private LibraryHook hook;
Expand Down
59 changes: 59 additions & 0 deletions src/me/staartvin/plugins/pluginlibrary/hooks/CMIHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package me.staartvin.plugins.pluginlibrary.hooks;

import com.Zrips.CMI.CMI;
import com.Zrips.CMI.Containers.CMIUser;
import me.staartvin.plugins.pluginlibrary.Library;

import java.util.UUID;

/**
* CMI library,
* <a href="https://www.spigotmc.org/resources/cmi-270-commands-insane-kits-portals-essentials-economy-mysql-sqlite-much-more.3742/">link</a>.
* <p>
*
* @author Staartvin
*
*/
public class CMIHook extends LibraryHook {

/*
* (non-Javadoc)
*
* @see me.staartvin.plugins.pluginlibrary.hooks.LibraryHook#isAvailable()
*/
@Override
public boolean isAvailable() {
return this.getPlugin().getServer().getPluginManager().isPluginEnabled(Library.CMI.getInternalPluginName());
}

/*
* (non-Javadoc)
*
* @see me.staartvin.plugins.pluginlibrary.hooks.LibraryHook#hook()
*/
@Override
public boolean hook() {
// All api calls are done static, so there is no need to get the plugin
// class.
// We only check if the plugin is available.
return isAvailable();
}

/**
* Check whether a user is AFK or not.
*
* @param uuid
* UUID of the player to check.
* @return true if the user is AFK, false otherwise.
*/
public boolean isAFK(UUID uuid) {
if (!this.isAvailable()) return false;

CMIUser user = CMI.getInstance().getPlayerManager().getUser(uuid);

if (user == null) return false;

return user.isAfk();
}

}
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ api-version: 1.14
description: Allows developers to get a lot of data from other plugins without importing the APIs themselves.
softdepend: [Autorank, Stats, mcMMO, Factions, afkTerminator, OnTime, RoyalCommands, UltimateCore, Statz,
AdvancedAchievements, BattleLevels, Jobs, RPGme, Statz, uSkyBlock, Vault, WorldEdit, WorldGuard, AcidIsland,
ASkyBlock, GriefPrevention, Essentials, Quests, PlayerPoints, Votifier]
ASkyBlock, GriefPrevention, Essentials, Quests, PlayerPoints, Votifier, CMI]

0 comments on commit c435bf7

Please sign in to comment.