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();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String ymlName(String str) {
|
||||||
|
return str.toLowerCase().replace("_", "-").replace(" ", "-");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param value an integer you want to convert
|
* @param value an integer you want to convert
|
||||||
|
@ -34,6 +34,10 @@ 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) {
|
||||||
|
return new ClassConfirmationInventory(data, GUIName, this, profess, last);
|
||||||
|
}
|
||||||
|
|
||||||
public class UnlockedItem extends InventoryItem<ClassConfirmationInventory> {
|
public class UnlockedItem extends InventoryItem<ClassConfirmationInventory> {
|
||||||
|
|
||||||
public UnlockedItem(ConfigurationSection config) {
|
public UnlockedItem(ConfigurationSection config) {
|
||||||
@ -98,10 +102,17 @@ 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;
|
||||||
}
|
}
|
||||||
@ -129,6 +140,8 @@ public class ClassConfirmation extends EditableInventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String calculateName() {
|
public String calculateName() {
|
||||||
|
if (GUIName != null)
|
||||||
|
return GUIName;
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ 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.player.PlayerData;
|
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.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;
|
||||||
@ -21,9 +22,7 @@ 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.ArrayList;
|
import java.util.*;
|
||||||
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 {
|
||||||
@ -43,12 +42,21 @@ 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() {
|
||||||
@ -105,6 +113,7 @@ 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;
|
||||||
@ -127,8 +136,13 @@ 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();
|
||||||
|
|
||||||
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