Moved "class-confirmation-gui-name" option from class-select to class-confirm GUI

This commit is contained in:
Jules 2023-03-03 14:22:43 +01:00
parent 8ac6af34af
commit 8c0d8da483
4 changed files with 60 additions and 59 deletions

View File

@ -1,7 +1,12 @@
package net.Indyuce.mmocore.gui; package net.Indyuce.mmocore.gui;
import net.Indyuce.mmocore.MMOCore; 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.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.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.InventoryClickContext; import net.Indyuce.mmocore.gui.api.InventoryClickContext;
@ -9,21 +14,29 @@ import net.Indyuce.mmocore.gui.api.PluginInventory;
import net.Indyuce.mmocore.gui.api.item.InventoryItem; import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders; import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem; 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 net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
public class ClassConfirmation extends EditableInventory { public class ClassConfirmation extends EditableInventory {
public ClassConfirmation() {
super("class-confirm"); /**
} * This enables to configure the name of the
* class confirmation GUI (for custom GUI textures).
*/
private final Map<String, String> specificNames = new HashMap<>();
public ClassConfirmation() {
super("class-confirm");
}
@Override @Override
public InventoryItem load(String function, ConfigurationSection config) { public InventoryItem load(String function, ConfigurationSection config) {
@ -34,12 +47,20 @@ public class ClassConfirmation extends EditableInventory {
return new ClassConfirmationInventory(data, this, profess, last); return new ClassConfirmationInventory(data, this, profess, last);
} }
public GeneratedInventory newInventory(PlayerData data, String GUIName, PlayerClass profess, PluginInventory last) { @Override
return new ClassConfirmationInventory(data, GUIName, this, profess, last); 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> { public class UnlockedItem extends InventoryItem<ClassConfirmationInventory> {
public UnlockedItem(ConfigurationSection config) { public UnlockedItem(ConfigurationSection config) {
super(config); super(config);
} }
@ -50,8 +71,8 @@ public class ClassConfirmation extends EditableInventory {
SavedClassInformation info = inv.getPlayerData().getClassInfo(profess); SavedClassInformation info = inv.getPlayerData().getClassInfo(profess);
Placeholders holders = new Placeholders(); Placeholders holders = new Placeholders();
int nextLevelExp = inv.getPlayerData().getLevelUpExperience(); final double nextLevelExp = inv.getPlayerData().getLevelUpExperience();
double ratio = (double) info.getExperience() / (double) nextLevelExp; final double ratio = info.getExperience() / nextLevelExp;
StringBuilder bar = new StringBuilder("" + ChatColor.BOLD); StringBuilder bar = new StringBuilder("" + ChatColor.BOLD);
int chars = (int) (ratio * 20); int chars = (int) (ratio * 20);
@ -102,17 +123,10 @@ public class ClassConfirmation extends EditableInventory {
public class ClassConfirmationInventory extends GeneratedInventory { public class ClassConfirmationInventory extends GeneratedInventory {
private final PlayerClass profess; private final PlayerClass profess;
private final PluginInventory last; private final PluginInventory last;
private String GUIName;
public ClassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess, PluginInventory last) { public ClassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess, PluginInventory last) {
super(playerData, editable); super(playerData, editable);
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.profess = profess;
this.last = last; this.last = last;
} }
@ -140,9 +154,9 @@ public class ClassConfirmation extends EditableInventory {
@Override @Override
public String calculateName() { public String calculateName() {
if (GUIName != null) final String professKey = MMOCoreUtils.ymlName(profess.getId());
return GUIName; final @Nullable String found = specificNames.get(professKey);
return getName(); return found == null ? getName().replace("{class}", profess.getName()) : found;
} }
} }
} }

View File

@ -2,18 +2,17 @@ package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmocore.MMOCore; 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.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.player.profess.ClassOption;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.gui.api.EditableInventory; import net.Indyuce.mmocore.gui.api.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.InventoryClickContext; import net.Indyuce.mmocore.gui.api.InventoryClickContext;
import net.Indyuce.mmocore.gui.api.item.InventoryItem; import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem; import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.player.profess.ClassOption;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -22,7 +21,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import java.util.*; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ClassSelect extends EditableInventory { public class ClassSelect extends EditableInventory {
@ -42,21 +43,12 @@ public class ClassSelect extends EditableInventory {
public class ClassItem extends SimplePlaceholderItem<ProfessSelectionInventory> { public class ClassItem extends SimplePlaceholderItem<ProfessSelectionInventory> {
private final String name; private final String name;
private final List<String> lore; private final List<String> lore;
/**
* This enables to configure the name of the class confirmation GUI (for custom GUI textures).
*/
private final Map<String, String> classGUINames = new HashMap<>();
public ClassItem(ConfigurationSection config) { public ClassItem(ConfigurationSection config) {
super(Material.BARRIER, config); super(Material.BARRIER, config);
this.name = config.getString("name"); this.name = config.getString("name");
this.lore = config.getStringList("lore"); 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() { public boolean hasDifferentDisplay() {
@ -113,7 +105,6 @@ public class ClassSelect extends EditableInventory {
@Override @Override
public void whenClicked(InventoryClickContext context, InventoryItem item) { public void whenClicked(InventoryClickContext context, InventoryItem item) {
if (item.getFunction().equals("class")) { if (item.getFunction().equals("class")) {
ClassItem classItem = (ClassItem) item;
String classId = context.getClickedItem().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING); String classId = context.getClickedItem().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING);
if (classId.equals("")) if (classId.equals(""))
return; return;
@ -124,7 +115,7 @@ public class ClassSelect extends EditableInventory {
return; return;
} }
PlayerClass profess = MMOCore.plugin.classManager.get(classId); final PlayerClass profess = MMOCore.plugin.classManager.get(classId);
if (profess.hasOption(ClassOption.NEEDS_PERMISSION) && !player.hasPermission("mmocore.class." + profess.getId().toLowerCase())) { if (profess.hasOption(ClassOption.NEEDS_PERMISSION) && !player.hasPermission("mmocore.class." + profess.getId().toLowerCase())) {
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player); MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player);
new ConfigMessage("no-permission-for-class").send(player); new ConfigMessage("no-permission-for-class").send(player);
@ -136,13 +127,9 @@ public class ClassSelect extends EditableInventory {
MMOCore.plugin.configManager.getSimpleMessage("already-on-class", "class", profess.getName()).send(player); MMOCore.plugin.configManager.getSimpleMessage("already-on-class", "class", profess.getName()).send(player);
return; 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();
} else final PlayerClass playerClass = findDeepestSubclass(playerData, profess);
InventoryManager.CLASS_CONFIRM.newInventory(playerData,playerClass, this).open(); InventoryManager.CLASS_CONFIRM.newInventory(playerData, playerClass, this).open();
} }
} }
} }

View File

@ -1,6 +1,15 @@
# GUI display name # GUI display name, used by default
name: Class Confirmation 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 # Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9. # between 9 and 54 and must be a multiple of 9.
@ -10,7 +19,7 @@ items:
yes: yes:
slots: [12] slots: [12]
function: 'yes' function: 'yes'
# Displayed when the player had already selected this class # Displayed when the player had already selected this class
# before (only if class slots are enabled in the config). # before (only if class slots are enabled in the config).
unlocked: unlocked:
@ -24,13 +33,13 @@ items:
- '' - ''
- '&7Skill Points: &6{skill_points}' - '&7Skill Points: &6{skill_points}'
- '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}' - '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}'
# Displayed when the class is being chosen for the first time. # Displayed when the class is being chosen for the first time.
locked: locked:
item: GREEN_TERRACOTTA item: GREEN_TERRACOTTA
name: '&aSelect {class}' name: '&aSelect {class}'
lore: {} lore: {}
back: back:
slots: [14] slots: [14]
item: RED_TERRACOTTA item: RED_TERRACOTTA

View File

@ -16,12 +16,3 @@ items:
- '{lore}' - '{lore}'
- '' - ''
- '{attribute-lore}' - '{attribute-lore}'
#Customizable name for the confirmation GUI.
#If none is provided the GUI name will be "Class Confirmation".
class-confirmation-GUI-name:
mage: "Select Mage"
rogue: "Select Rogue"
marksman: "Select Marksman"
warrior: "Select Warrior"
paladin: "Select Paladin"