mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-01-12 08:01:13 +01:00
Fixed shift click profile check
This commit is contained in:
parent
80b0455fed
commit
f679551b99
@ -5,18 +5,18 @@ import io.lumine.mythic.lib.UtilityMethods;
|
|||||||
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
|
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||||
|
import net.Indyuce.mmocore.api.util.math.format.DelayFormat;
|
||||||
|
import net.Indyuce.mmocore.experience.Booster;
|
||||||
|
import net.Indyuce.mmocore.experience.Profession;
|
||||||
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.item.InventoryItem;
|
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
|
||||||
import net.Indyuce.mmocore.player.stats.StatInfo;
|
|
||||||
import net.Indyuce.mmocore.api.util.math.format.DelayFormat;
|
|
||||||
import net.Indyuce.mmocore.experience.Booster;
|
|
||||||
import net.Indyuce.mmocore.experience.Profession;
|
|
||||||
import net.Indyuce.mmocore.party.AbstractParty;
|
import net.Indyuce.mmocore.party.AbstractParty;
|
||||||
|
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.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -70,7 +70,7 @@ public class PlayerStats extends EditableInventory {
|
|||||||
Validate.isTrue(MMOCore.plugin.professionManager.has(id));
|
Validate.isTrue(MMOCore.plugin.professionManager.has(id));
|
||||||
Profession profession = MMOCore.plugin.professionManager.get(id);
|
Profession profession = MMOCore.plugin.professionManager.get(id);
|
||||||
|
|
||||||
return new InventoryItem(config) {
|
return new InventoryItem<PlayerStatsInventory>(config) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasDifferentDisplay() {
|
public boolean hasDifferentDisplay() {
|
||||||
@ -78,13 +78,13 @@ public class PlayerStats extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
|
public Placeholders getPlaceholders(PlayerStatsInventory inv, int n) {
|
||||||
|
|
||||||
Placeholders holders = new Placeholders();
|
Placeholders holders = new Placeholders();
|
||||||
net.Indyuce.mmocore.api.player.stats.PlayerStats stats = inv.getPlayerData().getStats();
|
net.Indyuce.mmocore.api.player.stats.PlayerStats stats = inv.target.getStats();
|
||||||
|
|
||||||
double ratio = inv.getPlayerData().getCollectionSkills().getExperience(profession)
|
double ratio = inv.target.getCollectionSkills().getExperience(profession)
|
||||||
/ (double) inv.getPlayerData().getCollectionSkills().getLevelUpExperience(profession);
|
/ (double) inv.target.getCollectionSkills().getLevelUpExperience(profession);
|
||||||
|
|
||||||
String bar = "" + ChatColor.BOLD;
|
String bar = "" + ChatColor.BOLD;
|
||||||
int chars = (int) (ratio * 20);
|
int chars = (int) (ratio * 20);
|
||||||
@ -93,8 +93,8 @@ public class PlayerStats extends EditableInventory {
|
|||||||
|
|
||||||
// holders.register("profession", type.getName());
|
// holders.register("profession", type.getName());
|
||||||
holders.register("progress", bar);
|
holders.register("progress", bar);
|
||||||
holders.register("level", "" + inv.getPlayerData().getCollectionSkills().getLevel(profession));
|
holders.register("level", "" + inv.target.getCollectionSkills().getLevel(profession));
|
||||||
holders.register("xp", inv.getPlayerData().getCollectionSkills().getExperience(profession));
|
holders.register("xp", inv.target.getCollectionSkills().getExperience(profession));
|
||||||
holders.register("percent", decimal.format(ratio * 100));
|
holders.register("percent", decimal.format(ratio * 100));
|
||||||
for (StatInfo stat : MMOCore.plugin.statManager.getLoaded())
|
for (StatInfo stat : MMOCore.plugin.statManager.getLoaded())
|
||||||
if (Objects.equals(stat.profession, profession))
|
if (Objects.equals(stat.profession, profession))
|
||||||
@ -109,7 +109,7 @@ public class PlayerStats extends EditableInventory {
|
|||||||
return new PlayerProfileItem(config);
|
return new PlayerProfileItem(config);
|
||||||
|
|
||||||
if (function.equals("stats"))
|
if (function.equals("stats"))
|
||||||
return new InventoryItem(config) {
|
return new InventoryItem<PlayerStatsInventory>(config) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasDifferentDisplay() {
|
public boolean hasDifferentDisplay() {
|
||||||
@ -117,9 +117,9 @@ public class PlayerStats extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
|
public Placeholders getPlaceholders(PlayerStatsInventory inv, int n) {
|
||||||
return new Placeholders() {
|
return new Placeholders() {
|
||||||
final net.Indyuce.mmocore.api.player.stats.PlayerStats stats = inv.getPlayerData().getStats();
|
final net.Indyuce.mmocore.api.player.stats.PlayerStats stats = inv.target.getStats();
|
||||||
|
|
||||||
public String apply(Player player, String str) {
|
public String apply(Player player, String str) {
|
||||||
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
|
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
|
||||||
@ -134,7 +134,7 @@ public class PlayerStats extends EditableInventory {
|
|||||||
replaced = info.format(stats.getStat(info.name) - stats.getBase(info.name));
|
replaced = info.format(stats.getStat(info.name) - stats.getBase(info.name));
|
||||||
} else if (holder.startsWith("attribute_")) {
|
} else if (holder.startsWith("attribute_")) {
|
||||||
PlayerAttribute attr = MMOCore.plugin.attributeManager.get(holder.substring(10).replace("_", "-").toLowerCase());
|
PlayerAttribute attr = MMOCore.plugin.attributeManager.get(holder.substring(10).replace("_", "-").toLowerCase());
|
||||||
replaced = String.valueOf(inv.getPlayerData().getAttributes().getAttribute(attr));
|
replaced = String.valueOf(inv.target.getAttributes().getAttribute(attr));
|
||||||
} else {
|
} else {
|
||||||
StatInfo info = StatInfo.valueOf(UtilityMethods.enumName(holder));
|
StatInfo info = StatInfo.valueOf(UtilityMethods.enumName(holder));
|
||||||
replaced = info.format(stats.getStat(info.name));
|
replaced = info.format(stats.getStat(info.name));
|
||||||
@ -153,15 +153,28 @@ public class PlayerStats extends EditableInventory {
|
|||||||
return new SimplePlaceholderItem(config);
|
return new SimplePlaceholderItem(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStatsInventory newInventory(PlayerData data) {
|
public PlayerStatsInventory newInventory(PlayerData invTarget, PlayerData opening) {
|
||||||
return new PlayerStatsInventory(data, this);
|
return new PlayerStatsInventory(invTarget, opening, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerStatsInventory newInventory(PlayerData player) {
|
||||||
|
return new PlayerStatsInventory(player, player, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerStatsInventory extends GeneratedInventory {
|
public class PlayerStatsInventory extends GeneratedInventory {
|
||||||
|
private final PlayerData target;
|
||||||
|
|
||||||
private int boostOffset;
|
private int boostOffset;
|
||||||
|
|
||||||
public PlayerStatsInventory(PlayerData playerData, EditableInventory editable) {
|
/**
|
||||||
super(playerData, editable);
|
* @param invTarget Target player
|
||||||
|
* @param opening Player opening the inventory
|
||||||
|
* @param inv Corresponding editable inventory
|
||||||
|
*/
|
||||||
|
public PlayerStatsInventory(PlayerData invTarget, PlayerData opening, EditableInventory inv) {
|
||||||
|
super(opening, inv);
|
||||||
|
|
||||||
|
this.target = invTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -188,16 +201,16 @@ public class PlayerStats extends EditableInventory {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PartyMoraleItem extends InventoryItem {
|
public static class PartyMoraleItem extends InventoryItem<PlayerStatsInventory> {
|
||||||
public PartyMoraleItem(ConfigurationSection config) {
|
public PartyMoraleItem(ConfigurationSection config) {
|
||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
|
public Placeholders getPlaceholders(PlayerStatsInventory inv, int n) {
|
||||||
Placeholders holders = new Placeholders();
|
Placeholders holders = new Placeholders();
|
||||||
|
|
||||||
int count = inv.getPlayerData().getParty().getOnlineMembers().size();
|
int count = inv.target.getParty().getOnlineMembers().size();
|
||||||
holders.register("count", "" + count);
|
holders.register("count", "" + count);
|
||||||
for (StatModifier buff : MMOCore.plugin.partyManager.getBonuses())
|
for (StatModifier buff : MMOCore.plugin.partyManager.getBonuses())
|
||||||
holders.register("buff_" + buff.getStat().toLowerCase(), buff.multiply(count - 1).toString());
|
holders.register("buff_" + buff.getStat().toLowerCase(), buff.multiply(count - 1).toString());
|
||||||
@ -206,24 +219,24 @@ public class PlayerStats extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canDisplay(GeneratedInventory inv) {
|
public boolean canDisplay(PlayerStatsInventory inv) {
|
||||||
AbstractParty party = inv.getPlayerData().getParty();
|
AbstractParty party = inv.target.getParty();
|
||||||
return party != null && party.getOnlineMembers().size() > 1;
|
return party != null && party.getOnlineMembers().size() > 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PlayerProfileItem extends InventoryItem {
|
public static class PlayerProfileItem extends InventoryItem<PlayerStatsInventory> {
|
||||||
public PlayerProfileItem(ConfigurationSection config) {
|
public PlayerProfileItem(ConfigurationSection config) {
|
||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack display(GeneratedInventory inv, int n) {
|
public ItemStack display(PlayerStatsInventory inv, int n) {
|
||||||
ItemStack disp = super.display(inv, n);
|
ItemStack disp = super.display(inv, n);
|
||||||
if (disp.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
if (disp.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
|
||||||
SkullMeta meta = (SkullMeta) disp.getItemMeta();
|
SkullMeta meta = (SkullMeta) disp.getItemMeta();
|
||||||
inv.dynamicallyUpdateItem(this, n, disp, current -> {
|
inv.dynamicallyUpdateItem(this, n, disp, current -> {
|
||||||
meta.setOwningPlayer(inv.getPlayer());
|
meta.setOwningPlayer(inv.target.getPlayer());
|
||||||
current.setItemMeta(meta);
|
current.setItemMeta(meta);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -231,11 +244,11 @@ public class PlayerStats extends EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
|
public Placeholders getPlaceholders(PlayerStatsInventory inv, int n) {
|
||||||
PlayerData data = inv.getPlayerData();
|
PlayerData data = inv.target;
|
||||||
Placeholders holders = new Placeholders();
|
Placeholders holders = new Placeholders();
|
||||||
|
|
||||||
int nextLevelExp = inv.getPlayerData().getLevelUpExperience();
|
int nextLevelExp = inv.target.getLevelUpExperience();
|
||||||
double ratio = (double) data.getExperience() / (double) nextLevelExp;
|
double ratio = (double) data.getExperience() / (double) nextLevelExp;
|
||||||
|
|
||||||
StringBuilder bar = new StringBuilder("" + ChatColor.BOLD);
|
StringBuilder bar = new StringBuilder("" + ChatColor.BOLD);
|
||||||
|
@ -2,8 +2,8 @@ package net.Indyuce.mmocore.gui.api;
|
|||||||
|
|
||||||
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.gui.api.item.InventoryItem;
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||||
import net.Indyuce.mmocore.gui.api.item.TriggerItem;
|
import net.Indyuce.mmocore.gui.api.item.TriggerItem;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
@ -8,7 +8,6 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
public class PlayerProfileCheck implements Listener {
|
public class PlayerProfileCheck implements Listener {
|
||||||
|
|
||||||
@ -17,14 +16,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(event.getRightClicked().getUniqueId()), PlayerData.get(event.getPlayer())).open();
|
||||||
* This works because the PlayerStats class DOES NOT utilize
|
|
||||||
* at all the player instance saved in the InventoryClickEvent
|
|
||||||
*
|
|
||||||
* Opening inventories like that to other players does NOT
|
|
||||||
* necessarily works for any other custom inventory.
|
|
||||||
* */
|
|
||||||
Inventory inv = InventoryManager.PLAYER_STATS.newInventory(PlayerData.get(event.getRightClicked().getUniqueId())).getInventory();
|
|
||||||
event.getPlayer().openInventory(inv);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user