forked from Upstream/mmocore
Moved "class-confirmation-gui-name" option from class-select to class-confirm GUI
This commit is contained in:
parent
8ac6af34af
commit
8c0d8da483
@ -1,7 +1,12 @@
|
||||
package net.Indyuce.mmocore.gui;
|
||||
|
||||
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.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.GeneratedInventory;
|
||||
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.Placeholders;
|
||||
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.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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
|
||||
public InventoryItem load(String function, ConfigurationSection config) {
|
||||
@ -34,12 +47,20 @@ 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);
|
||||
@Override
|
||||
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 UnlockedItem(ConfigurationSection config) {
|
||||
super(config);
|
||||
}
|
||||
@ -50,8 +71,8 @@ public class ClassConfirmation extends EditableInventory {
|
||||
SavedClassInformation info = inv.getPlayerData().getClassInfo(profess);
|
||||
Placeholders holders = new Placeholders();
|
||||
|
||||
int nextLevelExp = inv.getPlayerData().getLevelUpExperience();
|
||||
double ratio = (double) info.getExperience() / (double) nextLevelExp;
|
||||
final double nextLevelExp = inv.getPlayerData().getLevelUpExperience();
|
||||
final double ratio = info.getExperience() / nextLevelExp;
|
||||
|
||||
StringBuilder bar = new StringBuilder("" + ChatColor.BOLD);
|
||||
int chars = (int) (ratio * 20);
|
||||
@ -102,17 +123,10 @@ 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;
|
||||
}
|
||||
@ -140,9 +154,9 @@ public class ClassConfirmation extends EditableInventory {
|
||||
|
||||
@Override
|
||||
public String calculateName() {
|
||||
if (GUIName != null)
|
||||
return GUIName;
|
||||
return getName();
|
||||
final String professKey = MMOCoreUtils.ymlName(profess.getId());
|
||||
final @Nullable String found = specificNames.get(professKey);
|
||||
return found == null ? getName().replace("{class}", profess.getName()) : found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,17 @@ package net.Indyuce.mmocore.gui;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
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.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.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
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.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -22,7 +21,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
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;
|
||||
|
||||
public class ClassSelect extends EditableInventory {
|
||||
@ -42,21 +43,12 @@ 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() {
|
||||
@ -113,7 +105,6 @@ 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;
|
||||
@ -124,7 +115,7 @@ public class ClassSelect extends EditableInventory {
|
||||
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())) {
|
||||
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(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);
|
||||
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
|
||||
InventoryManager.CLASS_CONFIRM.newInventory(playerData,playerClass, this).open();
|
||||
final PlayerClass playerClass = findDeepestSubclass(playerData, profess);
|
||||
InventoryManager.CLASS_CONFIRM.newInventory(playerData, playerClass, this).open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,15 @@
|
||||
|
||||
# GUI display name
|
||||
name: Class Confirmation
|
||||
# GUI display name, used by default
|
||||
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
|
||||
# between 9 and 54 and must be a multiple of 9.
|
||||
@ -10,7 +19,7 @@ items:
|
||||
yes:
|
||||
slots: [12]
|
||||
function: 'yes'
|
||||
|
||||
|
||||
# Displayed when the player had already selected this class
|
||||
# before (only if class slots are enabled in the config).
|
||||
unlocked:
|
||||
@ -24,13 +33,13 @@ items:
|
||||
- ''
|
||||
- '&7Skill Points: &6{skill_points}'
|
||||
- '&7Skills You Unlocked: &6{unlocked_skills}&7/&6{class_skills}'
|
||||
|
||||
|
||||
# Displayed when the class is being chosen for the first time.
|
||||
locked:
|
||||
item: GREEN_TERRACOTTA
|
||||
name: '&aSelect {class}'
|
||||
lore: {}
|
||||
|
||||
|
||||
back:
|
||||
slots: [14]
|
||||
item: RED_TERRACOTTA
|
||||
|
@ -16,12 +16,3 @@ items:
|
||||
- '{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"
|
||||
|
Loading…
Reference in New Issue
Block a user