Move related utility methods to dependency class

This commit is contained in:
PikaMug 2019-11-05 17:23:31 -05:00
parent cd2a52cead
commit 717b999e9b
5 changed files with 57 additions and 27 deletions

View File

@ -12,6 +12,9 @@
package me.blackvein.quests;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import me.blackvein.quests.util.DenizenAPI;
@ -27,7 +30,11 @@ import com.alessiodp.parties.api.Parties;
import com.alessiodp.parties.api.interfaces.PartiesAPI;
import com.codisimus.plugins.phatloots.PhatLoots;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.player.UserManager;
import com.herocraftonline.heroes.Heroes;
import com.herocraftonline.heroes.characters.Hero;
import de.erethon.dungeonsxl.DungeonsXL;
@ -218,4 +225,31 @@ public class Dependencies {
public boolean runDenizenScript(String scriptName, Quester quester) {
return plugin.getDenizenTrigger().runDenizenScript(scriptName, quester);
}
public int getMcmmoSkillLevel(SkillType st, String player) {
McMMOPlayer mPlayer = UserManager.getPlayer(player);
if (mPlayer == null) {
return -1;
}
return mPlayer.getProfile().getSkillLevel(st);
}
public Hero getHero(UUID uuid) {
Player p = plugin.getServer().getPlayer(uuid);
if (p == null) {
return null;
}
return heroes.getCharacterManager().getHero(p);
}
public boolean testPrimaryHeroesClass(String primaryClass, UUID uuid) {
Hero hero = getHero(uuid);
return hero.getHeroClass().getName().equalsIgnoreCase(primaryClass);
}
@SuppressWarnings("deprecation")
public boolean testSecondaryHeroesClass(String secondaryClass, UUID uuid) {
Hero hero = getHero(uuid);
return hero.getSecondClass().getName().equalsIgnoreCase(secondaryClass);
}
}

View File

@ -359,12 +359,14 @@ public class Quest {
}
}
if (reqs.getHeroesPrimaryClass() != null) {
if (plugin.testPrimaryHeroesClass(reqs.getHeroesPrimaryClass(), player.getUniqueId()) == false) {
if (plugin.getDependencies()
.testPrimaryHeroesClass(reqs.getHeroesPrimaryClass(), player.getUniqueId()) == false) {
return false;
}
}
if (reqs.getHeroesSecondaryClass() != null) {
if (plugin.testSecondaryHeroesClass(reqs.getHeroesSecondaryClass(), player.getUniqueId()) == false) {
if (plugin.getDependencies()
.testSecondaryHeroesClass(reqs.getHeroesSecondaryClass(), player.getUniqueId()) == false) {
return false;
}
}

View File

@ -72,9 +72,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.java.JavaPlugin;
import com.codisimus.plugins.phatloots.PhatLootsAPI;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.player.UserManager;
import com.herocraftonline.heroes.characters.Hero;
import com.herocraftonline.heroes.characters.classes.HeroClass;
@ -3784,30 +3782,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return false;
}
public static int getMCMMOSkillLevel(SkillType st, String player) {
McMMOPlayer mPlayer = UserManager.getPlayer(player);
if (mPlayer == null) {
return -1;
}
return mPlayer.getProfile().getSkillLevel(st);
}
/**
* @deprecated Use Dependencies.getHero(UUID)
*/
public Hero getHero(UUID uuid) {
Player p = getServer().getPlayer(uuid);
if (p == null) {
return null;
}
return depends.getHeroes().getCharacterManager().getHero(p);
return depends.getHero(uuid);
}
/**
* @deprecated Use Dependencies.testPrimaryHeroClass(String, UUID)
*/
public boolean testPrimaryHeroesClass(String primaryClass, UUID uuid) {
Hero hero = getHero(uuid);
return hero.getHeroClass().getName().equalsIgnoreCase(primaryClass);
return depends.testPrimaryHeroesClass(primaryClass, uuid);
}
@SuppressWarnings("deprecation")
/**
* @deprecated Use Dependencies.testSecondaryHeroClass(String, UUID)
*/
public boolean testSecondaryHeroesClass(String secondaryClass, UUID uuid) {
Hero hero = getHero(uuid);
return hero.getSecondClass().getName().equalsIgnoreCase(secondaryClass);
return depends.testSecondaryHeroesClass(secondaryClass, uuid);
}
}

View File

@ -2575,4 +2575,4 @@ public class ActionFactory implements ConversationAbandonedListener {
}
return null;
}
}
}

View File

@ -343,7 +343,8 @@ public class CmdExecutor implements CommandExecutor {
}
}
if (reqs.getHeroesPrimaryClass() != null) {
if (plugin.testPrimaryHeroesClass(reqs.getHeroesPrimaryClass(), player.getUniqueId())) {
if (plugin.getDependencies()
.testPrimaryHeroesClass(reqs.getHeroesPrimaryClass(), player.getUniqueId())) {
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.GREEN + reqs.getHeroesPrimaryClass()
+ ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass"));
} else {
@ -352,7 +353,8 @@ public class CmdExecutor implements CommandExecutor {
}
}
if (reqs.getHeroesSecondaryClass() != null) {
if (plugin.testSecondaryHeroesClass(reqs.getHeroesSecondaryClass(), player.getUniqueId())) {
if (plugin.getDependencies()
.testSecondaryHeroesClass(reqs.getHeroesSecondaryClass(), player.getUniqueId())) {
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.DARK_RED + reqs.getHeroesSecondaryClass()
+ ChatColor.RESET + "" + ChatColor.RED + " " + Lang.get("heroesClass"));
} else {
@ -362,7 +364,7 @@ public class CmdExecutor implements CommandExecutor {
}
if (reqs.getMcmmoSkills().isEmpty() == false) {
for (String skill : reqs.getMcmmoSkills()) {
int level = Quests.getMCMMOSkillLevel(Quests.getMcMMOSkill(skill), player.getName());
int level = plugin.getDependencies().getMcmmoSkillLevel(Quests.getMcMMOSkill(skill), player.getName());
int req = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(skill));
String skillName = MiscUtil.getCapitalized(skill);
if (level >= req) {