mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-24 15:01:44 +01:00
Another big AbilityManager improvement
Added /mi list tpability - Shows all third party abilities added into MI. - Fixed the API for third party plugins to even add custom abilities into MI and added a new method for doing so with console messages when they get added with the providing plugin name. - We also now check if the ability being registered is already registered to avoid multiple abilities. - We now get the Abilities internal registered name in case they aren't in the language config as well. This will always be the case with third party added abilities.
This commit is contained in:
parent
6fc6daf1c1
commit
3905f70787
@ -14,6 +14,7 @@ public class ListCommandTreeNode extends CommandTreeNode {
|
||||
addChild(new AbilityCommandTreeNode(this));
|
||||
addChild(new MIAbilityCommandTreeNode(this));
|
||||
addChild(new MMAbilityCommandTreeNode(this));
|
||||
addChild(new TPAbilityCommandTreeNode(this));
|
||||
addChild(new LuteAttackCommandTreeNode(this));
|
||||
addChild(new StaffSpiritCommandTreeNode(this));
|
||||
addChild(new TypeCommandTreeNode(this));
|
||||
@ -29,6 +30,7 @@ public class ListCommandTreeNode extends CommandTreeNode {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi list ability " + ChatColor.WHITE + "shows all available abilities");
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi list miability " + ChatColor.WHITE + "shows all available MMOItems abilities");
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi list mmability " + ChatColor.WHITE + "shows all available MythicMobs abilities");
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi list tpability " + ChatColor.WHITE + "shows all available Third Party abilities");
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("Spigot Javadoc Links:");
|
||||
|
@ -0,0 +1,29 @@
|
||||
package net.Indyuce.mmoitems.command.mmoitems.list;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
import net.mmogroup.mmolib.command.api.CommandTreeNode;
|
||||
|
||||
public class TPAbilityCommandTreeNode extends CommandTreeNode {
|
||||
public TPAbilityCommandTreeNode(CommandTreeNode parent) {
|
||||
super(parent, "tpability");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Third Party Abilities "
|
||||
+ ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
|
||||
sender.sendMessage(ChatColor.WHITE + "Here are all the abilities you can bind to items.");
|
||||
sender.sendMessage(ChatColor.WHITE + "The values inside brackets are " + ChatColor.UNDERLINE + "modifiers" + ChatColor.WHITE
|
||||
+ " which allow you to change the ability values (cooldown, damage...)");
|
||||
for (Ability a : MMOItems.plugin.getAbilities().getAllThirdPartyAbilities()) {
|
||||
String modFormat = ChatColor.GRAY + String.join(ChatColor.WHITE + ", " + ChatColor.GRAY, a.getModifiers());
|
||||
modFormat = ChatColor.WHITE + "(" + modFormat + ChatColor.WHITE + ")";
|
||||
sender.sendMessage("* " + ChatColor.LIGHT_PURPLE + a.getName() + " " + modFormat);
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ability.Ability;
|
||||
@ -21,10 +22,13 @@ import net.Indyuce.mmoitems.comp.mythicmobs.MythicMobsAbility;
|
||||
public class AbilityManager {
|
||||
// All abilities
|
||||
private final Map<String, Ability> abilities = new HashMap<>();
|
||||
|
||||
// Abilities from MMOItems
|
||||
private final Map<String, Ability> miAbilities = new HashMap<>();
|
||||
// Abilities from MythicMobs
|
||||
private final Map<String, Ability> mmAbilities = new HashMap<>();
|
||||
// Abilities from ThirdParty plugins
|
||||
private final Map<String, Ability> tpAbilities = new HashMap<>();
|
||||
|
||||
private boolean registrationIsDone = false;
|
||||
|
||||
@ -46,7 +50,7 @@ public class AbilityManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns all known abilities, both from MI and MM.
|
||||
* @return Returns all known abilities, both from MI, MM and Third Party plugins.
|
||||
*/
|
||||
public Collection<Ability> getAllAbilities() {
|
||||
return abilities.values();
|
||||
@ -66,29 +70,78 @@ public class AbilityManager {
|
||||
return mmAbilities.values();
|
||||
}
|
||||
|
||||
public void registerAbility(Ability ability, boolean mmSkill) {
|
||||
if (registrationIsDone) {
|
||||
MMOItems.plugin.getLogger().log(Level.INFO,
|
||||
/**
|
||||
* @return Returns all known THIRD PARTY abilities.
|
||||
*/
|
||||
public Collection<Ability> getAllThirdPartyAbilities() {
|
||||
return tpAbilities.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom ability into MMOItems.
|
||||
* Used for Third Party abilities only.
|
||||
*
|
||||
* @param ability - A class that extends {@link Ability}
|
||||
*/
|
||||
public void registerAbility(Ability ability) {
|
||||
if (registerAbility(ability, false, true))
|
||||
MMOItems.plugin.getLogger().log(Level.INFO, "Loaded third party ability: " + ability.getName() + " from " + JavaPlugin.getProvidingPlugin(ability.getClass()).getName() + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom abilities into MMOItems.
|
||||
* Used for Third Party abilities only.
|
||||
* Same as {@link #registerAbility(Ability ability)}
|
||||
* but for multiple abilities.
|
||||
*
|
||||
* @param ability - A class that extends {@link Ability}
|
||||
*/
|
||||
public void registerAbilities(Ability... abilities) {
|
||||
int count = 0;
|
||||
for (Ability ability : abilities) {
|
||||
if (!registerAbility(ability, false, true))
|
||||
continue;
|
||||
count++;
|
||||
}
|
||||
|
||||
MMOItems.plugin.getLogger().log(Level.INFO, "Loaded " + count + " third party abilities from " + JavaPlugin.getProvidingPlugin(abilities[0].getClass()).getName() + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Used only internally.
|
||||
*/
|
||||
protected boolean registerAbility(Ability ability, boolean fromMM, boolean fromTP) {
|
||||
if (registrationIsDone && !fromTP) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING,
|
||||
"Failed attempt to register ability " + ability.getID() + ". Make sure abilities are registered when MI is loading.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ability.isEnabled()) {
|
||||
MMOItems.plugin.getLogger().log(Level.INFO, "Cannot register disabled ability " + ability.getID() + ".");
|
||||
return;
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Cannot register disabled ability " + ability.getID() + ".");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasAbility(ability.getID())) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Ability " + ability.getID() + " is already registered!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ability instanceof Listener)
|
||||
Bukkit.getPluginManager().registerEvents((Listener) ability, MMOItems.plugin);
|
||||
|
||||
// Add to MM or MI ability list
|
||||
if (mmSkill)
|
||||
// Add to MM/MI or TP ability list
|
||||
if (fromTP)
|
||||
tpAbilities.put(ability.getID(), ability);
|
||||
else if (fromMM)
|
||||
mmAbilities.put(ability.getID(), ability);
|
||||
else
|
||||
miAbilities.put(ability.getID(), ability);
|
||||
|
||||
// Add to all ability list
|
||||
abilities.put(ability.getID(), ability);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
@ -100,7 +153,7 @@ public class AbilityManager {
|
||||
if (!name.contains("$") && name.endsWith(".class") && name.startsWith("net.Indyuce.mmoitems.ability.")) {
|
||||
Ability ability = (Ability) Class.forName(name.substring(0, name.length() - 6)).newInstance();
|
||||
if (ability.isEnabled())
|
||||
registerAbility(ability, false);
|
||||
registerAbility(ability, false, false);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
@ -118,7 +171,7 @@ public class AbilityManager {
|
||||
for (File file : mythicMobs.listFiles()) {
|
||||
try {
|
||||
registerAbility(new MythicMobsAbility(file.getName().substring(0, file.getName().length() - 4),
|
||||
YamlConfiguration.loadConfiguration(file)), true);
|
||||
YamlConfiguration.loadConfiguration(file)), true, false);
|
||||
count++;
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load ability from " + file.getName() + ": " + exception.getMessage());
|
||||
|
@ -222,7 +222,8 @@ public class ConfigManager implements Reloadable {
|
||||
}
|
||||
|
||||
public String getAbilityName(Ability ability) {
|
||||
return abilities.getConfig().getString("ability." + ability.getLowerCaseID());
|
||||
String configName = abilities.getConfig().getString("ability." + ability.getLowerCaseID());
|
||||
return configName != null ? configName : ability.getName();
|
||||
}
|
||||
|
||||
public String getCastingModeName(CastingMode mode) {
|
||||
|
Loading…
Reference in New Issue
Block a user