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) {
|
||||||
@ -54,10 +58,10 @@ public class ClassConfirmation extends EditableInventory {
|
|||||||
for (int j = 0; j < 20; j++)
|
for (int j = 0; j < 20; j++)
|
||||||
bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|");
|
bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|");
|
||||||
|
|
||||||
holders.register("percent", decimal.format(ratio * 100));
|
holders.register("percent", decimal.format(ratio * 100));
|
||||||
holders.register("progress", bar.toString());
|
holders.register("progress", bar.toString());
|
||||||
holders.register("class", profess.getName());
|
holders.register("class", profess.getName());
|
||||||
holders.register("unlocked_skills", info.getSkillKeys().size());
|
holders.register("unlocked_skills", info.getSkillKeys().size());
|
||||||
holders.register("class_skills", profess.getSkills().size());
|
holders.register("class_skills", profess.getSkills().size());
|
||||||
holders.register("next_level", "" + nextLevelExp);
|
holders.register("next_level", "" + nextLevelExp);
|
||||||
holders.register("level", info.getLevel());
|
holders.register("level", info.getLevel());
|
||||||
@ -93,43 +97,52 @@ public class ClassConfirmation extends EditableInventory {
|
|||||||
public ItemStack display(ClassConfirmationInventory inv, int n) {
|
public ItemStack display(ClassConfirmationInventory inv, int n) {
|
||||||
return inv.getPlayerData().hasSavedClass(inv.profess) ? unlocked.display(inv, n) : locked.display(inv, n);
|
return inv.getPlayerData().hasSavedClass(inv.profess) ? unlocked.display(inv, n) : locked.display(inv, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
this.profess = profess;
|
public ClassConfirmationInventory(PlayerData playerData, String GUIName, EditableInventory editable, PlayerClass profess, PluginInventory last) {
|
||||||
this.last = last;
|
super(playerData, editable);
|
||||||
}
|
this.GUIName = GUIName;
|
||||||
|
this.profess = profess;
|
||||||
|
this.last = last;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||||
if (item.getFunction().equals("back"))
|
if (item.getFunction().equals("back"))
|
||||||
last.open();
|
last.open();
|
||||||
|
|
||||||
else if (item.getFunction().equals("yes")) {
|
else if (item.getFunction().equals("yes")) {
|
||||||
|
|
||||||
PlayerChangeClassEvent called = new PlayerChangeClassEvent(playerData, profess);
|
PlayerChangeClassEvent called = new PlayerChangeClassEvent(playerData, profess);
|
||||||
Bukkit.getPluginManager().callEvent(called);
|
Bukkit.getPluginManager().callEvent(called);
|
||||||
if (called.isCancelled())
|
if (called.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
playerData.giveClassPoints(-1);
|
playerData.giveClassPoints(-1);
|
||||||
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess)
|
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess)
|
||||||
: new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData);
|
: new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData);
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player);
|
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player);
|
||||||
MMOCore.plugin.soundManager.getSound(SoundEvent.SELECT_CLASS).playTo(player);
|
MMOCore.plugin.soundManager.getSound(SoundEvent.SELECT_CLASS).playTo(player);
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String calculateName() {
|
public String calculateName() {
|
||||||
return getName();
|
if (GUIName != null)
|
||||||
}
|
return GUIName;
|
||||||
}
|
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