diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/ItemCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/ItemCommandTreeNode.java new file mode 100644 index 00000000..d66f5eac --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/ItemCommandTreeNode.java @@ -0,0 +1,44 @@ +package net.Indyuce.mmocore.command.rpg.waypoint; + +import io.lumine.mythic.lib.api.util.SmartGive; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import io.lumine.mythic.lib.command.api.Parameter; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.util.item.WaypointBookBuilder; +import net.Indyuce.mmocore.waypoint.Waypoint; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ItemCommandTreeNode extends CommandTreeNode { + public ItemCommandTreeNode(CommandTreeNode parent) { + super(parent, "item"); + + addParameter(new Parameter("", (explorer, list) -> MMOCore.plugin.waypointManager.getAll().forEach(way -> list.add(way.getId())))); + addParameter(Parameter.PLAYER); + } + + @Override + public CommandResult execute(CommandSender sender, String[] args) { + if (args.length < 4) + return CommandResult.THROW_USAGE; + + if (!MMOCore.plugin.waypointManager.has(args[2])) { + sender.sendMessage(ChatColor.RED + "Could not find waypoint " + args[2]); + return CommandResult.FAILURE; + } + + Player player = Bukkit.getPlayer(args[3]); + if (player == null) { + sender.sendMessage(ChatColor.RED + "Could not find player " + args[3]); + return CommandResult.FAILURE; + } + + Waypoint waypoint = MMOCore.plugin.waypointManager.get(args[2]); + new SmartGive(player).give(new WaypointBookBuilder(waypoint).build()); + sender.sendMessage(ChatColor.GOLD + "Gave " + player.getName() + ChatColor.YELLOW + " a waypoint book of " + ChatColor.GOLD + waypoint.getId() + + ChatColor.YELLOW + "."); + return CommandResult.SUCCESS; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/WaypointsCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/WaypointsCommandTreeNode.java index 839f2995..48aeba29 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/WaypointsCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/WaypointsCommandTreeNode.java @@ -11,6 +11,7 @@ public class WaypointsCommandTreeNode extends CommandTreeNode { addChild(new UnlockCommandTreeNode(this)); addChild(new OpenCommandTreeNode(this)); addChild(new TeleportCommandTreeNode(this)); + addChild(new ItemCommandTreeNode(this)); } @Override diff --git a/src/main/java/net/Indyuce/mmocore/listener/WaypointsListener.java b/src/main/java/net/Indyuce/mmocore/listener/WaypointsListener.java index f49dc3ca..c703c607 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/WaypointsListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/WaypointsListener.java @@ -52,7 +52,19 @@ public class WaypointsListener implements Listener { return; NBTItem nbtItem = NBTItem.get(event.getItem()); - if (Objects.equals(nbtItem.getString("MMOCoreItemId"), "WAYPOINT_BOOK")) - InventoryManager.WAYPOINTS.newInventory(PlayerData.get(event.getPlayer())).open(); + if (Objects.equals(nbtItem.getString("MMOCoreItemId"), "WAYPOINT_BOOK")) { + String waypointId = nbtItem.getString("WaypointBookId"); + Waypoint waypoint = MMOCore.plugin.waypointManager.get(waypointId); + if (waypoint == null) + return; + + PlayerData playerData = PlayerData.get(event.getPlayer()); + if (playerData.hasWaypoint(waypoint)) + return; + + playerData.unlockWaypoint(waypoint); + event.getItem().setAmount(event.getItem().getAmount() - 1); // Consume item + MMOCore.plugin.configManager.getSimpleMessage("new-waypoint-book", "waypoint", waypoint.getName()).send(event.getPlayer()); + } } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/WaypointManager.java b/src/main/java/net/Indyuce/mmocore/manager/WaypointManager.java index f3b93d32..97bb5a00 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/WaypointManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/WaypointManager.java @@ -25,6 +25,7 @@ public class WaypointManager implements MMOCoreManager { return waypoints.containsKey(id); } + @Nullable public Waypoint get(String id) { return waypoints.get(id); } diff --git a/src/main/java/net/Indyuce/mmocore/util/item/SkillBookBuilder.java b/src/main/java/net/Indyuce/mmocore/util/item/SkillBookBuilder.java new file mode 100644 index 00000000..6c809a26 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/util/item/SkillBookBuilder.java @@ -0,0 +1,29 @@ +package net.Indyuce.mmocore.util.item; + +import io.lumine.mythic.lib.api.item.ItemTag; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.skill.RegisteredSkill; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +@Deprecated +public class SkillBookBuilder extends AbstractItemBuilder { + private final RegisteredSkill skill; + + public SkillBookBuilder(RegisteredSkill skill) { + super(MMOCore.plugin.configItems.get("SKILL_BOOK")); + + this.skill = skill; + } + + @Override + public void whenBuildingMeta(ItemStack item, ItemMeta meta) { + + } + + @Override + public void whenBuildingNBT(NBTItem nbtItem) { + nbtItem.addTag(new ItemTag("SkillBookId", skill.getHandler().getId())); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/util/item/WaypointBookBuilder.java b/src/main/java/net/Indyuce/mmocore/util/item/WaypointBookBuilder.java new file mode 100644 index 00000000..d16aeeb0 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/util/item/WaypointBookBuilder.java @@ -0,0 +1,30 @@ +package net.Indyuce.mmocore.util.item; + +import io.lumine.mythic.lib.api.item.ItemTag; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.waypoint.Waypoint; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class WaypointBookBuilder extends AbstractItemBuilder { + private final Waypoint waypoint; + + public WaypointBookBuilder(Waypoint waypoint) { + super(MMOCore.plugin.configItems.get("WAYPOINT_BOOK")); + + this.waypoint = waypoint; + + addPlaceholders("waypoint", waypoint.getName()); + } + + @Override + public void whenBuildingMeta(ItemStack item, ItemMeta meta) { + + } + + @Override + public void whenBuildingNBT(NBTItem nbtItem) { + nbtItem.addTag(new ItemTag("WaypointBookId", waypoint.getId())); + } +} diff --git a/src/main/resources/default/items.yml b/src/main/resources/default/items.yml index 05de0cbe..ab5b3967 100644 --- a/src/main/resources/default/items.yml +++ b/src/main/resources/default/items.yml @@ -1,3 +1,18 @@ +# The default item template, not used by MMOCore but it does +# indicates all the item options you can use to configure your items. +TEMPLATE: + item: BOOK + name: 'Your item name' + custom-model-data: 0 + damage: 0 + unbreakable: false + lore: + - 'This is your item lore' + - 'And that is the second line' + - 'This supports &acolors &7as well' + # For player heads only, that is the skull texture value + texture: 'eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGUwYzUzN2EzZDAyMjlmNzMyZTlkMWY4NTRiMzc3YWQwNDA3NjE4ZmQwM2NkNGJiZTgwMzc2MjI0YTRmMWQxZSJ9fX0=' + GOLD_COIN: item: GOLD_NUGGET name: '&6Gold Coin' @@ -10,12 +25,23 @@ NOTE: lore: - '&eWorth: {worth}g' -WAYPOINT_BOOK: - item: ENCHANTED_BOOK - name: '&6Waypoints Book' +SKILL_POINT_BOOK: + item: book + name: '&6Skill Book' lore: - - '&7Waypoints are locations used to save your progress.' - - '&7This book gives you the ability to freely warp between these.' + - '&7Click to redeem one skill point.' + +SKILL_BOOK: + item: book + name: '&6Skill Book: {skill}' + lore: + - '&7Click to unlock {skill}' + +WAYPOINT_BOOK: + item: BOOK + name: '&6Waypoint Book: {waypoint}' + lore: + - '&7Click to unlock {waypoint}' DEPOSIT_ITEM: item: BOOK diff --git a/src/main/resources/default/messages.yml b/src/main/resources/default/messages.yml index 697ebaa9..b311b6ba 100644 --- a/src/main/resources/default/messages.yml +++ b/src/main/resources/default/messages.yml @@ -67,6 +67,7 @@ leave-combat: '%&aYou left combat.' # Waypoints new-waypoint: '%&eYou unlocked the &6{waypoint} &ewaypoint!' +new-waypoint-book: '%&eYou unlocked the &6{waypoint} &ewaypoint!' not-enough-stellium: '&cYou don''t have enough stellium: you need {more} more.' waypoint-cooldown: '&cPlease wait {cooldown} before using a waypoint again.' not-unlocked-waypoint: '&cYou have not unlocked that waypoint yet.'