Skip to content

Commit

Permalink
Fix skill indicators in NewSkillGUI
Browse files Browse the repository at this point in the history
Also fix performance issue in NewSkillGUI and NewEnchantmentGUI, where page button are added multiple times.
  • Loading branch information
Sentropic committed Jul 4, 2023
1 parent 1d14578 commit 9f673fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ protected void onCreate(@NotNull Player player, @NotNull Inventory inventory, in
this.addButton(this.createButton(key, ItemType.NEW, Material.ENCHANTED_BOOK,
"&e"+key, List.of(
"&6Left-Click: &eSet"), invIndex, guiClick));
this.addButton(this.createButton("prev-page", ContentType.BACK, Material.ENDER_PEARL, "&dPrevious Page", List.of(), 0, guiClick));
this.addButton(this.createButton("next-page", ContentType.NEXT, Material.ENDER_PEARL, "&dNext Page", List.of(), 8, guiClick));
this.addButton(this.createButton("return", ContentType.RETURN, Material.BARRIER, "&c&lReturn", List.of(), 53, guiClick));
}
this.addButton(this.createButton("prev-page", ContentType.BACK, Material.ENDER_PEARL, "&dPrevious Page", List.of(), 0, guiClick));
this.addButton(this.createButton("next-page", ContentType.NEXT, Material.ENDER_PEARL, "&dNext Page", List.of(), 8, guiClick));
this.addButton(this.createButton("return", ContentType.RETURN, Material.BARRIER, "&c&lReturn", List.of(), 53, guiClick));
}

private void sendSetMessage(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.quantumrpg.QuantumRPG;
import su.nightexpress.quantumrpg.hooks.EHook;
import su.nightexpress.quantumrpg.hooks.external.SkillAPIHK;
import su.nightexpress.quantumrpg.modules.list.itemgenerator.ItemGeneratorManager;
import su.nightexpress.quantumrpg.modules.list.itemgenerator.editor.AbstractEditorGUI;
import su.nightexpress.quantumrpg.modules.list.itemgenerator.editor.EditorGUI;
Expand Down Expand Up @@ -73,16 +78,33 @@ public void run() {
}.runTask(plugin);
}
};
SkillAPIHK skillAPIHK = (SkillAPIHK) QuantumRPG.getInstance().getHook(EHook.SKILL_API);
for (int enchantmentIndex = (currentPage-1)*42, last = Math.min(this.list.size(), enchantmentIndex+42), invIndex = 1;
enchantmentIndex < last; enchantmentIndex++, invIndex++) {
if ((invIndex)%9 == 8) { invIndex += 2; }
String key = this.list.get(enchantmentIndex);
this.addButton(this.createButton(key, ItemType.NEW, Material.ENCHANTED_BOOK,
"&e"+key, List.of(
"&6Left-Click: &eSet"), invIndex, guiClick));
this.addButton(this.createButton("prev-page", ContentType.BACK, Material.ENDER_PEARL, "&dPrevious Page", List.of(), 0, guiClick));
this.addButton(this.createButton("next-page", ContentType.NEXT, Material.ENDER_PEARL, "&dNext Page", List.of(), 8, guiClick));
this.addButton(this.createButton("return", ContentType.RETURN, Material.BARRIER, "&c&lReturn", List.of(), 53, guiClick));
GuiItem guiItem = this.createButton(key, ItemType.NEW, Material.JACK_O_LANTERN,
"&e"+key, List.of("&6Left-Click: &eAdd"), invIndex, guiClick);
if (skillAPIHK != null) {
ItemStack indicator = skillAPIHK.getSkillIndicator(key);
if (indicator != null) {
ItemStack itemStack = guiItem.getItemRaw();
itemStack.setType(indicator.getType());
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta != null) {
ItemMeta indicatorMeta = indicator.getItemMeta();
if (indicatorMeta != null && indicatorMeta.hasCustomModelData()) {
itemMeta.setCustomModelData(indicatorMeta.getCustomModelData());
itemStack.setItemMeta(itemMeta);
}
}
guiItem.setItem(itemStack);
}
}
this.addButton(guiItem);
}
this.addButton(this.createButton("prev-page", ContentType.BACK, Material.ENDER_PEARL, "&dPrevious Page", List.of(), 0, guiClick));
this.addButton(this.createButton("next-page", ContentType.NEXT, Material.ENDER_PEARL, "&dNext Page", List.of(), 8, guiClick));
this.addButton(this.createButton("return", ContentType.RETURN, Material.BARRIER, "&c&lReturn", List.of(), 53, guiClick));
}
}

0 comments on commit 9f673fa

Please sign in to comment.