Added default config for class-confirm GUI and made the subclass-select.yml GUI as the class-select GUI.

This commit is contained in:
Ka0rX 2023-04-06 09:57:19 +01:00
parent 2cbc1666f2
commit 816fbc5722
15 changed files with 131 additions and 434 deletions

View File

@ -26,9 +26,9 @@ public class ClassConfirmation extends EditableInventory {
private final PlayerClass playerClass;
public ClassConfirmation(PlayerClass playerClass) {
super("class-confirm-"+ UtilityMethods.ymlName(playerClass.getId()));
this.playerClass=playerClass;
public ClassConfirmation(PlayerClass playerClass, boolean isDefault) {
super("class-confirm-" + (isDefault ? "default" : UtilityMethods.ymlName(playerClass.getId())));
this.playerClass = playerClass;
}
@Override

View File

@ -64,9 +64,6 @@ public class ClassSelect extends EditableInventory {
@Override
public ItemStack display(ProfessSelectionInventory inv, int n) {
if (n >= inv.classes.size())
return null;
ItemStack item = playerClass.getIcon();
ItemMeta meta = item.getItemMeta();
if (hideFlags())
@ -93,6 +90,8 @@ public class ClassSelect extends EditableInventory {
item.setItemMeta(meta);
return item;
}
}
public class ProfessSelectionInventory extends GeneratedInventory {

View File

@ -1,77 +0,0 @@
package net.Indyuce.mmocore.gui;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
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.PluginInventory;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.SoundEvent;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
public class SubclassConfirmation extends EditableInventory {
public SubclassConfirmation() {
super("subclass-confirm");
}
@Override
public InventoryItem load(String function, ConfigurationSection config) {
return function.equalsIgnoreCase("yes") ? new InventoryItem<SubclassConfirmationInventory>(config) {
@Override
public Placeholders getPlaceholders(SubclassConfirmationInventory inv, int n) {
Placeholders holders = new Placeholders();
holders.register("class", inv.profess.getName());
return holders;
}
} : new SimplePlaceholderItem(config);
}
public GeneratedInventory newInventory(PlayerData data, PlayerClass profess, PluginInventory last) {
return new SubclassConfirmationInventory(data, this, profess, last);
}
public class SubclassConfirmationInventory extends GeneratedInventory {
private final PlayerClass profess;
private final PluginInventory last;
public SubclassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess, PluginInventory last) {
super(playerData, editable);
this.profess = profess;
this.last = last;
}
@Override
public void whenClicked(InventoryClickContext context, InventoryItem item) {
if (item.getFunction().equals("back"))
last.open();
else if (item.getFunction().equals("yes")) {
PlayerChangeClassEvent called = new PlayerChangeClassEvent(playerData, profess);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
playerData.setClass(profess);
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.SELECT_CLASS).playTo(player);
player.closeInventory();
}
}
@Override
public String calculateName() {
return getName();
}
}
}

View File

@ -1,8 +1,7 @@
package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.EditableInventory;
@ -15,116 +14,118 @@ import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.player.profess.Subclass;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class SubclassSelect extends EditableInventory {
public SubclassSelect() {
super("subclass-select");
}
public SubclassSelect() {
super("subclass-select");
}
@Override
public InventoryItem load(String function, ConfigurationSection config) {
return function.equals("class") ? new ClassItem(config) : new SimplePlaceholderItem(config);
}
@Override
public InventoryItem load(String function, ConfigurationSection config) {
return function.startsWith("sub-class") ? new ClassItem(config) : new SimplePlaceholderItem(config);
}
public GeneratedInventory newInventory(PlayerData data) {
return new SubclassSelectionInventory(data, this);
}
public GeneratedInventory newInventory(PlayerData data) {
return new SubclassSelectionInventory(data, this);
}
public class ClassItem extends SimplePlaceholderItem<SubclassSelectionInventory> {
private final String name;
private final List<String> lore;
public class ClassItem extends SimplePlaceholderItem<SubclassSelectionInventory> {
private final String name;
private final List<String> lore;
private final PlayerClass playerClass;
public ClassItem(ConfigurationSection config) {
super(Material.BARRIER, config);
public ClassItem(ConfigurationSection config) {
super(Material.BARRIER, config);
Validate.isTrue(config.getString("function").length() > 10, "Couldn't find the class associated to: " + config.getString("function"));
String classId = UtilityMethods.enumName(config.getString("function").substring(10));
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");
}
this.name = config.getString("name");
this.lore = config.getStringList("lore");
}
public boolean hasDifferentDisplay() {
return true;
}
@Override
public boolean hasDifferentDisplay() {
return true;
}
@Override
public ItemStack display(SubclassSelectionInventory inv, int n) {
ItemStack item = playerClass.getIcon();
ItemMeta meta = item.getItemMeta();
if (hideFlags())
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", playerClass.getName()));
List<String> lore = new ArrayList<>(this.lore);
@Override
public ItemStack display(SubclassSelectionInventory inv, int n) {
if (n >= inv.subclasses.size())
return null;
int index = lore.indexOf("{lore}");
if (index >= 0) {
lore.remove(index);
for (int j = 0; j < playerClass.getDescription().size(); j++)
lore.add(index + j, playerClass.getDescription().get(j));
}
PlayerClass profess = inv.subclasses.get(n).getProfess();
index = lore.indexOf("{attribute-lore}");
if (index >= 0) {
lore.remove(index);
for (int j = 0; j < playerClass.getAttributeDescription().size(); j++)
lore.add(index + j, playerClass.getAttributeDescription().get(j));
}
ItemStack item = profess.getIcon();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", profess.getName()));
List<String> lore = new ArrayList<>(this.lore);
meta.getPersistentDataContainer().set(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING, playerClass.getId());
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
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));
}
@Override
public boolean canDisplay(SubclassSelectionInventory inv) {
return inv.getPlayerData().getProfess().hasSubclass(playerClass);
}
}
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));
}
public class SubclassSelectionInventory extends GeneratedInventory {
private final List<Subclass> subclasses;
meta.setLore(lore);
item.setItemMeta(meta);
return NBTItem.get(item).addTag(new ItemTag("classId", profess.getId())).toItem();
}
public SubclassSelectionInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable);
@Override
public boolean canDisplay(SubclassSelectionInventory inv) {
return true;
}
}
subclasses = playerData.getProfess().getSubclasses().stream().filter(sub -> playerData.getLevel() >= sub.getLevel())
.collect(Collectors.toList());
}
public class SubclassSelectionInventory extends GeneratedInventory {
private final List<Subclass> subclasses;
@Override
public String calculateName() {
return getName();
}
public SubclassSelectionInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable);
@Override
public void whenClicked(InventoryClickContext context, InventoryItem item) {
if (item.getFunction().equals("back"))
InventoryManager.CLASS_SELECT.newInventory(playerData).open();
subclasses = playerData.getProfess().getSubclasses().stream().filter(sub -> playerData.getLevel() >= sub.getLevel())
.collect(Collectors.toList());
}
if (item.getFunction().startsWith("sub-class")) {
String classId= item.getFunction().substring(10);
@Override
public String calculateName() {
return getName();
}
@Override
public void whenClicked(InventoryClickContext context, InventoryItem item) {
if (item.getFunction().equals("back"))
InventoryManager.CLASS_SELECT.newInventory(playerData).open();
if (item.getFunction().equals("class")) {
String tag = NBTItem.get(context.getClickedItem()).getString("classId");
if (tag.equals(""))
return;
if (playerData.getClassPoints() < 1) {
player.closeInventory();
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(getPlayer());
new ConfigMessage("cant-choose-new-class").send(player);
return;
}
InventoryManager.SUBCLASS_CONFIRM.newInventory(playerData, MMOCore.plugin.classManager.get(tag), this).open();
}
}
}
if (playerData.getClassPoints() < 1) {
player.closeInventory();
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(getPlayer());
new ConfigMessage("cant-choose-new-class").send(player);
return;
}
InventoryManager.CLASS_CONFIRM.get(classId).newInventory(playerData, this).open();
}
}
}
}

View File

@ -182,12 +182,19 @@ public class ConfigManager {
}
public void loadDefaultFile(String path, String name) {
String newPath = path.isEmpty() ? "" : "/" + path;
File folder = new File(MMOCore.plugin.getDataFolder() + (newPath));
if (!folder.exists()) folder.mkdir();
String newPath ="";
if(!path.isEmpty()){
String[] subpaths = path.split("/");
for (String subpath : subpaths) {
newPath+="/"+subpath;
File folder = new File(MMOCore.plugin.getDataFolder() + (newPath));
if (!folder.exists()) folder.mkdir();
}
}
File file = new File(MMOCore.plugin.getDataFolder() + (newPath), name);
if (!file.exists()) try {
MMOCore.log("default/" + (path.isEmpty() ? "" : path + "/") + name);
Files.copy(MMOCore.plugin.getResource("default/" + (path.isEmpty() ? "" : path + "/") + name), file.getAbsoluteFile().toPath());
} catch (IOException e) {
e.printStackTrace();

View File

@ -22,7 +22,6 @@ public class InventoryManager {
public static final ClassSelect CLASS_SELECT = new ClassSelect();
public static final SubclassSelect SUBCLASS_SELECT = new SubclassSelect();
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();
public static final EditableFriendRemoval FRIEND_REMOVAL = new EditableFriendRemoval();
@ -33,22 +32,39 @@ 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 = 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 final List<EditableInventory> list = new ArrayList(Arrays.asList(PLAYER_STATS, ATTRIBUTE_VIEW, TREE_VIEW, SKILL_LIST, CLASS_SELECT, SUBCLASS_SELECT, QUEST_LIST, WAYPOINTS, FRIEND_LIST, FRIEND_REMOVAL, PARTY_VIEW, PARTY_CREATION, GUILD_VIEW, GUILD_CREATION));
private static List<String> defaultClass = Arrays.asList(new String[]{"human", "mage", "paladin", "warrior", "rogue", "arcane-mage"});
public static void load() {
String classConfirmFolder = "gui/class-confirm";
try {
MMOCore.plugin.configManager.loadDefaultFile(classConfirmFolder, "class-confirm-default.yml");
} catch (Exception exception) {
MMOCore.log(Level.WARNING, "Could not load inventory 'class-confirm/class-confirm-default" + "': " + exception.getMessage());
}
for (PlayerClass playerClass : MMOCore.plugin.classManager.getAll()) {
ClassConfirmation GUI = new ClassConfirmation(playerClass);
String classId = MMOCoreUtils.ymlName(playerClass.getId());
ConfigFile configFile = new ConfigFile(classConfirmFolder, "class-confirm-" + classId);
ClassConfirmation GUI;
if (configFile.exists())
GUI = new ClassConfirmation(playerClass, false);
else {
GUI = new ClassConfirmation(playerClass, true);
}
CLASS_CONFIRM.put(MMOCoreUtils.ymlName(playerClass.getId()), GUI);
list.add(GUI);
GUI.reload(new ConfigFile("/" +classConfirmFolder, GUI.getId()).getConfig());
}
list.forEach(inv -> {
String folder="gui"+(inv instanceof ClassConfirmation?"/class-confirm":"");
list.forEach(inv ->
{
String folder = "gui" + (inv instanceof ClassConfirmation ? "/class-confirm" : "");
try {
MMOCore.plugin.configManager.loadDefaultFile(folder, inv.getId() + ".yml");
inv.reload(new ConfigFile("/"+folder, inv.getId()).getConfig());
inv.reload(new ConfigFile("/" + folder, inv.getId()).getConfig());
} catch (Exception exception) {
MMOCore.log(Level.WARNING, "Could not load inventory '" +(inv instanceof ClassConfirmation?"class-confirm/":""+ inv.getId() + "': " + exception.getMessage()));
MMOCore.log(Level.WARNING, "Could not load inventory '" + (inv instanceof ClassConfirmation ? "class-confirm/" : "") + inv.getId() + "': " + exception.getMessage());
}
});
}

View File

@ -1,38 +0,0 @@
# 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

@ -1,38 +0,0 @@
# 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

@ -1,38 +0,0 @@
# 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

@ -1,38 +0,0 @@
# 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

@ -1,38 +0,0 @@
# 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

@ -1,38 +0,0 @@
# 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

@ -1,21 +0,0 @@
# GUI display name
name: Subclass Confirmation
# 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]
item: GREEN_TERRACOTTA
function: 'yes'
name: '&aSelect {class}'
lore: {}
back:
slots: [14]
item: RED_TERRACOTTA
function: back
name: '&aBack'
lore: {}

View File

@ -13,10 +13,10 @@ items:
item: RED_STAINED_GLASS_PANE
name: '&aBack to Class Selection'
lore: []
class:
slots: [13,12,14,11,15,10,16]
function: class
name: '&a&lThe {name}'
arcane-mage:
slots: [13]
function: sub-class-arcane-mage
name: '&a&lThe Arcane Mage'
lore:
- '{lore}'
- ''