diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java index 6ef895ba..798c1394 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java @@ -53,6 +53,10 @@ public class MMOCoreUtils { return builder.toString(); } + public static String ymlName(String str) { + return str.toLowerCase().replace("_", "-").replace(" ", "-"); + } + /** * * @param value an integer you want to convert diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java index a6a918ba..64a57eb2 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java @@ -34,6 +34,10 @@ public class ClassConfirmation extends EditableInventory { return new ClassConfirmationInventory(data, this, profess, last); } + public GeneratedInventory newInventory(PlayerData data, String GUIName, PlayerClass profess, PluginInventory last) { + return new ClassConfirmationInventory(data, GUIName, this, profess, last); + } + public class UnlockedItem extends InventoryItem { public UnlockedItem(ConfigurationSection config) { @@ -54,10 +58,10 @@ public class ClassConfirmation extends EditableInventory { for (int j = 0; j < 20; j++) bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|"); - holders.register("percent", decimal.format(ratio * 100)); - holders.register("progress", bar.toString()); - holders.register("class", profess.getName()); - holders.register("unlocked_skills", info.getSkillKeys().size()); + holders.register("percent", decimal.format(ratio * 100)); + holders.register("progress", bar.toString()); + holders.register("class", profess.getName()); + holders.register("unlocked_skills", info.getSkillKeys().size()); holders.register("class_skills", profess.getSkills().size()); holders.register("next_level", "" + nextLevelExp); holders.register("level", info.getLevel()); @@ -93,43 +97,52 @@ public class ClassConfirmation extends EditableInventory { public ItemStack display(ClassConfirmationInventory inv, int n) { return inv.getPlayerData().hasSavedClass(inv.profess) ? unlocked.display(inv, n) : locked.display(inv, n); } - } + } - public class ClassConfirmationInventory extends GeneratedInventory { - private final PlayerClass profess; - private final PluginInventory last; + public class ClassConfirmationInventory extends GeneratedInventory { + private final PlayerClass profess; + private final PluginInventory last; + private String GUIName; - public ClassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess, PluginInventory last) { - super(playerData, editable); + public ClassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess, PluginInventory last) { + super(playerData, editable); + this.profess = profess; + this.last = last; + } - this.profess = profess; - this.last = last; - } + public ClassConfirmationInventory(PlayerData playerData, String GUIName, EditableInventory editable, PlayerClass profess, PluginInventory last) { + super(playerData, editable); + this.GUIName = GUIName; + this.profess = profess; + this.last = last; + } - @Override - public void whenClicked(InventoryClickContext context, InventoryItem item) { - if (item.getFunction().equals("back")) - last.open(); + @Override + public void whenClicked(InventoryClickContext context, InventoryItem item) { + if (item.getFunction().equals("back")) + last.open(); - else if (item.getFunction().equals("yes")) { + else if (item.getFunction().equals("yes")) { - PlayerChangeClassEvent called = new PlayerChangeClassEvent(playerData, profess); - Bukkit.getPluginManager().callEvent(called); - if (called.isCancelled()) - return; + PlayerChangeClassEvent called = new PlayerChangeClassEvent(playerData, profess); + Bukkit.getPluginManager().callEvent(called); + if (called.isCancelled()) + return; - playerData.giveClassPoints(-1); - (playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess) - : new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData); - MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player); - MMOCore.plugin.soundManager.getSound(SoundEvent.SELECT_CLASS).playTo(player); - player.closeInventory(); - } - } + playerData.giveClassPoints(-1); + (playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess) + : new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData); + 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(); - } - } + @Override + public String calculateName() { + if (GUIName != null) + return GUIName; + return getName(); + } + } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java index d1704bbb..a8c65ccd 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java @@ -3,6 +3,7 @@ package net.Indyuce.mmocore.gui; import io.lumine.mythic.lib.MythicLib; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; +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,9 +22,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; public class ClassSelect extends EditableInventory { @@ -43,12 +42,21 @@ public class ClassSelect extends EditableInventory { public class ClassItem extends SimplePlaceholderItem { private final String name; private final List lore; + /** + * This enables to configure the name of the class confirmation GUI (for custom GUI textures). + */ + private final Map classGUINames = new HashMap<>(); public ClassItem(ConfigurationSection config) { super(Material.BARRIER, config); this.name = config.getString("name"); this.lore = config.getStringList("lore"); + if (config.contains("class-confirmation-GUI-name")) { + ConfigurationSection section = config.getConfigurationSection("class-confirmation-GUI-name"); + for (String key : section.getKeys(false)) + classGUINames.put(key, section.getString(key)); + } } public boolean hasDifferentDisplay() { @@ -105,6 +113,7 @@ public class ClassSelect extends EditableInventory { @Override public void whenClicked(InventoryClickContext context, InventoryItem item) { if (item.getFunction().equals("class")) { + ClassItem classItem = (ClassItem) item; String classId = context.getClickedItem().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING); if (classId.equals("")) return; @@ -127,8 +136,13 @@ public class ClassSelect extends EditableInventory { MMOCore.plugin.configManager.getSimpleMessage("already-on-class", "class", profess.getName()).send(player); return; } + PlayerClass playerClass = findDeepestSubclass(playerData, profess); + String classKey = MMOCoreUtils.ymlName(playerClass.getName()); + if (classItem.classGUINames.containsKey(classKey)) { + InventoryManager.CLASS_CONFIRM.newInventory(playerData,classItem.classGUINames.get(classKey),playerClass, this).open(); - InventoryManager.CLASS_CONFIRM.newInventory(playerData, findDeepestSubclass(playerData, profess), this).open(); + } else + InventoryManager.CLASS_CONFIRM.newInventory(playerData,playerClass, this).open(); } } }