Refactor of the ClassSelect & ClassConfirmation GUI. Now you can fully customize the GUI depending on each class. Reload the GUI folder & add a class-confirm/... gui for each new class you created.

This commit is contained in:
Ka0rX 2023-03-31 09:04:58 +01:00
parent dca44b232d
commit 739f958d5a
15 changed files with 321 additions and 67 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MMOCore</artifactId>
<groupId>net.Indyuce</groupId>
<version>1.11.2-SNAPSHOT</version>
<version>1.11.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -341,7 +341,6 @@ public class MMOCore extends JavaPlugin {
statManager.initialize(clearBefore);
professionManager.initialize(clearBefore);
InventoryManager.load();
skillTreeManager.initialize(clearBefore);
classManager.initialize(clearBefore);
questManager.initialize(clearBefore);
@ -351,6 +350,8 @@ public class MMOCore extends JavaPlugin {
requestManager.initialize(clearBefore);
soundManager.initialize(clearBefore);
configItems.initialize(clearBefore);
//Needs to be loaded after the class manager.
InventoryManager.load();
if (getConfig().isConfigurationSection("action-bar"))
actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));

View File

@ -1,12 +1,12 @@
package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.gui.api.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
@ -21,21 +21,14 @@ import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
public class ClassConfirmation extends EditableInventory {
/**
* This enables to configure the name of the
* class confirmation GUI (for custom GUI textures).
*/
private final Map<String, String> specificNames = new HashMap<>();
private final PlayerClass playerClass;
public ClassConfirmation() {
super("class-confirm");
public ClassConfirmation(PlayerClass playerClass) {
super("class-confirm-"+ UtilityMethods.ymlName(playerClass.getId()));
this.playerClass=playerClass;
}
@Override
@ -43,21 +36,13 @@ public class ClassConfirmation extends EditableInventory {
return function.equalsIgnoreCase("yes") ? new YesItem(config) : new SimplePlaceholderItem(config);
}
public GeneratedInventory newInventory(PlayerData data, PlayerClass profess, PluginInventory last) {
return new ClassConfirmationInventory(data, this, profess, last);
public GeneratedInventory newInventory(PlayerData data, PluginInventory last) {
return new ClassConfirmationInventory(data, this, playerClass, last);
}
@Override
public void reload(FileConfiguration config) {
super.reload(config);
specificNames.clear();
if (config.contains("class-specific-name")) {
final ConfigurationSection section = config.getConfigurationSection("class-specific-name");
for (String key : section.getKeys(false))
specificNames.put(key, section.getString(key));
}
}
public class UnlockedItem extends InventoryItem<ClassConfirmationInventory> {
@ -154,9 +139,7 @@ public class ClassConfirmation extends EditableInventory {
@Override
public String calculateName() {
final String professKey = MMOCoreUtils.ymlName(profess.getId());
final @Nullable String found = specificNames.get(professKey);
return found == null ? getName().replace("{class}", profess.getName()) : found;
return getName().replace("{class}", profess.getName());
}
}
}

View File

@ -1,18 +1,21 @@
package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore;
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.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.gui.api.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.manager.InventoryManager;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection;
@ -24,6 +27,7 @@ import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class ClassSelect extends EditableInventory {
@ -33,7 +37,7 @@ public class ClassSelect extends EditableInventory {
@Override
public InventoryItem load(String function, ConfigurationSection config) {
return function.equals("class") ? new ClassItem(config) : new SimplePlaceholderItem(config);
return function.startsWith("class") ? new ClassItem(config) : new SimplePlaceholderItem(config);
}
public GeneratedInventory newInventory(PlayerData data) {
@ -43,10 +47,13 @@ public class ClassSelect extends EditableInventory {
public class ClassItem extends SimplePlaceholderItem<ProfessSelectionInventory> {
private final String name;
private final List<String> lore;
private final PlayerClass playerClass;
public ClassItem(ConfigurationSection config) {
super(Material.BARRIER, config);
Validate.isTrue(config.getString("function").length()>6,"Couldn't find the class associated to: "+config.getString("function"));
String classId = UtilityMethods.enumName(config.getString("function").substring(6));
this.playerClass = Objects.requireNonNull(MMOCore.plugin.classManager.get(classId),classId+" does not correspond to any classId.");
this.name = config.getString("name");
this.lore = config.getStringList("lore");
}
@ -60,29 +67,28 @@ public class ClassSelect extends EditableInventory {
if (n >= inv.classes.size())
return null;
PlayerClass profess = inv.classes.get(n);
ItemStack item = profess.getIcon();
ItemStack item = playerClass.getIcon();
ItemMeta meta = item.getItemMeta();
if (hideFlags())
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", profess.getName()));
meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", playerClass.getName()));
List<String> lore = new ArrayList<>(this.lore);
int index = lore.indexOf("{lore}");
if (index >= 0) {
lore.remove(index);
for (int j = 0; j < profess.getDescription().size(); j++)
lore.add(index + j, profess.getDescription().get(j));
for (int j = 0; j < playerClass.getDescription().size(); j++)
lore.add(index + j, playerClass.getDescription().get(j));
}
index = lore.indexOf("{attribute-lore}");
if (index >= 0) {
lore.remove(index);
for (int j = 0; j < profess.getAttributeDescription().size(); j++)
lore.add(index + j, profess.getAttributeDescription().get(j));
for (int j = 0; j < playerClass.getAttributeDescription().size(); j++)
lore.add(index + j, playerClass.getAttributeDescription().get(j));
}
meta.getPersistentDataContainer().set(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING, profess.getId());
meta.getPersistentDataContainer().set(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING, playerClass.getId());
meta.setLore(lore);
item.setItemMeta(meta);
return item;
@ -104,10 +110,8 @@ public class ClassSelect extends EditableInventory {
@Override
public void whenClicked(InventoryClickContext context, InventoryItem item) {
if (item.getFunction().equals("class")) {
String classId = context.getClickedItem().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING);
if (classId.equals(""))
return;
if (item instanceof ClassItem) {
PlayerClass profess = ((ClassItem) item).playerClass;
if (playerData.getClassPoints() < 1) {
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player);
@ -115,7 +119,6 @@ public class ClassSelect extends EditableInventory {
return;
}
final PlayerClass profess = MMOCore.plugin.classManager.get(classId);
if (profess.hasOption(ClassOption.NEEDS_PERMISSION) && !player.hasPermission("mmocore.class." + profess.getId().toLowerCase())) {
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player);
new ConfigMessage("no-permission-for-class").send(player);
@ -129,7 +132,7 @@ public class ClassSelect extends EditableInventory {
}
final PlayerClass playerClass = findDeepestSubclass(playerData, profess);
InventoryManager.CLASS_CONFIRM.newInventory(playerData, playerClass, this).open();
InventoryManager.CLASS_CONFIRM.get(MMOCoreUtils.ymlName(playerClass.getId())).newInventory(playerData, this).open();
}
}
}

View File

@ -1,10 +1,11 @@
package net.Indyuce.mmocore.manager;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.logging.Level;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.gui.social.friend.EditableFriendList;
import net.Indyuce.mmocore.gui.*;
import net.Indyuce.mmocore.gui.social.friend.EditableFriendRemoval;
@ -20,7 +21,7 @@ public class InventoryManager {
public static final SkillList SKILL_LIST = new SkillList();
public static final ClassSelect CLASS_SELECT = new ClassSelect();
public static final SubclassSelect SUBCLASS_SELECT = new SubclassSelect();
public static final ClassConfirmation CLASS_CONFIRM = new ClassConfirmation();
public static final Map<String, ClassConfirmation> CLASS_CONFIRM = new HashMap<>();
public static final SubclassConfirmation SUBCLASS_CONFIRM = new SubclassConfirmation();
public static final WaypointViewer WAYPOINTS = new WaypointViewer();
public static final EditableFriendList FRIEND_LIST = new EditableFriendList();
@ -32,14 +33,21 @@ public class InventoryManager {
public static final QuestViewer QUEST_LIST = new QuestViewer();
public static final AttributeView ATTRIBUTE_VIEW = new AttributeView();
public static final SkillTreeViewer TREE_VIEW = new SkillTreeViewer();
public static final List<EditableInventory> list = Arrays.asList(PLAYER_STATS, ATTRIBUTE_VIEW, TREE_VIEW,SKILL_LIST, CLASS_SELECT, SUBCLASS_SELECT, SUBCLASS_CONFIRM, QUEST_LIST, WAYPOINTS, CLASS_CONFIRM, FRIEND_LIST, FRIEND_REMOVAL, PARTY_VIEW, PARTY_CREATION, GUILD_VIEW, GUILD_CREATION);
public static final List<EditableInventory> list = new ArrayList(Arrays.asList(PLAYER_STATS, ATTRIBUTE_VIEW, TREE_VIEW, SKILL_LIST, CLASS_SELECT, SUBCLASS_SELECT, SUBCLASS_CONFIRM, QUEST_LIST, WAYPOINTS, FRIEND_LIST, FRIEND_REMOVAL, PARTY_VIEW, PARTY_CREATION, GUILD_VIEW, GUILD_CREATION));
public static void load() {
for (PlayerClass playerClass : MMOCore.plugin.classManager.getAll()) {
ClassConfirmation GUI = new ClassConfirmation(playerClass);
CLASS_CONFIRM.put(MMOCoreUtils.ymlName(playerClass.getId()), GUI);
list.add(GUI);
}
list.forEach(inv -> {
MMOCore.plugin.configManager.loadDefaultFile("gui", inv.getId() + ".yml");
String folder="gui"+(inv instanceof ClassConfirmation?"/class-confirm":"");
MMOCore.plugin.configManager.loadDefaultFile(folder, inv.getId() + ".yml");
try {
inv.reload(new ConfigFile("/gui", inv.getId()).getConfig());
} catch (IllegalArgumentException exception) {
inv.reload(new ConfigFile("/"+folder, inv.getId()).getConfig());
} catch (Exception exception) {
MMOCore.log(Level.WARNING, "Could not load inventory '" + inv.getId() + "': " + exception.getMessage());
}
});

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>MMOCore</artifactId>
<groupId>net.Indyuce</groupId>
<version>1.11.2-SNAPSHOT</version>
<version>1.11.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -67,7 +67,7 @@
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore-API</artifactId>
<version>1.11.2-SNAPSHOT</version>
<version>1.11.3-SNAPSHOT</version>
<optional>true</optional>
</dependency>

View File

@ -1,16 +1,6 @@
# GUI display name, used by default
name: 'Confirmation: {class}'
# GUI display name which overrides the default one.
# This can be used to apply custom textures to the GUI
class-specific-name:
mage: "Select Mage"
rogue: "Select Rogue"
marksman: "Select Marksman"
warrior: "Select Warrior"
paladin: "Select Paladin"
# Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 27

View File

@ -0,0 +1,38 @@
# GUI display name, used by default
name: 'Confirmation: {class}'
# Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 27
items:
yes:
slots: [12]
function: 'yes'
# Displayed when the player had already selected this class
# before (only if class slots are enabled in the config).
unlocked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore:
- ''
- '&7Class Level: &e{level}'
- '&7Progression: &e{exp} / {next_level}'
- '&8[&e{progress}&8] &e{percent}%'
- ''
- '&7Skill Points: &6{skill_points}'
- '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}'
# Displayed when the class is being chosen for the first time.
locked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore: {}
back:
slots: [14]
item: RED_TERRACOTTA
function: back
name: '&aBack'
lore: {}

View File

@ -0,0 +1,38 @@
# GUI display name, used by default
name: 'Confirmation: {class}'
# Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 27
items:
yes:
slots: [12]
function: 'yes'
# Displayed when the player had already selected this class
# before (only if class slots are enabled in the config).
unlocked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore:
- ''
- '&7Class Level: &e{level}'
- '&7Progression: &e{exp} / {next_level}'
- '&8[&e{progress}&8] &e{percent}%'
- ''
- '&7Skill Points: &6{skill_points}'
- '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}'
# Displayed when the class is being chosen for the first time.
locked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore: {}
back:
slots: [14]
item: RED_TERRACOTTA
function: back
name: '&aBack'
lore: {}

View File

@ -0,0 +1,38 @@
# GUI display name, used by default
name: 'Confirmation: {class}'
# Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 27
items:
yes:
slots: [12]
function: 'yes'
# Displayed when the player had already selected this class
# before (only if class slots are enabled in the config).
unlocked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore:
- ''
- '&7Class Level: &e{level}'
- '&7Progression: &e{exp} / {next_level}'
- '&8[&e{progress}&8] &e{percent}%'
- ''
- '&7Skill Points: &6{skill_points}'
- '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}'
# Displayed when the class is being chosen for the first time.
locked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore: {}
back:
slots: [14]
item: RED_TERRACOTTA
function: back
name: '&aBack'
lore: {}

View File

@ -0,0 +1,38 @@
# GUI display name, used by default
name: 'Confirmation: {class}'
# Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 27
items:
yes:
slots: [12]
function: 'yes'
# Displayed when the player had already selected this class
# before (only if class slots are enabled in the config).
unlocked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore:
- ''
- '&7Class Level: &e{level}'
- '&7Progression: &e{exp} / {next_level}'
- '&8[&e{progress}&8] &e{percent}%'
- ''
- '&7Skill Points: &6{skill_points}'
- '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}'
# Displayed when the class is being chosen for the first time.
locked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore: {}
back:
slots: [14]
item: RED_TERRACOTTA
function: back
name: '&aBack'
lore: {}

View File

@ -0,0 +1,38 @@
# GUI display name, used by default
name: 'Confirmation: {class}'
# Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 27
items:
yes:
slots: [12]
function: 'yes'
# Displayed when the player had already selected this class
# before (only if class slots are enabled in the config).
unlocked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore:
- ''
- '&7Class Level: &e{level}'
- '&7Progression: &e{exp} / {next_level}'
- '&8[&e{progress}&8] &e{percent}%'
- ''
- '&7Skill Points: &6{skill_points}'
- '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}'
# Displayed when the class is being chosen for the first time.
locked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore: {}
back:
slots: [14]
item: RED_TERRACOTTA
function: back
name: '&aBack'
lore: {}

View File

@ -0,0 +1,38 @@
# GUI display name, used by default
name: 'Confirmation: {class}'
# Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9.
slots: 27
items:
yes:
slots: [12]
function: 'yes'
# Displayed when the player had already selected this class
# before (only if class slots are enabled in the config).
unlocked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore:
- ''
- '&7Class Level: &e{level}'
- '&7Progression: &e{exp} / {next_level}'
- '&8[&e{progress}&8] &e{percent}%'
- ''
- '&7Skill Points: &6{skill_points}'
- '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}'
# Displayed when the class is being chosen for the first time.
locked:
item: GREEN_TERRACOTTA
name: '&aSelect {class}'
lore: {}
back:
slots: [14]
item: RED_TERRACOTTA
function: back
name: '&aBack'
lore: {}

View File

@ -7,10 +7,51 @@ name: Class Selection
slots: 27
items:
class:
slots: [13,12,14,11,15,10,16]
function: class
name: '&a&lThe {name}'
class-rogue:
slots: [11]
function: class-rogue
name: '&a&lThe Rogue'
hide-flags: true
lore:
- '{lore}'
- ''
- '{attribute-lore}'
class-mage:
slots: [12]
function: class-mage
name: '&a&lThe Mage'
hide-flags: true
lore:
- '{lore}'
- ''
- '{attribute-lore}'
class-marksman:
slots: [13]
function: class-marksman
name: '&a&lThe Marksman'
hide-flags: true
lore:
- '{lore}'
- ''
- '{attribute-lore}'
class-warrior:
slots: [14]
function: class-warrior
name: '&a&lThe Warrior'
hide-flags: true
lore:
- '{lore}'
- ''
- '{attribute-lore}'
class-paladin:
slots: [15]
function: class-paladin
name: '&a&lThe Paladin'
hide-flags: true
lore:
- '{lore}'

View File

@ -13,7 +13,7 @@ And then add MMOCore-API as dependency
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore-API</artifactId>
<version>1.11.2-SNAPSHOT</version>
<version>1.11.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
```