This commit is contained in:
parent
a75ddc2ac3
commit
3bbd427d7c
4 changed files with 166 additions and 1 deletions
|
@ -0,0 +1,101 @@
|
|||
package me.unurled.sacredrealms.sr.gui.attributes;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import me.unurled.sacredrealms.sr.components.player.PlayerManager;
|
||||
import me.unurled.sacredrealms.sr.components.player.SRPlayer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.xenondevs.inventoryaccess.component.AdventureComponentWrapper;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AbstractItem;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
||||
public class AttributeItem extends AbstractItem {
|
||||
|
||||
private final Attribute attribute;
|
||||
|
||||
private final Player targetPlayer;
|
||||
|
||||
public AttributeItem(Attribute attribute, Player target) {
|
||||
this.attribute = attribute;
|
||||
this.targetPlayer = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link ItemProvider}. This method gets called every time a {@link Window} is notified
|
||||
* ({@link #notifyWindows()}).
|
||||
*
|
||||
* @return The {@link ItemProvider}
|
||||
*/
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
|
||||
double value = 0;
|
||||
|
||||
if (targetPlayer != null) {
|
||||
PlayerManager playerManager = PlayerManager.getInstance(PlayerManager.class);
|
||||
SRPlayer sp = playerManager.getPlayer(targetPlayer.getUniqueId());
|
||||
if (sp != null) value = sp.getAttribute(attribute);
|
||||
}
|
||||
|
||||
ItemBuilder ip =
|
||||
switch (attribute) {
|
||||
case STRENGTH -> new ItemBuilder(Material.IRON_SWORD).setDisplayName("Strength " + value);
|
||||
case AGILITY -> new ItemBuilder(Material.BOW).setDisplayName("Agility " + value);
|
||||
case MANA -> new ItemBuilder(Material.ENCHANTING_TABLE).setDisplayName("Mana " + value);
|
||||
case HEALTH -> new ItemBuilder(Material.GOLDEN_APPLE).setDisplayName("Health " + value);
|
||||
case LUCK ->
|
||||
new ItemBuilder(Material.ENCHANTED_GOLDEN_APPLE).setDisplayName("Luck " + value);
|
||||
case DEFENSE -> new ItemBuilder(Material.SHIELD).setDisplayName("Defense " + value);
|
||||
case CHARISMA ->
|
||||
new ItemBuilder(Material.PLAYER_HEAD).setDisplayName("Charisma " + value);
|
||||
};
|
||||
|
||||
ip.addLoreLines(new AdventureComponentWrapper(comp("<green><b>+1</b> Left Click to increase")));
|
||||
ip.addLoreLines(new AdventureComponentWrapper(comp("<red><b>-1</b> Right Click to decrease")));
|
||||
ip.addLoreLines(
|
||||
new AdventureComponentWrapper(comp("<gray>Shift + Left Click to increase by 10")));
|
||||
ip.addLoreLines(
|
||||
new AdventureComponentWrapper(comp("<gray>Shift + Right Click to decrease by 10")));
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* A method called if the {@link ItemStack} associated to this {@link Item} has been clicked by a
|
||||
* player.
|
||||
*
|
||||
* @param clickType The {@link ClickType} the {@link Player} performed.
|
||||
* @param player The {@link Player} who clicked on the {@link ItemStack}.
|
||||
* @param event The {@link InventoryClickEvent} associated with this click.
|
||||
*/
|
||||
@Override
|
||||
public void handleClick(
|
||||
@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
|
||||
if (targetPlayer != null) {
|
||||
PlayerManager playerManager = PlayerManager.getInstance(PlayerManager.class);
|
||||
SRPlayer sp = playerManager.getPlayer(targetPlayer.getUniqueId());
|
||||
if (sp != null) {
|
||||
if (clickType == ClickType.LEFT) {
|
||||
sp.setAttribute(attribute, sp.getAttribute(attribute) + 1);
|
||||
} else if (clickType == ClickType.RIGHT) {
|
||||
sp.setAttribute(attribute, sp.getAttribute(attribute) - 1);
|
||||
} else if (clickType == ClickType.SHIFT_LEFT) {
|
||||
sp.setAttribute(attribute, sp.getAttribute(attribute) + 10);
|
||||
} else if (clickType == ClickType.SHIFT_RIGHT) {
|
||||
sp.setAttribute(attribute, sp.getAttribute(attribute) - 10);
|
||||
}
|
||||
notifyWindows();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package me.unurled.sacredrealms.sr.gui.attributes;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.Gui.Builder.Normal;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
|
||||
public class AttributesGUI {
|
||||
|
||||
public static Gui createGui(Player target) {
|
||||
ItemStack t = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta tMeta = (SkullMeta) t.getItemMeta();
|
||||
tMeta.setOwningPlayer(target);
|
||||
tMeta.displayName(comp(target.getName()));
|
||||
t.setItemMeta(tMeta);
|
||||
Item head = new SimpleItem(t);
|
||||
Normal gui =
|
||||
Gui.normal()
|
||||
.setStructure(".........", "....h....", ".........", ".0123456.")
|
||||
.addIngredient('h', head);
|
||||
for (int i = 0; i < Attribute.values().length; i++) {
|
||||
Item item = new AttributeItem(Attribute.values()[i], target);
|
||||
gui.addIngredient((char) (i + '0'), item);
|
||||
}
|
||||
return gui.build();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue