Bug fix with the 'Workbench only' upgrade option

This commit is contained in:
Jules 2021-07-24 22:32:26 +02:00
parent e791926ddb
commit 317bd675e3
2 changed files with 56 additions and 36 deletions

View File

@ -1,51 +1,68 @@
package net.Indyuce.mmoitems.comp.rpg; package net.Indyuce.mmoitems.comp.rpg;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.comp.mmocore.MMOCoreHook; import net.Indyuce.mmoitems.comp.mmocore.MMOCoreHook;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
public interface RPGHandler { public interface RPGHandler {
RPGPlayer getInfo(PlayerData data);
void refreshStats(PlayerData data); /**
* A RPGPlayer is a class used to retrieve all the rpg
* information of a player, like its class, level, mana
* stamina. It's also used to give or take mana/stamina
* to handle ability costs.
*
* @param data Player to retrieve rpg info from
* @return A new RPGPlayer for the given player
*/
RPGPlayer getInfo(PlayerData data);
enum PluginEnum { /**
MMOCORE("MMOCore", MMOCoreHook.class), * Called everytime the player's inventory updates. This
HEROES("Heroes", HeroesHook.class), * method should update the rpg stats like Max Mana which
SKILLAPI("SkillAPI", SkillAPIHook.class), * are normally given by items.
RPGPLAYERLEVELING("RPGPlayerLeveling", RPGPlayerLevelingHook.class), *
RACESANDCLASSES("RacesAndClasses", RacesAndClassesHook.class), * @param data Player to update
BATTLELEVELS("BattleLevels", BattleLevelsHook.class), */
MCMMO("mcMMO", McMMOHook.class), void refreshStats(PlayerData data);
MCRPG("McRPG", McRPGHook.class),
SKILLS("Skills", SkillsHook.class),
AURELIUM_SKILLS("AureliumSkills", AureliumSkillsHook.class),
SKILLSPRO("SkillsPro", SkillsProHook.class);
private final Class<? extends RPGHandler> pluginClass; enum PluginEnum {
private final String name; MMOCORE("MMOCore", MMOCoreHook.class),
HEROES("Heroes", HeroesHook.class),
SKILLAPI("SkillAPI", SkillAPIHook.class),
RPGPLAYERLEVELING("RPGPlayerLeveling", RPGPlayerLevelingHook.class),
RACESANDCLASSES("RacesAndClasses", RacesAndClassesHook.class),
BATTLELEVELS("BattleLevels", BattleLevelsHook.class),
MCMMO("mcMMO", McMMOHook.class),
MCRPG("McRPG", McRPGHook.class),
SKILLS("Skills", SkillsHook.class),
AURELIUM_SKILLS("AureliumSkills", AureliumSkillsHook.class),
SKILLSPRO("SkillsPro", SkillsProHook.class);
PluginEnum(String name, Class<? extends RPGHandler> pluginClass) { private final Class<? extends RPGHandler> pluginClass;
this.pluginClass = pluginClass; private final String name;
this.name = name;
}
public RPGHandler load() { PluginEnum(String name, Class<? extends RPGHandler> pluginClass) {
try { this.pluginClass = pluginClass;
return pluginClass.getDeclaredConstructor().newInstance(); this.name = name;
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException exception) { }
MMOItems.plugin.getLogger().log(Level.WARNING,
"Could not initialize RPG plugin compatibility with " + name + ": " + exception.getMessage());
return new DefaultHook();
}
}
public String getName() { public RPGHandler load() {
return name; try {
} return pluginClass.getDeclaredConstructor().newInstance();
} } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING,
"Could not initialize RPG plugin compatibility with " + name + ": " + exception.getMessage());
return new DefaultHook();
}
}
public String getName() {
return name;
}
}
} }

View File

@ -178,6 +178,9 @@ public class UpgradeStat extends ItemStat implements ConsumableItemInteraction {
MMOItem targetMMO = new LiveMMOItem(target); MMOItem targetMMO = new LiveMMOItem(target);
UpgradeData targetSharpening = (UpgradeData) targetMMO.getData(ItemStats.UPGRADE); UpgradeData targetSharpening = (UpgradeData) targetMMO.getData(ItemStats.UPGRADE);
if (targetSharpening.isWorkbench())
return false;
if (!targetSharpening.canLevelUp()) { if (!targetSharpening.canLevelUp()) {
Message.MAX_UPGRADES_HIT.format(ChatColor.RED).send(player); Message.MAX_UPGRADES_HIT.format(ChatColor.RED).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);