allow for all mcmmo versions 3.4.1
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'sh.okx'
|
group 'sh.okx'
|
||||||
version '3.4'
|
version '3.4.1'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package sh.okx.rankup;
|
package sh.okx.rankup;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
@@ -47,6 +46,7 @@ import sh.okx.rankup.requirements.requirement.advancedachievements.AdvancedAchie
|
|||||||
import sh.okx.rankup.requirements.requirement.advancedachievements.AdvancedAchievementsTotalRequirement;
|
import sh.okx.rankup.requirements.requirement.advancedachievements.AdvancedAchievementsTotalRequirement;
|
||||||
import sh.okx.rankup.requirements.requirement.mcmmo.McMMOPowerLevelRequirement;
|
import sh.okx.rankup.requirements.requirement.mcmmo.McMMOPowerLevelRequirement;
|
||||||
import sh.okx.rankup.requirements.requirement.mcmmo.McMMOSkillRequirement;
|
import sh.okx.rankup.requirements.requirement.mcmmo.McMMOSkillRequirement;
|
||||||
|
import sh.okx.rankup.requirements.requirement.mcmmo.McMMOSkillUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@@ -219,14 +219,16 @@ public class Rankup extends JavaPlugin {
|
|||||||
|
|
||||||
private void registerRequirements() {
|
private void registerRequirements() {
|
||||||
requirementRegistry = new RequirementRegistry();
|
requirementRegistry = new RequirementRegistry();
|
||||||
|
if (economy != null) {
|
||||||
requirementRegistry.addRequirement(new MoneyRequirement(this));
|
requirementRegistry.addRequirement(new MoneyRequirement(this));
|
||||||
|
}
|
||||||
requirementRegistry.addRequirement(new XpLevelRequirement(this));
|
requirementRegistry.addRequirement(new XpLevelRequirement(this));
|
||||||
requirementRegistry.addRequirement(new PlaytimeMinutesRequirement(this));
|
requirementRegistry.addRequirement(new PlaytimeMinutesRequirement(this));
|
||||||
requirementRegistry.addRequirement(new GroupRequirement(this));
|
requirementRegistry.addRequirement(new GroupRequirement(this));
|
||||||
requirementRegistry.addRequirement(new PermissionRequirement(this));
|
requirementRegistry.addRequirement(new PermissionRequirement(this));
|
||||||
requirementRegistry.addRequirement(new PlaceholderRequirement(this));
|
requirementRegistry.addRequirement(new PlaceholderRequirement(this));
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
|
||||||
for (PrimarySkillType skill : PrimarySkillType.values()) {
|
for (String skill : McMMOSkillUtil.getInstance().getSkills()) {
|
||||||
requirementRegistry.addRequirement(new McMMOSkillRequirement(this, skill));
|
requirementRegistry.addRequirement(new McMMOSkillRequirement(this, skill));
|
||||||
}
|
}
|
||||||
requirementRegistry.addRequirement(new McMMOPowerLevelRequirement(this));
|
requirementRegistry.addRequirement(new McMMOPowerLevelRequirement(this));
|
||||||
|
|||||||
+4
-6
@@ -1,16 +1,14 @@
|
|||||||
package sh.okx.rankup.requirements.requirement.mcmmo;
|
package sh.okx.rankup.requirements.requirement.mcmmo;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import sh.okx.rankup.Rankup;
|
import sh.okx.rankup.Rankup;
|
||||||
import sh.okx.rankup.requirements.Requirement;
|
import sh.okx.rankup.requirements.Requirement;
|
||||||
|
|
||||||
public class McMMOSkillRequirement extends Requirement {
|
public class McMMOSkillRequirement extends Requirement {
|
||||||
private PrimarySkillType skill;
|
private String skill;
|
||||||
|
|
||||||
public McMMOSkillRequirement(Rankup plugin, PrimarySkillType skill) {
|
public McMMOSkillRequirement(Rankup plugin, String skill) {
|
||||||
super(plugin, "mcmmo-" + skill.toString().toLowerCase());
|
super(plugin, "mcmmo-" + skill.toLowerCase());
|
||||||
this.skill = skill;
|
this.skill = skill;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +24,7 @@ public class McMMOSkillRequirement extends Requirement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRemaining(Player player) {
|
public double getRemaining(Player player) {
|
||||||
return Math.max(0, getValueInt() - UserManager.getPlayer(player).getSkillLevel(skill));
|
return Math.max(0, getValueInt() - McMMOSkillUtil.getInstance().getSkillLevel(player, skill));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package sh.okx.rankup.requirements.requirement.mcmmo;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Because mcMMO like changing the name of their skill types.
|
||||||
|
* Singleton (not thread safe!) class to access different mcMMO versions.
|
||||||
|
*/
|
||||||
|
public class McMMOSkillUtil {
|
||||||
|
private static McMMOSkillUtil instance;
|
||||||
|
|
||||||
|
private Class<?> skillTypeClass;
|
||||||
|
private Method values;
|
||||||
|
private Method valueOf;
|
||||||
|
//private Class<?> userManagerClass;
|
||||||
|
private Method getSkillLevel;
|
||||||
|
|
||||||
|
private McMMOSkillUtil() {
|
||||||
|
final String pckg = "com.gmail.nossr50.datatypes.skills.";
|
||||||
|
try {
|
||||||
|
skillTypeClass = Class.forName(pckg + "PrimarySkillType");
|
||||||
|
} catch (ClassNotFoundException e0) {
|
||||||
|
try {
|
||||||
|
skillTypeClass = Class.forName(pckg + "PrimarySkill");
|
||||||
|
} catch (ClassNotFoundException e1) {
|
||||||
|
try {
|
||||||
|
skillTypeClass = Class.forName(pckg + "SkillType");
|
||||||
|
} catch (ClassNotFoundException e2) {
|
||||||
|
throw new RuntimeException("mcMMO Skill Type class not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
values = skillTypeClass.getMethod("values");
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException("mcMMO " + skillTypeClass + ".values() not found");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
valueOf = skillTypeClass.getMethod("valueOf", String.class);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException("mcMMO" + skillTypeClass + ".valueOf(String) not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*try {
|
||||||
|
userManagerClass = Class.forName("com.gmail.nossr50.util.player.UserManager");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException("mcMMO UserManager class not found");
|
||||||
|
}*/
|
||||||
|
try {
|
||||||
|
getSkillLevel = McMMOPlayer.class.getMethod("getSkillLevel", skillTypeClass);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException("mcMMO UserManager.getSkillLevel(" + skillTypeClass + ") not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static McMMOSkillUtil getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new McMMOSkillUtil();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getSkills() {
|
||||||
|
try {
|
||||||
|
Enum<?>[] skills = (Enum<?>[]) values.invoke(null);
|
||||||
|
String[] stringSkills = new String[skills.length];
|
||||||
|
for (int i = 0; i < skills.length; i++) {
|
||||||
|
stringSkills[i] = skills[i].name();
|
||||||
|
}
|
||||||
|
return stringSkills;
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSkillLevel(Player player, String skill) {
|
||||||
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
try {
|
||||||
|
Object skillType = skillTypeClass.cast(valueOf.invoke(null, skill));
|
||||||
|
return (int) getSkillLevel.invoke(mcMMOPlayer, skillType);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
name: Rankup
|
name: Rankup
|
||||||
version: 3.4
|
version: 3.4.1
|
||||||
main: sh.okx.rankup.Rankup
|
main: sh.okx.rankup.Rankup
|
||||||
author: Okx
|
author: Okx
|
||||||
depend: [Vault]
|
depend: [Vault]
|
||||||
|
|||||||
Reference in New Issue
Block a user