Bug Fixing for the refacto

This commit is contained in:
Ka0rX 2023-09-12 16:12:46 +01:00
parent ed17756842
commit 4db1a93436
19 changed files with 196 additions and 173 deletions

View File

@ -34,7 +34,7 @@ public class ClassCommand extends RegisteredCommand {
if (data.getProfess().getSubclasses().stream().anyMatch(sub -> sub.getLevel() <= data.getLevel())) if (data.getProfess().getSubclasses().stream().anyMatch(sub -> sub.getLevel() <= data.getLevel()))
InventoryManager.SUBCLASS_SELECT.newInventory(data).open(); InventoryManager.SUBCLASS_SELECT.newInventory(data).open();
else else
InventoryManager.CLASS_SELECT.newInventory(data).open(); InventoryManager.CLASS_SELECT.generate(data).open();
return true; return true;
} }
} }

View File

@ -28,7 +28,7 @@ public class PlayerStatsCommand extends RegisteredCommand {
PlayerData data = PlayerData.get((Player) sender); PlayerData data = PlayerData.get((Player) sender);
MMOCommandEvent event = new MMOCommandEvent(data, "profile"); MMOCommandEvent event = new MMOCommandEvent(data, "profile");
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) InventoryManager.PLAYER_STATS.newInventory(data).open(); if (!event.isCancelled()) InventoryManager.PLAYER_STATS.generate(data).open();
return true; return true;
} }
} }

View File

@ -21,7 +21,7 @@ public class WaypointsCommand extends RegisteredCommand {
PlayerData data = PlayerData.get((Player) sender); PlayerData data = PlayerData.get((Player) sender);
MMOCommandEvent event = new MMOCommandEvent(data, "waypoints"); MMOCommandEvent event = new MMOCommandEvent(data, "waypoints");
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled()) InventoryManager.WAYPOINTS.newInventory(data).open(); if(!event.isCancelled()) InventoryManager.WAYPOINTS.generate(data).open();
} }
return true; return true;
} }

View File

@ -28,7 +28,7 @@ public class OpenCommandTreeNode extends CommandTreeNode {
return CommandResult.FAILURE; return CommandResult.FAILURE;
} }
InventoryManager.WAYPOINTS.newInventory(PlayerData.get(player)).open(); InventoryManager.WAYPOINTS.generate(PlayerData.get(player)).open();
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
} }

View File

@ -47,7 +47,7 @@ public class ForceClassProfileDataModule implements ProfileDataModule, Listener
} }
final PlayerData playerData = PlayerData.get(event.getPlayerData().getPlayer()); final PlayerData playerData = PlayerData.get(event.getPlayerData().getPlayer());
InventoryManager.CLASS_SELECT.newInventory(playerData, () -> event.validate(this)).open(); InventoryManager.CLASS_SELECT.generate(playerData, () -> event.validate(this)).open();
} }
/** /**
@ -62,7 +62,7 @@ public class ForceClassProfileDataModule implements ProfileDataModule, Listener
if (!event.hasProfileEvent()) { if (!event.hasProfileEvent()) {
Validate.isTrue(MythicLib.plugin.getProfileMode() == ProfileMode.PROXY, "Listened to a data load event with no profile event attached but proxy-based profiles are disabled"); Validate.isTrue(MythicLib.plugin.getProfileMode() == ProfileMode.PROXY, "Listened to a data load event with no profile event attached but proxy-based profiles are disabled");
if (playerData.getProfess().equals(MMOCore.plugin.classManager.getDefaultClass())) if (playerData.getProfess().equals(MMOCore.plugin.classManager.getDefaultClass()))
InventoryManager.CLASS_SELECT.newInventory(playerData, () -> { InventoryManager.CLASS_SELECT.generate(playerData, () -> {
}).open(); }).open();
return; return;
} }
@ -71,7 +71,7 @@ public class ForceClassProfileDataModule implements ProfileDataModule, Listener
// Validate if necessary // Validate if necessary
if (playerData.getProfess().equals(MMOCore.plugin.classManager.getDefaultClass())) if (playerData.getProfess().equals(MMOCore.plugin.classManager.getDefaultClass()))
InventoryManager.CLASS_SELECT.newInventory(playerData, () -> event1.validate(this)).open(); InventoryManager.CLASS_SELECT.generate(playerData, () -> event1.validate(this)).open();
else event1.validate(this); else event1.validate(this);
} }
} }

View File

@ -1,5 +1,10 @@
package net.Indyuce.mmocore.gui; package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.gui.framework.EditableInventory;
import io.lumine.mythic.lib.gui.framework.GeneratedInventory;
import io.lumine.mythic.lib.gui.framework.item.InventoryItem;
import io.lumine.mythic.lib.gui.framework.item.Placeholders;
import io.lumine.mythic.lib.gui.framework.item.SimpleItem;
import io.lumine.mythic.lib.manager.StatManager; import io.lumine.mythic.lib.manager.StatManager;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
@ -9,149 +14,154 @@ import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.api.SoundEvent; import net.Indyuce.mmocore.api.SoundEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;
public class AttributeView extends EditableInventory { public class AttributeView extends EditableInventory<PlayerData> {
public AttributeView() { public AttributeView() {
super("attribute-view"); super("attribute-view");
} }
@Override
public InventoryItem loadItem(String function, ConfigurationSection config) {
if (function.equalsIgnoreCase("reallocation"))
return new InventoryItem(config) {
@Override
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
Placeholders holders = new Placeholders();
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
holders.register("points", inv.getPlayerData().getAttributeReallocationPoints());
holders.register("total", inv.getPlayerData().getAttributes().countPoints());
return holders;
}
};
return function.startsWith("attribute_") ? new AttributeItem(function, config) : new SimpleItem(config); @Override
} public InventoryItem loadItem(String function, ConfigurationSection config) {
if (function.equalsIgnoreCase("reallocation"))
return new InventoryItem<AttributeViewerInventory>(config) {
public GeneratedInventory newInventory(PlayerData data) { @Override
return new AttributeViewerInventory(data, this); public Placeholders getPlaceholders(AttributeViewerInventory inv, int n) {
} Placeholders holders = new Placeholders();
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
holders.register("points", inv.getPlayerData().getAttributeReallocationPoints());
holders.register("total", inv.getPlayerData().getAttributes().countPoints());
return holders;
}
};
public static class AttributeItem extends InventoryItem { return function.startsWith("attribute_") ? new AttributeItem(function, config) : new SimpleItem(config);
private final PlayerAttribute attribute; }
private final int shiftCost;
public AttributeItem(String function, ConfigurationSection config) { @Override
super(config); public GeneratedInventory generate(PlayerData playerData, @Nullable GeneratedInventory generatedInventory) {
return new AttributeViewerInventory(playerData, this);
}
attribute = MMOCore.plugin.attributeManager public static class AttributeItem extends InventoryItem<AttributeViewerInventory> {
.get(function.substring("attribute_".length()).toLowerCase().replace(" ", "-").replace("_", "-")); private final PlayerAttribute attribute;
shiftCost = Math.max(config.getInt("shift-cost"), 1); private final int shiftCost;
}
@Override public AttributeItem(String function, ConfigurationSection config) {
public Placeholders getPlaceholders(GeneratedInventory inv, int n) { super(config);
int total = inv.getPlayerData().getAttributes().getInstance(attribute).getTotal();
Placeholders holders = new Placeholders(); attribute = MMOCore.plugin.attributeManager
holders.register("name", attribute.getName()); .get(function.substring("attribute_".length()).toLowerCase().replace(" ", "-").replace("_", "-"));
holders.register("buffs", attribute.getBuffs().size()); shiftCost = Math.max(config.getInt("shift-cost"), 1);
holders.register("spent", inv.getPlayerData().getAttributes().getInstance(attribute).getBase()); }
holders.register("max", attribute.getMax());
holders.register("current", total);
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
holders.register("shift_points", shiftCost);
attribute.getBuffs().forEach(buff -> {
final String stat = buff.getStat();
holders.register("buff_" + buff.getStat().toLowerCase(), StatManager.format(stat, buff.getValue()));
holders.register("total_" + buff.getStat().toLowerCase(), StatManager.format(stat, buff.multiply(total).getValue()));
});
return holders; @Override
} public Placeholders getPlaceholders(AttributeViewerInventory inv, int n) {
} int total = inv.getPlayerData().getAttributes().getInstance(attribute).getTotal();
public class AttributeViewerInventory extends GeneratedInventory { Placeholders holders = new Placeholders();
holders.register("name", attribute.getName());
holders.register("buffs", attribute.getBuffs().size());
holders.register("spent", inv.getPlayerData().getAttributes().getInstance(attribute).getBase());
holders.register("max", attribute.getMax());
holders.register("current", total);
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
holders.register("shift_points", shiftCost);
attribute.getBuffs().forEach(buff -> {
final String stat = buff.getStat();
holders.register("buff_" + buff.getStat().toLowerCase(), StatManager.format(stat, buff.getValue()));
holders.register("total_" + buff.getStat().toLowerCase(), StatManager.format(stat, buff.multiply(total).getValue()));
});
public AttributeViewerInventory(PlayerData playerData, EditableInventory editable) { return holders;
super(playerData, editable); }
}
} public class AttributeViewerInventory extends GeneratedInventory<PlayerData> {
@Override public AttributeViewerInventory(PlayerData playerData, EditableInventory editable) {
public String calculateName() { super(playerData, editable);
return getName();
}
@Override }
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
if (item.getFunction().equalsIgnoreCase("reallocation")) { @Override
int spent = playerData.getAttributes().countPoints(); public String applyNamePlaceholders(String s) {
if (spent < 1) { return s;
MMOCore.plugin.configManager.getSimpleMessage("no-attribute-points-spent").send(player); }
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
return;
}
if (playerData.getAttributeReallocationPoints() < 1) { @Override
MMOCore.plugin.configManager.getSimpleMessage("not-attribute-reallocation-point").send(player); public void whenClicked(InventoryClickEvent event, InventoryItem item) {
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
return;
}
playerData.getAttributes().getInstances().forEach(ins -> ins.setBase(0)); if (item.getFunction().equalsIgnoreCase("reallocation")) {
playerData.giveAttributePoints(spent); int spent = playerData.getAttributes().countPoints();
playerData.giveAttributeReallocationPoints(-1); if (spent < 1) {
MMOCore.plugin.configManager.getSimpleMessage("attribute-points-reallocated", "points", "" + playerData.getAttributePoints()).send(player); MMOCore.plugin.configManager.getSimpleMessage("no-attribute-points-spent").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.RESET_ATTRIBUTES).playTo(getPlayer()); MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
open(); return;
} }
if (item.getFunction().startsWith("attribute_")) { if (playerData.getAttributeReallocationPoints() < 1) {
PlayerAttribute attribute = ((AttributeItem) item).attribute; MMOCore.plugin.configManager.getSimpleMessage("not-attribute-reallocation-point").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
return;
}
if (playerData.getAttributePoints() < 1) { playerData.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point").send(player); playerData.giveAttributePoints(spent);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer()); playerData.giveAttributeReallocationPoints(-1);
return; MMOCore.plugin.configManager.getSimpleMessage("attribute-points-reallocated", "points", "" + playerData.getAttributePoints()).send(player);
} MMOCore.plugin.soundManager.getSound(SoundEvent.RESET_ATTRIBUTES).playTo(getPlayer());
open();
}
PlayerAttributes.AttributeInstance ins = playerData.getAttributes().getInstance(attribute); if (item.getFunction().startsWith("attribute_")) {
if (attribute.hasMax() && ins.getBase() >= attribute.getMax()) { PlayerAttribute attribute = ((AttributeItem) item).attribute;
MMOCore.plugin.configManager.getSimpleMessage("attribute-max-points-hit").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
return;
}
// Amount of points spent if (playerData.getAttributePoints() < 1) {
final boolean shiftClick = event.getClick().isShiftClick(); MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point").send(player);
int pointsSpent = shiftClick ? ((AttributeItem) item).shiftCost : 1; MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
if (attribute.hasMax()) return;
pointsSpent = Math.min(pointsSpent, attribute.getMax() - ins.getBase()); }
if (shiftClick && playerData.getAttributePoints() < pointsSpent) { PlayerAttributes.AttributeInstance ins = playerData.getAttributes().getInstance(attribute);
MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point-shift", "shift_points", String.valueOf(pointsSpent)).send(player); if (attribute.hasMax() && ins.getBase() >= attribute.getMax()) {
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer()); MMOCore.plugin.configManager.getSimpleMessage("attribute-max-points-hit").send(player);
return; MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
} return;
}
ins.addBase(pointsSpent); // Amount of points spent
playerData.giveAttributePoints(-pointsSpent); final boolean shiftClick = event.getClick().isShiftClick();
int pointsSpent = shiftClick ? ((AttributeItem) item).shiftCost : 1;
if (attribute.hasMax())
pointsSpent = Math.min(pointsSpent, attribute.getMax() - ins.getBase());
// Apply exp table as many times as required if (shiftClick && playerData.getAttributePoints() < pointsSpent) {
if (attribute.hasExperienceTable()) MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point-shift", "shift_points", String.valueOf(pointsSpent)).send(player);
while (pointsSpent-- > 0) MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
attribute.getExperienceTable().claim(playerData, ins.getBase(), attribute); return;
}
MMOCore.plugin.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", String.valueOf(ins.getBase())).send(player); ins.addBase(pointsSpent);
MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_ATTRIBUTE).playTo(getPlayer()); playerData.giveAttributePoints(-pointsSpent);
PlayerAttributeUseEvent playerAttributeUseEvent = new PlayerAttributeUseEvent(playerData, attribute); // Apply exp table as many times as required
Bukkit.getServer().getPluginManager().callEvent(playerAttributeUseEvent); if (attribute.hasExperienceTable())
while (pointsSpent-- > 0)
attribute.getExperienceTable().claim(playerData, ins.getBase(), attribute);
open(); MMOCore.plugin.configManager.getSimpleMessage("attribute-level-up", "attribute", attribute.getName(), "level", String.valueOf(ins.getBase())).send(player);
} MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_ATTRIBUTE).playTo(getPlayer());
}
} PlayerAttributeUseEvent playerAttributeUseEvent = new PlayerAttributeUseEvent(playerData, attribute);
Bukkit.getServer().getPluginManager().callEvent(playerAttributeUseEvent);
open();
}
}
}
} }

View File

@ -89,7 +89,7 @@ public class ClassConfirmation extends EditableInventory<PlayerData> {
private final InventoryItem unlocked, locked; private final InventoryItem unlocked, locked;
public YesItem(ConfigurationSection config) { public YesItem(ConfigurationSection config) {
super(Material.BARRIER, config); super(config, Material.BARRIER);
Validate.isTrue(config.contains("unlocked"), "Could not load 'unlocked' config"); Validate.isTrue(config.contains("unlocked"), "Could not load 'unlocked' config");
Validate.isTrue(config.contains("locked"), "Could not load 'locked' config"); Validate.isTrue(config.contains("locked"), "Could not load 'locked' config");
@ -170,8 +170,9 @@ public class ClassConfirmation extends EditableInventory<PlayerData> {
} }
@Override @Override
public String calculateName() { public String applyNamePlaceholders(String s) {
return getName().replace("{class}", profess.getName()); return s.replace("{class}", profess.getName());
} }
} }
} }

View File

@ -41,12 +41,12 @@ public class ClassSelect extends EditableInventory<PlayerData> {
return function.startsWith("class") ? new ClassItem(config) : new SimpleItem(config); return function.startsWith("class") ? new ClassItem(config) : new SimpleItem(config);
} }
public GeneratedInventory newInventory(PlayerData data) { public GeneratedInventory generate(PlayerData playerData, @Nullable GeneratedInventory generatedInventory) {
return newInventory(data, null); return generate(playerData, null, null);
} }
public GeneratedInventory newInventory(PlayerData data, @Nullable Runnable profileRunnable) { public GeneratedInventory generate(PlayerData playerData, @Nullable GeneratedInventory generatedInventory, @Nullable Runnable profileRunnable) {
return new ProfessSelectionInventory(data, this, profileRunnable); return new ProfessSelectionInventory(playerData, this, profileRunnable);
} }
public class ClassItem extends SimpleItem<ProfessSelectionInventory> { public class ClassItem extends SimpleItem<ProfessSelectionInventory> {
@ -55,7 +55,7 @@ public class ClassSelect extends EditableInventory<PlayerData> {
private final PlayerClass playerClass; private final PlayerClass playerClass;
public ClassItem(ConfigurationSection config) { public ClassItem(ConfigurationSection config) {
super(config.contains("item") ? Material.valueOf(UtilityMethods.enumName(config.getString("item"))) : Material.BARRIER, config); super(config, config.contains("item") ? Material.valueOf(UtilityMethods.enumName(config.getString("item"))) : Material.BARRIER);
Validate.isTrue(config.getString("function").length() > 6, "Couldn't find the class associated to: " + config.getString("function")); Validate.isTrue(config.getString("function").length() > 6, "Couldn't find the class associated to: " + config.getString("function"));
String classId = UtilityMethods.enumName(config.getString("function").substring(6)); String classId = UtilityMethods.enumName(config.getString("function").substring(6));
@ -152,7 +152,6 @@ public class ClassSelect extends EditableInventory<PlayerData> {
} }
@Override @Override
public void whenClosed(InventoryCloseEvent event) { public void whenClosed(InventoryCloseEvent event) {
if (profileRunnable != null && !canClose) if (profileRunnable != null && !canClose)

View File

@ -20,22 +20,23 @@ import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.player.stats.StatInfo; import net.Indyuce.mmocore.player.stats.StatInfo;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.Nullable;
import java.util.Objects; import java.util.Objects;
public class PlayerStats extends EditableInventory { public class PlayerStats extends EditableInventory<PlayerData> {
public PlayerStats() { public PlayerStats() {
super("player-stats"); super("player-stats");
} }
@Override @Override
public InventoryItem loadItemItem(String function, ConfigurationSection config) { public InventoryItem loadItem(String function, ConfigurationSection config) {
if (function.equals("boost")) if (function.equals("boost"))
return new BoostItem(config); return new BoostItem(config);
@ -124,7 +125,7 @@ public class PlayerStats extends EditableInventory {
final net.Indyuce.mmocore.api.player.stats.PlayerStats stats = inv.target.getStats(); final net.Indyuce.mmocore.api.player.stats.PlayerStats stats = inv.target.getStats();
@Override @Override
public String apply(OfflinePlayer player, String str) { public String apply(Player player, String str) {
String explored = str; String explored = str;
// Internal placeholders // Internal placeholders
while (explored.contains("{") && explored.substring(explored.indexOf("{")).contains("}")) { while (explored.contains("{") && explored.substring(explored.indexOf("{")).contains("}")) {
@ -161,11 +162,12 @@ public class PlayerStats extends EditableInventory {
return new SimpleItem(config); return new SimpleItem(config);
} }
public PlayerStatsInventory newInventory(PlayerData invTarget, PlayerData opening) { public PlayerStatsInventory generate(PlayerData invTarget, PlayerData opening, @Nullable GeneratedInventory previousInventory) {
return new PlayerStatsInventory(invTarget, opening, this); return new PlayerStatsInventory(invTarget, opening, this);
} }
public PlayerStatsInventory newInventory(PlayerData player) { @Override
public PlayerStatsInventory generate(PlayerData player, @Nullable GeneratedInventory previousInventory) {
return new PlayerStatsInventory(player, player, this); return new PlayerStatsInventory(player, player, this);
} }
@ -186,8 +188,8 @@ public class PlayerStats extends EditableInventory {
} }
@Override @Override
public String calculateName() { public String applyNamePlaceholders(String s) {
return getName(); return s;
} }
@Override @Override

View File

@ -2,7 +2,6 @@ package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.data.SynchronizedDataHolder;
import io.lumine.mythic.lib.gui.framework.EditableInventory; import io.lumine.mythic.lib.gui.framework.EditableInventory;
import io.lumine.mythic.lib.gui.framework.GeneratedInventory; import io.lumine.mythic.lib.gui.framework.GeneratedInventory;
import io.lumine.mythic.lib.gui.framework.item.InventoryItem; import io.lumine.mythic.lib.gui.framework.item.InventoryItem;
@ -35,7 +34,7 @@ public class SubclassSelect extends EditableInventory<PlayerData> {
} }
@Override @Override
public InventoryItem loadItemItem(String function, ConfigurationSection config) { public InventoryItem loadItem(String function, ConfigurationSection config) {
return function.startsWith("sub-class") ? new ClassItem(config) : new SimpleItem(config); return function.startsWith("sub-class") ? new ClassItem(config) : new SimpleItem(config);
} }
@ -51,7 +50,7 @@ public class SubclassSelect extends EditableInventory<PlayerData> {
private final PlayerClass playerClass; private final PlayerClass playerClass;
public ClassItem(ConfigurationSection config) { public ClassItem(ConfigurationSection config) {
super(config.contains("item") ? Material.valueOf(UtilityMethods.enumName(config.getString("item"))) : Material.BARRIER, config); super(config, config.contains("item") ? Material.valueOf(UtilityMethods.enumName(config.getString("item"))) : Material.BARRIER);
Validate.isTrue(config.getString("function").length() > 10, "Couldn't find the class associated to: " + config.getString("function")); Validate.isTrue(config.getString("function").length() > 10, "Couldn't find the class associated to: " + config.getString("function"));
String classId = UtilityMethods.enumName(config.getString("function").substring(10)); String classId = UtilityMethods.enumName(config.getString("function").substring(10));
this.playerClass = Objects.requireNonNull(MMOCore.plugin.classManager.get(classId), classId + " does not correspond to any classId."); this.playerClass = Objects.requireNonNull(MMOCore.plugin.classManager.get(classId), classId + " does not correspond to any classId.");
@ -116,7 +115,7 @@ public class SubclassSelect extends EditableInventory<PlayerData> {
@Override @Override
public void whenClicked(InventoryClickEvent event, InventoryItem item) { public void whenClicked(InventoryClickEvent event, InventoryItem item) {
if (item.getFunction().equals("back")) if (item.getFunction().equals("back"))
InventoryManager.CLASS_SELECT.newInventory(playerData).open(); InventoryManager.CLASS_SELECT.generate(playerData,this).open();
if (item.getFunction().startsWith("sub-class")) { if (item.getFunction().startsWith("sub-class")) {
String classId = UtilityMethods.ymlName(item.getFunction().substring(10)); String classId = UtilityMethods.ymlName(item.getFunction().substring(10));

View File

@ -58,11 +58,12 @@ public class WaypointViewer extends EditableInventory<PlayerData> {
return new SimpleItem(config); return new SimpleItem(config);
} }
public GeneratedInventory newInventory(PlayerData data) { @Override
return newInventory(data, null); public GeneratedInventory generate(PlayerData data, @Nullable GeneratedInventory generatedInventory) {
return newInventory(data, null, null);
} }
public GeneratedInventory newInventory(PlayerData data, Waypoint waypoint) { public GeneratedInventory newInventory(PlayerData data, Waypoint waypoint, @Nullable GeneratedInventory generatedInventory) {
return new WaypointViewerInventory(data, this, waypoint); return new WaypointViewerInventory(data, this, waypoint);
} }
@ -71,7 +72,7 @@ public class WaypointViewer extends EditableInventory<PlayerData> {
private final WaypointItemHandler availWaypoint, noStellium, notLinked, notDynamic, currentWayPoint; private final WaypointItemHandler availWaypoint, noStellium, notLinked, notDynamic, currentWayPoint;
public WaypointItem(ConfigurationSection config) { public WaypointItem(ConfigurationSection config) {
super(Material.BARRIER, config); super(config, Material.BARRIER);
Validate.notNull(config.getConfigurationSection("no-waypoint"), "Could not load 'no-waypoint' config"); Validate.notNull(config.getConfigurationSection("no-waypoint"), "Could not load 'no-waypoint' config");
Validate.notNull(config.getConfigurationSection("locked"), "Could not load 'locked' config"); Validate.notNull(config.getConfigurationSection("locked"), "Could not load 'locked' config");
@ -211,10 +212,11 @@ public class WaypointViewer extends EditableInventory<PlayerData> {
} }
@Override @Override
public String calculateName() { public String applyNamePlaceholders(String s) {
return getName(); return s;
} }
public boolean isDynamicUse() { public boolean isDynamicUse() {
return current == null; return current == null;
} }

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.gui.api.packets; package net.Indyuce.mmocore.gui.api.packets;
import io.lumine.mythic.lib.gui.framework.PluginInventory;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -2,22 +2,25 @@ package net.Indyuce.mmocore.gui.eco;
import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.gui.framework.PluginInventory;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
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.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class GoldPouch extends PluginInventory { public class GoldPouch extends PluginInventory<PlayerData> {
private final boolean mob; private final boolean mob;
private final NBTItem nbt; private final NBTItem nbt;
public GoldPouch(Player player, NBTItem nbt) { public GoldPouch(Player player, NBTItem nbt) {
super(player); super(PlayerData.get(player));
this.nbt = nbt; this.nbt = nbt;
this.mob = nbt.getBoolean("RpgPouchMob"); this.mob = nbt.getBoolean("RpgPouchMob");

View File

@ -57,8 +57,12 @@ public class SkillTreeViewer extends EditableInventory<PlayerData> {
this.defaultSkillTree = initialSkillTree; this.defaultSkillTree = initialSkillTree;
} }
public SkillTreeInventory generate(PlayerData playerData, @Nullable GeneratedInventory previousInventory) {
return new SkillTreeInventory(playerData, this, defaultSkillTree);
}
@Override @Override
public void reload(FileConfiguration config) { public void reload(ConfigurationSection config) {
super.reload(config); super.reload(config);
if (config.contains("status-names")) if (config.contains("status-names"))
for (SkillTreeStatus skillTreeStatus : SkillTreeStatus.values()) for (SkillTreeStatus skillTreeStatus : SkillTreeStatus.values())
@ -127,16 +131,11 @@ public class SkillTreeViewer extends EditableInventory<PlayerData> {
} }
public SkillTreeInventory generate(PlayerData playerData) {
return new SkillTreeInventory(playerData, this, defaultSkillTree);
}
public class SkillTreeItem extends InventoryItem<SkillTreeInventory> { public class SkillTreeItem extends InventoryItem<SkillTreeInventory> {
public SkillTreeItem(ConfigurationSection config) { public SkillTreeItem(ConfigurationSection config) {
//We must use this constructor to show that there are not specified material //We must use this constructor to show that there are not specified material
super(Material.BARRIER, config); super(config, Material.BARRIER);
} }
@ -223,7 +222,7 @@ public class SkillTreeViewer extends EditableInventory<PlayerData> {
public SkillTreeNodeItem(ConfigurationSection config) { public SkillTreeNodeItem(ConfigurationSection config) {
super(Material.AIR, config); super(config, Material.AIR);
if (config.isList("path-lore")) if (config.isList("path-lore"))
pathLore.addAll(config.getStringList("path-lore")); pathLore.addAll(config.getStringList("path-lore"));
} }
@ -409,10 +408,11 @@ public class SkillTreeViewer extends EditableInventory<PlayerData> {
} }
@Override @Override
public String calculateName() { public String applyNamePlaceholders(String s) {
return getEditable().getName().replace("{skill-tree-name}", skillTree.getName()).replace("{skill-tree-id}", skillTree.getId()); return s.replace("{skill-tree-name}", skillTree.getName()).replace("{skill-tree-id}", skillTree.getId());
} }
public IntegerCoordinates getCoordinates(int n) { public IntegerCoordinates getCoordinates(int n) {
int slot = slots.get(n); int slot = slots.get(n);
int deltaX = (slot - getMinSlot()) % 9; int deltaX = (slot - getMinSlot()) % 9;

View File

@ -242,7 +242,7 @@ public class EditableFriendList extends EditableInventory<PlayerData> {
if (tag == null || tag.isEmpty()) if (tag == null || tag.isEmpty())
return; return;
InventoryManager.FRIEND_REMOVAL.newInventory(playerData, Bukkit.getOfflinePlayer(UUID.fromString(tag)), this).open(); InventoryManager.FRIEND_REMOVAL.generate(playerData, Bukkit.getOfflinePlayer(UUID.fromString(tag)), this).open();
} }
} }
} }

View File

@ -11,6 +11,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;
public class EditableFriendRemoval extends EditableInventory<PlayerData> { public class EditableFriendRemoval extends EditableInventory<PlayerData> {
public EditableFriendRemoval() { public EditableFriendRemoval() {
@ -31,7 +32,17 @@ public class EditableFriendRemoval extends EditableInventory<PlayerData> {
}; };
} }
public GeneratedInventory newInventory(PlayerData data, OfflinePlayer friend, GeneratedInventory last) { /**
* Do not use this method but rather use {@link #generate(PlayerData, OfflinePlayer, GeneratedInventory)}
*/
@Deprecated
@Override
public GeneratedInventory generate(PlayerData playerData, @Nullable GeneratedInventory generatedInventory) {
throw new RuntimeException("Unsupported method");
}
public GeneratedInventory generate(PlayerData data, OfflinePlayer friend, GeneratedInventory last) {
return new ClassConfirmationInventory(data, this, friend, last); return new ClassConfirmationInventory(data, this, friend, last);
} }
@ -65,9 +76,5 @@ public class EditableFriendRemoval extends EditableInventory<PlayerData> {
last.open(); last.open();
} }
@Override
public String calculateName() {
return getName();
}
} }
} }

View File

@ -43,7 +43,7 @@ public class EditablePartyCreation extends EditableInventory<PlayerData> {
if (item.getFunction().equals("create")) { if (item.getFunction().equals("create")) {
((MMOCorePartyModule) MMOCore.plugin.partyModule).newRegisteredParty(playerData); ((MMOCorePartyModule) MMOCore.plugin.partyModule).newRegisteredParty(playerData);
InventoryManager.PARTY_VIEW.newInventory(playerData).open(); InventoryManager.PARTY_VIEW.generate(playerData, this).open();
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1); player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
} }

View File

@ -87,8 +87,7 @@ public class EditablePartyView extends EditableInventory<PlayerData> {
if (meta instanceof SkullMeta) if (meta instanceof SkullMeta)
inv.dynamicallyUpdateItem(this, n, disp, current -> { inv.dynamicallyUpdateItem(this, n, disp, current -> {
((SkullMeta) meta).setOwningPlayer(member); ((SkullMeta) meta).setOwningPlayer(member);
current.47 current.setItemMeta(meta);
setItemMeta(meta);
}); });
disp.setItemMeta(meta); disp.setItemMeta(meta);
@ -101,7 +100,7 @@ public class EditablePartyView extends EditableInventory<PlayerData> {
private final MemberDisplayItem member; private final MemberDisplayItem member;
public MemberItem(ConfigurationSection config) { public MemberItem(ConfigurationSection config) {
super(Material.BARRIER, config); super(config, Material.BARRIER);
Validate.notNull(config.contains("empty"), "Could not load empty config"); Validate.notNull(config.contains("empty"), "Could not load empty config");
Validate.notNull(config.contains("member"), "Could not load member config"); Validate.notNull(config.contains("member"), "Could not load member config");

View File

@ -17,6 +17,6 @@ public class PlayerProfileCheck implements Listener {
if (event.getRightClicked().getType() != EntityType.PLAYER || !event.getPlayer().isSneaking() || !MythicLib.plugin.getEntities().canTarget(event.getPlayer(), event.getRightClicked(), InteractionType.SUPPORT_ACTION)) if (event.getRightClicked().getType() != EntityType.PLAYER || !event.getPlayer().isSneaking() || !MythicLib.plugin.getEntities().canTarget(event.getPlayer(), event.getRightClicked(), InteractionType.SUPPORT_ACTION))
return; return;
InventoryManager.PLAYER_STATS.newInventory(PlayerData.get((Player) event.getRightClicked()), PlayerData.get(event.getPlayer())).open(); InventoryManager.PLAYER_STATS.generate(PlayerData.get((Player) event.getRightClicked()), PlayerData.get(event.getPlayer())).open();
} }
} }