forked from Upstream/mmocore
Enabled to have customizable ClassConfirmation GUI names.
This commit is contained in:
parent
6ac3267059
commit
a9ebca0f4d
@ -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
|
||||
|
@ -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<ClassConfirmationInventory> {
|
||||
|
||||
public UnlockedItem(ConfigurationSection config) {
|
||||
@ -98,10 +102,17 @@ public class ClassConfirmation extends EditableInventory {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
@ -129,6 +140,8 @@ public class ClassConfirmation extends EditableInventory {
|
||||
|
||||
@Override
|
||||
public String calculateName() {
|
||||
if (GUIName != null)
|
||||
return GUIName;
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
@ -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<ProfessSelectionInventory> {
|
||||
private final String name;
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user