mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-11-18 06:24:17 +01:00
Fixed subclass select throwing NPE
This commit is contained in:
parent
24c1b48c3e
commit
423f0a6563
@ -98,7 +98,7 @@ public class PlayerClass implements ExperienceObject, PreloadedObject {
|
||||
public PlayerClass(String id, ConfigurationSection config) {
|
||||
postLoadAction.cacheConfig(config);
|
||||
|
||||
this.id = id.toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
this.id = UtilityMethods.enumName(id);
|
||||
|
||||
name = MythicLib.plugin.parseColors(config.getString("display.name", "INVALID DISPLAY NAME"));
|
||||
icon = Icon.from(config.get("display.item", "BARRIER")).toItem();
|
||||
|
||||
@ -8,6 +8,7 @@ import net.Indyuce.mmocore.api.ConfigMessage;
|
||||
import net.Indyuce.mmocore.api.SoundEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.ClassOption;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@ -61,7 +62,7 @@ public class SubclassSelect extends AbstractClassSelect {
|
||||
return;
|
||||
}
|
||||
|
||||
InventoryManager.CLASS_CONFIRM.get(playerClass.getId()).newInventory(inv, true).open();
|
||||
InventoryManager.CLASS_CONFIRM.get(MMOCoreUtils.ymlName(playerClass.getId())).newInventory(inv, true).open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -49,20 +50,28 @@ public class InventoryManager {
|
||||
@Deprecated
|
||||
public static final List<EditableInventory> list = LIST;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static void load() {
|
||||
//Loads the specific inventories
|
||||
for (SpecificInventoryLoader loader : SpecificInventoryLoader.values()) {
|
||||
|
||||
// Loads specific inventories
|
||||
for (var invType : InventoryDuplicate.values()) {
|
||||
|
||||
// Copy default config
|
||||
try {
|
||||
MMOCore.plugin.configManager.copyDefaultFile("gui/" + loader.name + "/" + loader.name + "-default.yml");
|
||||
MMOCore.plugin.configManager.copyDefaultFile("gui/" + invType.name + "/" + invType.name + "-default.yml");
|
||||
} catch (Exception exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load inventory 'gui/" + loader.name + "/" + loader.name + "-default" + "': " + exception.getMessage());
|
||||
MMOCore.log(Level.WARNING, "Could not load inventory 'gui/" + invType.name + "/" + invType.name + "-default" + "': " + exception.getMessage());
|
||||
}
|
||||
for (String id : loader.ids) {
|
||||
String formattedId = UtilityMethods.ymlName(id);
|
||||
final ConfigFile configFile = new ConfigFile("/gui/" + loader.name, loader.name + "-" + formattedId);
|
||||
final EditableInventory GUI = loader.provider.apply(id, !configFile.exists());
|
||||
loader.inventories.put(formattedId, GUI);
|
||||
GUI.reload(MMOCore.plugin, new ConfigFile("/gui/" + loader.name, GUI.getId()).getConfig());
|
||||
|
||||
MMOCore.plugin.getLogger().log(Level.INFO, "For inv type " + invType.name+" got " + invType.ids.get());
|
||||
|
||||
for (String id : invType.ids.get()) {
|
||||
final var formattedId = UtilityMethods.ymlName(id);
|
||||
final var configFile = new ConfigFile("/gui/" + invType.name, invType.name + "-" + formattedId);
|
||||
final var specificUi = invType.provider.apply(id, !configFile.exists());
|
||||
|
||||
((Map) invType.inventories).put(formattedId, specificUi);
|
||||
specificUi.reload(MMOCore.plugin, new ConfigFile("/gui/" + invType.name, specificUi.getId()).getConfig());
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,39 +85,34 @@ public class InventoryManager {
|
||||
});
|
||||
}
|
||||
|
||||
public enum SpecificInventoryLoader {
|
||||
CLASS_CONFIRM("class-confirm",
|
||||
InventoryManager.CLASS_CONFIRM,
|
||||
MMOCore.plugin.classManager.getAll().
|
||||
private static enum InventoryDuplicate {
|
||||
CLASS_CONFIRM("class-confirm", InventoryManager.CLASS_CONFIRM,
|
||||
(id, isDefault) -> new ClassConfirmation(MMOCore.plugin.classManager.get(id), isDefault),
|
||||
() -> MMOCore.plugin.classManager.getAll().
|
||||
stream().
|
||||
map(PlayerClass::getId).
|
||||
collect(Collectors.toList()),
|
||||
(id, isDefault) -> new ClassConfirmation(MMOCore.plugin.classManager.get(id), isDefault)
|
||||
),
|
||||
collect(Collectors.toList())),
|
||||
|
||||
SPECIFIC_TREE("specific-skill-tree",
|
||||
InventoryManager.SPECIFIC_TREE_VIEW,
|
||||
MMOCore.plugin.skillTreeManager.getAll().
|
||||
SPECIFIC_TREE("specific-skill-tree", InventoryManager.SPECIFIC_TREE_VIEW,
|
||||
(id, isDefault) -> new SkillTreeViewer(MMOCore.plugin.skillTreeManager.get(id), isDefault),
|
||||
() -> MMOCore.plugin.skillTreeManager.getAll().
|
||||
stream().
|
||||
map(SkillTree::getId).
|
||||
collect(Collectors.toList()),
|
||||
(id, isDefault) -> new SkillTreeViewer(MMOCore.plugin.skillTreeManager.get(id), isDefault));
|
||||
collect(Collectors.toList()));
|
||||
|
||||
private final String name;
|
||||
|
||||
private final Map inventories;
|
||||
|
||||
private final List<String> ids;
|
||||
|
||||
private final Map<String, ? extends EditableInventory> inventories;
|
||||
private final Supplier<List<String>> ids;
|
||||
private final BiFunction<String, Boolean, ? extends EditableInventory> provider;
|
||||
|
||||
SpecificInventoryLoader(String name, Map inventories, List<String> ids,
|
||||
BiFunction<String, Boolean, ? extends EditableInventory> provider) {
|
||||
InventoryDuplicate(String name,
|
||||
Map<String, ? extends EditableInventory> inventories,
|
||||
BiFunction<String, Boolean, ? extends EditableInventory> provider,
|
||||
Supplier<List<String>> ids) {
|
||||
this.name = name;
|
||||
this.inventories = inventories;
|
||||
this.ids = ids;
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user