Stations name placeholders patched

This commit is contained in:
Roch Blonndiaux 2022-12-08 16:33:13 +01:00
parent d2ad83e218
commit 96d02969fd
6 changed files with 343 additions and 369 deletions

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmoitems.api.crafting;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.crafting.ingredient.inventory.IngredientInventory;
@ -22,7 +21,6 @@ import java.util.logging.Level;
public class CraftingStation extends PostLoadObject {
private final String id;
private final String name;
private final String unparsedName;
private final Layout layout;
private final Sound sound;
private final StationItemOptions itemOptions;
@ -44,8 +42,7 @@ public class CraftingStation extends PostLoadObject {
super(config);
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.unparsedName = config.getString("name", "Unnamed");
this.name = MythicLib.plugin.parseColors(unparsedName);
this.name = config.getString("name", "Unnamed");
this.layout = MMOItems.plugin.getLayouts().getLayout(config.getString("layout", "default"));
this.sound = Sound.valueOf(config.getString("sound", "ENTITY_EXPERIENCE_ORB_PICKUP").toUpperCase());
@ -69,8 +66,7 @@ public class CraftingStation extends PostLoadObject {
Validate.notNull(sound, "Crafting station sound must not be null");
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.unparsedName = name;
this.name = MythicLib.plugin.parseColors(name);
this.name = name;
this.layout = layout;
this.sound = sound;
this.itemOptions = itemOptions;
@ -87,10 +83,6 @@ public class CraftingStation extends PostLoadObject {
return name;
}
public String getUnparsedName() {
return unparsedName;
}
public Layout getLayout() {
return layout;
}

View File

@ -68,7 +68,6 @@ public class StatEdition implements Edition {
@Override
public boolean processInput(String input) {
// apply string input parsers
for (StringInputParser parser : MMOItems.plugin.getStringInputParsers())
input = parser.parseInput(inv.getPlayer(), input);
@ -86,9 +85,7 @@ public class StatEdition implements Edition {
// Success
return true;
} catch (RuntimeException exception) {
// Add message to the FFP
if (!exception.getMessage().isEmpty()) { inv.getFFP().log(FriendlyFeedbackCategory.ERROR, exception.getMessage()); }

View File

@ -4,7 +4,6 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.SmartGive;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.crafting.CraftingStation;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue;
import net.Indyuce.mmoitems.api.crafting.CraftingStatus.CraftingQueue.CraftingInfo;
@ -18,6 +17,7 @@ import net.Indyuce.mmoitems.api.event.PlayerUseCraftingStationEvent;
import net.Indyuce.mmoitems.api.item.util.ConfigItems;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.listener.CustomSoundListener;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -32,232 +32,232 @@ import java.util.List;
import java.util.UUID;
public class CraftingStationView extends PluginInventory {
private final CraftingStation station;
private final Layout layout;
private final CraftingStation station;
private final Layout layout;
private List<CheckedRecipe> recipes;
private IngredientInventory ingredients;
private List<CheckedRecipe> recipes;
private IngredientInventory ingredients;
private int queueOffset;
private int queueOffset;
public CraftingStationView(Player player, CraftingStation station, int page) {
super(player);
public CraftingStationView(Player player, CraftingStation station, int page) {
super(player);
this.station = station;
this.layout = station.getLayout();
this.page = page;
this.station = station;
this.layout = station.getLayout();
this.page = page;
updateData();
}
updateData();
}
public CraftingStation getStation() {
return station;
}
public CraftingStation getStation() {
return station;
}
void updateData() {
ingredients = new IngredientInventory(player);
recipes = station.getAvailableRecipes(playerData, ingredients);
}
void updateData() {
ingredients = new IngredientInventory(player);
recipes = station.getAvailableRecipes(playerData, ingredients);
}
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, layout.getSize(),
MythicLib.plugin.getPlaceholderParser().parse(getPlayer(), station.getName().replace("#page#", "" + page).replace("#max#", "" + station.getMaxPage())));
int min = (page - 1) * layout.getRecipeSlots().size(), max = page * layout.getRecipeSlots().size();
for (int j = min; j < max; j++) {
if (j >= recipes.size()) {
if (station.getItemOptions().hasNoRecipe())
inv.setItem(layout.getRecipeSlots().get(j - min), station.getItemOptions().getNoRecipe());
continue;
}
@Override
public Inventory getInventory() {
final String title = MythicLib.plugin.parseColors(MythicLib.plugin.getPlaceholderParser().parse(getPlayer(), station.getName().replace("#page#", "" + page).replace("#max#", "" + station.getMaxPage())));
Inventory inv = Bukkit.createInventory(this, layout.getSize(), title);
int min = (page - 1) * layout.getRecipeSlots().size(), max = page * layout.getRecipeSlots().size();
for (int j = min; j < max; j++) {
if (j >= recipes.size()) {
if (station.getItemOptions().hasNoRecipe())
inv.setItem(layout.getRecipeSlots().get(j - min), station.getItemOptions().getNoRecipe());
continue;
}
inv.setItem(layout.getRecipeSlots().get(j - min), recipes.get(j).display());
}
inv.setItem(layout.getRecipeSlots().get(j - min), recipes.get(j).display());
}
if (max < recipes.size())
inv.setItem(layout.getRecipeNextSlot(), ConfigItems.NEXT_PAGE.getItem());
if (page > 1)
inv.setItem(layout.getRecipePreviousSlot(), ConfigItems.PREVIOUS_PAGE.getItem());
if (max < recipes.size())
inv.setItem(layout.getRecipeNextSlot(), ConfigItems.NEXT_PAGE.getItem());
if (page > 1)
inv.setItem(layout.getRecipePreviousSlot(), ConfigItems.PREVIOUS_PAGE.getItem());
CraftingQueue queue = playerData.getCrafting().getQueue(station);
for (int j = queueOffset; j < queueOffset + layout.getQueueSlots().size(); j++) {
if (j >= queue.getCrafts().size()) {
if (station.getItemOptions().hasNoQueueItem())
inv.setItem(layout.getQueueSlots().get(j - queueOffset), station.getItemOptions().getNoQueueItem());
continue;
}
CraftingQueue queue = playerData.getCrafting().getQueue(station);
for (int j = queueOffset; j < queueOffset + layout.getQueueSlots().size(); j++) {
if (j >= queue.getCrafts().size()) {
if (station.getItemOptions().hasNoQueueItem())
inv.setItem(layout.getQueueSlots().get(j - queueOffset), station.getItemOptions().getNoQueueItem());
continue;
}
inv.setItem(layout.getQueueSlots().get(j - queueOffset),
ConfigItems.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
}
if (queueOffset + layout.getQueueSlots().size() < queue.getCrafts().size())
inv.setItem(layout.getQueueNextSlot(), ConfigItems.NEXT_IN_QUEUE.getItem());
if (queueOffset > 0)
inv.setItem(layout.getQueuePreviousSlot(), ConfigItems.PREVIOUS_IN_QUEUE.getItem());
inv.setItem(layout.getQueueSlots().get(j - queueOffset),
ConfigItems.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
}
if (queueOffset + layout.getQueueSlots().size() < queue.getCrafts().size())
inv.setItem(layout.getQueueNextSlot(), ConfigItems.NEXT_IN_QUEUE.getItem());
if (queueOffset > 0)
inv.setItem(layout.getQueuePreviousSlot(), ConfigItems.PREVIOUS_IN_QUEUE.getItem());
new BukkitRunnable() {
public void run() {
new BukkitRunnable() {
public void run() {
/*
* easier than caching a boolean and changing its state when
* closing or opening inventories which is glitchy when just
* updating them.
*/
if (inv.getViewers().size() < 1) {
cancel();
return;
}
/*
* easier than caching a boolean and changing its state when
* closing or opening inventories which is glitchy when just
* updating them.
*/
if (inv.getViewers().size() < 1) {
cancel();
return;
}
for (int j = queueOffset; j < queueOffset + layout.getQueueSlots().size(); j++)
if (j >= queue.getCrafts().size())
inv.setItem(layout.getQueueSlots().get(j - queueOffset),
station.getItemOptions().hasNoQueueItem() ? station.getItemOptions().getNoQueueItem() : null);
else
inv.setItem(layout.getQueueSlots().get(j - queueOffset),
ConfigItems.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
}
}.runTaskTimerAsynchronously(MMOItems.plugin, 0, 20);
if (station.getItemOptions().hasFill())
for (int j = 0; j < layout.getSize(); j++)
if (inv.getItem(j) == null || inv.getItem(j).getType() == Material.AIR)
inv.setItem(j, station.getItemOptions().getFill());
for (int j = queueOffset; j < queueOffset + layout.getQueueSlots().size(); j++)
if (j >= queue.getCrafts().size())
inv.setItem(layout.getQueueSlots().get(j - queueOffset),
station.getItemOptions().hasNoQueueItem() ? station.getItemOptions().getNoQueueItem() : null);
else
inv.setItem(layout.getQueueSlots().get(j - queueOffset),
ConfigItems.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
}
}.runTaskTimerAsynchronously(MMOItems.plugin, 0, 20);
if (station.getItemOptions().hasFill())
for (int j = 0; j < layout.getSize(); j++)
if (inv.getItem(j) == null || inv.getItem(j).getType() == Material.AIR)
inv.setItem(j, station.getItemOptions().getFill());
return inv;
}
return inv;
}
@Override
public void whenClicked(InventoryClickEvent event) {
if (!playerData.isOnline())
return;
@Override
public void whenClicked(InventoryClickEvent event) {
if (!playerData.isOnline())
return;
event.setCancelled(true);
if (!MMOUtils.isMetaItem(event.getCurrentItem(), false))
return;
event.setCancelled(true);
if (!MMOUtils.isMetaItem(event.getCurrentItem(), false))
return;
NBTItem nbtItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getCurrentItem());
if (nbtItem.getString("ItemId").equals("PREVIOUS_IN_QUEUE")) {
queueOffset--;
open();
return;
}
NBTItem nbtItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getCurrentItem());
if (nbtItem.getString("ItemId").equals("PREVIOUS_IN_QUEUE")) {
queueOffset--;
open();
return;
}
if (nbtItem.getString("ItemId").equals("NEXT_IN_QUEUE")) {
queueOffset++;
open();
return;
}
if (nbtItem.getString("ItemId").equals("NEXT_IN_QUEUE")) {
queueOffset++;
open();
return;
}
if (nbtItem.getString("ItemId").equals("NEXT_PAGE")) {
page++;
open();
return;
}
if (nbtItem.getString("ItemId").equals("NEXT_PAGE")) {
page++;
open();
return;
}
if (nbtItem.getString("ItemId").equals("PREVIOUS_PAGE")) {
page--;
open();
return;
}
if (nbtItem.getString("ItemId").equals("PREVIOUS_PAGE")) {
page--;
open();
return;
}
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getCurrentItem());
String tag = item.getString("recipeId");
if (!tag.isEmpty()) {
CheckedRecipe recipe = getRecipe(tag);
if (event.isRightClick())
new CraftingStationPreview(this, recipe).open();
else {
processRecipe(recipe);
open();
}
}
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getCurrentItem());
String tag = item.getString("recipeId");
if (!tag.isEmpty()) {
CheckedRecipe recipe = getRecipe(tag);
if (event.isRightClick())
new CraftingStationPreview(this, recipe).open();
else {
processRecipe(recipe);
open();
}
}
if (!(tag = item.getString("queueId")).isEmpty()) {
CraftingInfo recipeInfo = playerData.getCrafting().getQueue(station).getCraft(UUID.fromString(tag));
CraftingRecipe recipe = recipeInfo.getRecipe();
if (!(tag = item.getString("queueId")).isEmpty()) {
CraftingInfo recipeInfo = playerData.getCrafting().getQueue(station).getCraft(UUID.fromString(tag));
CraftingRecipe recipe = recipeInfo.getRecipe();
/*
* If the crafting recipe is ready, give the player the output item
* to the player and remove the recipe from the queue
*/
if (recipeInfo.isReady()) {
ItemStack result = recipe.hasOption(Recipe.RecipeOption.OUTPUT_ITEM) ? recipe.getOutputItemStack(playerData.getRPG()) : null;
/*
* If the crafting recipe is ready, give the player the output item
* to the player and remove the recipe from the queue
*/
if (recipeInfo.isReady()) {
ItemStack result = recipe.hasOption(Recipe.RecipeOption.OUTPUT_ITEM) ? recipe.getOutputItemStack(playerData.getRPG()) : null;
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(playerData, station, recipe, result);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(playerData, station, recipe, result);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
// Remove from crafting queue
playerData.getCrafting().getQueue(station).remove(recipeInfo);
recipe.whenClaimed().forEach(trigger -> trigger.whenCrafting(playerData));
// Remove from crafting queue
playerData.getCrafting().getQueue(station).remove(recipeInfo);
recipe.whenClaimed().forEach(trigger -> trigger.whenCrafting(playerData));
// Play sounds
CustomSoundListener.stationCrafting(result, player);
if (!recipe.hasOption(Recipe.RecipeOption.SILENT_CRAFT))
player.playSound(player.getLocation(), station.getSound(), 1, 1);
// Play sounds
CustomSoundListener.stationCrafting(result, player);
if (!recipe.hasOption(Recipe.RecipeOption.SILENT_CRAFT))
player.playSound(player.getLocation(), station.getSound(), 1, 1);
if (result != null)
new SmartGive(player).give(result);
if (result != null)
new SmartGive(player).give(result);
/*
* If the recipe is not ready, cancel the recipe and give the
* ingredients back to the player
*/
} else {
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(playerData, station, recipe);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
/*
* If the recipe is not ready, cancel the recipe and give the
* ingredients back to the player
*/
} else {
PlayerUseCraftingStationEvent called = new PlayerUseCraftingStationEvent(playerData, station, recipe);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
// Remove from crafting queue
playerData.getCrafting().getQueue(station).remove(recipeInfo);
recipe.whenCanceled().forEach(trigger -> trigger.whenCrafting(playerData));
// Remove from crafting queue
playerData.getCrafting().getQueue(station).remove(recipeInfo);
recipe.whenCanceled().forEach(trigger -> trigger.whenCrafting(playerData));
// Play sounds
if (!recipe.hasOption(Recipe.RecipeOption.SILENT_CRAFT))
player.playSound(player.getLocation(), station.getSound(), 1, 1);
// Play sounds
if (!recipe.hasOption(Recipe.RecipeOption.SILENT_CRAFT))
player.playSound(player.getLocation(), station.getSound(), 1, 1);
// Give ingredients back
for (Ingredient ingredient : recipeInfo.getRecipe().getIngredients())
new SmartGive(player).give(ingredient.generateItemStack(playerData.getRPG()));
}
// Give ingredients back
for (Ingredient ingredient : recipeInfo.getRecipe().getIngredients())
new SmartGive(player).give(ingredient.generateItemStack(playerData.getRPG()));
}
updateData();
open();
}
}
updateData();
open();
}
}
public void processRecipe(CheckedRecipe recipe) {
if (!recipe.areConditionsMet()) {
Message.CONDITIONS_NOT_MET.format(ChatColor.RED).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
return;
}
public void processRecipe(CheckedRecipe recipe) {
if (!recipe.areConditionsMet()) {
Message.CONDITIONS_NOT_MET.format(ChatColor.RED).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
return;
}
if (!recipe.allIngredientsHad()) {
Message.NOT_ENOUGH_MATERIALS.format(ChatColor.RED).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
return;
}
if (!recipe.allIngredientsHad()) {
Message.NOT_ENOUGH_MATERIALS.format(ChatColor.RED).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
return;
}
if (!recipe.getRecipe().canUse(playerData, ingredients, recipe, station)) {
updateData();
return;
}
if (!recipe.getRecipe().canUse(playerData, ingredients, recipe, station)) {
updateData();
return;
}
if (recipe.getRecipe().whenUsed(playerData, ingredients, recipe, station)) {
recipe.getIngredients().forEach(ingredient -> ingredient.takeAway());
recipe.getConditions().forEach(condition -> condition.getCondition().whenCrafting(playerData));
recipe.getRecipe().whenUsed().forEach(trigger -> trigger.whenCrafting(playerData));
if (recipe.getRecipe().whenUsed(playerData, ingredients, recipe, station)) {
recipe.getIngredients().forEach(ingredient -> ingredient.takeAway());
recipe.getConditions().forEach(condition -> condition.getCondition().whenCrafting(playerData));
recipe.getRecipe().whenUsed().forEach(trigger -> trigger.whenCrafting(playerData));
updateData();
}
}
updateData();
}
}
private CheckedRecipe getRecipe(String id) {
for (CheckedRecipe info : recipes)
if (info.getRecipe().getId().equals(id))
return info;
return null;
}
private CheckedRecipe getRecipe(String id) {
for (CheckedRecipe info : recipes)
if (info.getRecipe().getId().equals(id))
return info;
return null;
}
}

View File

@ -5,10 +5,10 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -20,100 +20,98 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class ItemEdition extends EditionInventory {
private static final int[] slots = { 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43 };
private static final int[] slots = {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43};
public ItemEdition(Player player, MMOItemTemplate template) {
super(player, template);
}
public ItemEdition(Player player, MMOItemTemplate template) {
super(player, template);
}
@Override
public Inventory getInventory() {
int min = (page - 1) * slots.length;
int max = page * slots.length;
int n = 0;
@Override
public Inventory getInventory() {
int min = (page - 1) * slots.length;
int max = page * slots.length;
int n = 0;
/*
* it has to determine what stats can be applied first because otherwise
* the for loop will just let some slots empty
*/
List<ItemStat> appliable = new ArrayList<>(getEdited().getType().getAvailableStats()).stream()
.filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat)).collect(Collectors.toList());
/*
* it has to determine what stats can be applied first because otherwise
* the for loop will just let some slots empty
*/
List<ItemStat> appliable = new ArrayList<>(getEdited().getType().getAvailableStats()).stream()
.filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat)).toList();
Inventory inv = Bukkit.createInventory(this, 54, "Item Edition: " + getEdited().getId());
for (int j = min; j < Math.min(appliable.size(), max); j++) {
ItemStat stat = appliable.get(j);
ItemStack item = new ItemStack(stat.getDisplayMaterial());
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(ChatColor.GREEN + stat.getName());
List<String> lore = new ArrayList<>();
for (String s1 : stat.getLore())
lore.add(ChatColor.GRAY + MythicLib.plugin.parseColors(s1));
lore.add("");
Inventory inv = Bukkit.createInventory(this, 54, "Item Edition: " + getEdited().getId());
for (int j = min; j < Math.min(appliable.size(), max); j++) {
ItemStat stat = appliable.get(j);
ItemStack item = new ItemStack(stat.getDisplayMaterial());
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(ChatColor.GREEN + stat.getName());
List<String> lore = MythicLib.plugin.parseColors(Arrays.stream(stat.getLore()).map(s -> ChatColor.GRAY + s).toList());
lore.add("");
stat.whenDisplayed(lore, getEventualStatData(stat));
stat.whenDisplayed(lore, getEventualStatData(stat));
meta.setLore(lore);
item.setItemMeta(meta);
inv.setItem(slots[n++], MythicLib.plugin.getVersion().getWrapper().getNBTItem(item).addTag(new ItemTag("guiStat", stat.getId())).toItem());
}
meta.setLore(lore);
item.setItemMeta(meta);
inv.setItem(slots[n++], MythicLib.plugin.getVersion().getWrapper().getNBTItem(item).addTag(new ItemTag("guiStat", stat.getId())).toItem());
}
ItemStack glass = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
ItemMeta glassMeta = glass.getItemMeta();
glassMeta.setDisplayName(ChatColor.RED + "- No Item Stat -");
glass.setItemMeta(glassMeta);
ItemStack glass = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
ItemMeta glassMeta = glass.getItemMeta();
glassMeta.setDisplayName(ChatColor.RED + "- No Item Stat -");
glass.setItemMeta(glassMeta);
ItemStack next = new ItemStack(Material.ARROW);
ItemMeta nextMeta = next.getItemMeta();
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
next.setItemMeta(nextMeta);
ItemStack next = new ItemStack(Material.ARROW);
ItemMeta nextMeta = next.getItemMeta();
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
next.setItemMeta(nextMeta);
ItemStack previous = new ItemStack(Material.ARROW);
ItemMeta previousMeta = previous.getItemMeta();
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
previous.setItemMeta(previousMeta);
ItemStack previous = new ItemStack(Material.ARROW);
ItemMeta previousMeta = previous.getItemMeta();
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
previous.setItemMeta(previousMeta);
addEditionInventoryItems(inv, true);
addEditionInventoryItems(inv, true);
while (n < slots.length)
inv.setItem(slots[n++], glass);
inv.setItem(27, page > 1 ? previous : null);
inv.setItem(35, appliable.size() > max ? next : null);
while (n < slots.length)
inv.setItem(slots[n++], glass);
inv.setItem(27, page > 1 ? previous : null);
inv.setItem(35, appliable.size() > max ? next : null);
return inv;
}
return inv;
}
@Override
public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true);
if (event.getInventory() != event.getClickedInventory())
return;
@Override
public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true);
if (event.getInventory() != event.getClickedInventory())
return;
ItemStack item = event.getCurrentItem();
if (!MMOUtils.isMetaItem(item, false) || event.getInventory().getItem(4) == null)
return;
ItemStack item = event.getCurrentItem();
if (!MMOUtils.isMetaItem(item, false) || event.getInventory().getItem(4) == null)
return;
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) {
page++;
open();
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) {
page++;
open();
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Previous Page")) {
page--;
open();
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Previous Page")) {
page--;
open();
}
String tag = NBTItem.get(item).getString("guiStat");
if (!tag.equals(""))
MMOItems.plugin.getStats().get(tag).whenClicked(this, event);
}
String tag = NBTItem.get(item).getString("guiStat");
if (!tag.equals(""))
MMOItems.plugin.getStats().get(tag).whenClicked(this, event);
}
public ItemEdition onPage(int value) {
page = value;
return this;
}
public ItemEdition onPage(int value) {
page = value;
return this;
}
}

View File

@ -35,15 +35,14 @@ public class DisplayName extends StringStat implements GemStoneStat {
String format = data.toString();
ItemTier tier = item.getMMOItem().getTier();
format = format.replace("<tier-name>", tier != null ? parser.stripColors(tier.getUnparsedName()) : "");
format = format.replace("<tier-color>", tier != null ? parser.lastColor(tier.getUnparsedName(), true) : "&f");
format = format.replace("<tier-color-cleaned>", tier != null ? parser.lastColor(tier.getUnparsedName(), false) : "");
format = format.replace("<tier-name>", tier != null ? parser.stripColors(tier.getUnparsedName()) : "")
.replace("<tier-color>", tier != null ? parser.lastColor(tier.getUnparsedName(), true) : "&f")
.replace("<tier-color-cleaned>", tier != null ? parser.lastColor(tier.getUnparsedName(), false) : "");
// Is this upgradable?
format = cropUpgrade(format);
if (item.getMMOItem().hasUpgradeTemplate()) {
if (item.getMMOItem().hasUpgradeTemplate())
format = appendUpgradeLevel(format, item.getMMOItem().getUpgradeLevel());
}
item.getMeta().setDisplayName(format);

View File

@ -1,104 +1,92 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import org.apache.commons.lang.Validate;
import org.bouncycastle.util.StringList;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Lore extends StringListStat implements GemStoneStat {
public Lore() {
super("LORE", VersionMaterial.WRITABLE_BOOK.toMaterial(), "Lore", new String[] { "The item lore." }, new String[] { "all" });
}
public Lore() {
super("LORE", VersionMaterial.WRITABLE_BOOK.toMaterial(), "Lore", new String[]{"The item lore."}, new String[]{"all"});
}
@Override
@SuppressWarnings("unchecked")
public StringListData whenInitialized(Object object) {
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
return new StringListData((List<String>) object);
}
@Override
@SuppressWarnings("unchecked")
public StringListData whenInitialized(Object object) {
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
return new StringListData((List<String>) object);
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
// Apply yes
item.addItemTag(getAppliedNBT(data));
}
// Apply yes
item.addItemTag(getAppliedNBT(data));
}
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(inv, ItemStats.LORE).enable("Write in the chat the lore line you want to add.");
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(inv, ItemStats.LORE).enable("Write in the chat the lore line you want to add.");
if (event.getAction() == InventoryAction.PICKUP_HALF && inv.getEditedSection().contains("lore")) {
List<String> lore = inv.getEditedSection().getStringList("lore");
if (lore.isEmpty())
return;
if (event.getAction() == InventoryAction.PICKUP_HALF && inv.getEditedSection().contains("lore")) {
List<String> lore = inv.getEditedSection().getStringList("lore");
if (lore.isEmpty())
return;
String last = lore.get(lore.size() - 1);
lore.remove(last);
inv.getEditedSection().set("lore", lore.isEmpty() ? null : lore);
inv.registerTemplateEdition();
inv.getPlayer()
.sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + MythicLib.plugin.parseColors(last) + ChatColor.GRAY + "'.");
}
}
String last = lore.get(lore.size() - 1);
lore.remove(last);
inv.getEditedSection().set("lore", lore.isEmpty() ? null : lore);
inv.registerTemplateEdition();
inv.getPlayer()
.sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + MythicLib.plugin.parseColors(last) + ChatColor.GRAY + "'.");
}
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
List<String> lore = inv.getEditedSection().contains("lore") ? inv.getEditedSection().getStringList("lore") : new ArrayList<>();
lore.add(message);
inv.getEditedSection().set("lore", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Lore successfully added.");
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
List<String> lore = inv.getEditedSection().contains("lore") ? inv.getEditedSection().getStringList("lore") : new ArrayList<>();
lore.add(message);
inv.getEditedSection().set("lore", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Lore successfully added.");
}
@Override
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
@Override
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
statData.ifPresentOrElse(stringListData -> {
lore.add(ChatColor.GRAY + "Current Value:");
lore.addAll(MythicLib.plugin.parseColors(stringListData.getList()
.stream()
.map(s -> ChatColor.GRAY + s)
.toList()));
}, () -> lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None"));
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
StringListData data = statData.get();
data.getList().forEach(element -> lore.add(ChatColor.GRAY + MythicLib.plugin.parseColors(element)));
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a line.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last line.");
}
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None");
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a line.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last line.");
}
/*
* The lore is not directly inserted into the final itemStack lore
* because all stats have not registered all their lore placeholders
* yet. The lore is only saved in a JSon array so that it can be
* recalculated LATER on with right placeholders
*/
/*
* The lore is not directly inserted into the final itemStack lore
* because all stats have not registered all their lore placeholders
* yet. The lore is only saved in a JSon array so that it can be
* recalculated LATER on with right placeholders
*/
}