forked from Upstream/mmocore
Waypoint books
This commit is contained in:
parent
98dec0f4a2
commit
0000b76d96
@ -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("<waypoint>", (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;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ public class WaypointsCommandTreeNode extends CommandTreeNode {
|
|||||||
addChild(new UnlockCommandTreeNode(this));
|
addChild(new UnlockCommandTreeNode(this));
|
||||||
addChild(new OpenCommandTreeNode(this));
|
addChild(new OpenCommandTreeNode(this));
|
||||||
addChild(new TeleportCommandTreeNode(this));
|
addChild(new TeleportCommandTreeNode(this));
|
||||||
|
addChild(new ItemCommandTreeNode(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +52,19 @@ public class WaypointsListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
NBTItem nbtItem = NBTItem.get(event.getItem());
|
NBTItem nbtItem = NBTItem.get(event.getItem());
|
||||||
if (Objects.equals(nbtItem.getString("MMOCoreItemId"), "WAYPOINT_BOOK"))
|
if (Objects.equals(nbtItem.getString("MMOCoreItemId"), "WAYPOINT_BOOK")) {
|
||||||
InventoryManager.WAYPOINTS.newInventory(PlayerData.get(event.getPlayer())).open();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public class WaypointManager implements MMOCoreManager {
|
|||||||
return waypoints.containsKey(id);
|
return waypoints.containsKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Waypoint get(String id) {
|
public Waypoint get(String id) {
|
||||||
return waypoints.get(id);
|
return waypoints.get(id);
|
||||||
}
|
}
|
||||||
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
@ -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:
|
GOLD_COIN:
|
||||||
item: GOLD_NUGGET
|
item: GOLD_NUGGET
|
||||||
name: '&6Gold Coin'
|
name: '&6Gold Coin'
|
||||||
@ -10,12 +25,23 @@ NOTE:
|
|||||||
lore:
|
lore:
|
||||||
- '&eWorth: {worth}g'
|
- '&eWorth: {worth}g'
|
||||||
|
|
||||||
WAYPOINT_BOOK:
|
SKILL_POINT_BOOK:
|
||||||
item: ENCHANTED_BOOK
|
item: book
|
||||||
name: '&6Waypoints Book'
|
name: '&6Skill Book'
|
||||||
lore:
|
lore:
|
||||||
- '&7Waypoints are locations used to save your progress.'
|
- '&7Click to redeem one skill point.'
|
||||||
- '&7This book gives you the ability to freely warp between these.'
|
|
||||||
|
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:
|
DEPOSIT_ITEM:
|
||||||
item: BOOK
|
item: BOOK
|
||||||
|
@ -67,6 +67,7 @@ leave-combat: '%&aYou left combat.'
|
|||||||
|
|
||||||
# Waypoints
|
# Waypoints
|
||||||
new-waypoint: '%&eYou unlocked the &6{waypoint} &ewaypoint!'
|
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.'
|
not-enough-stellium: '&cYou don''t have enough stellium: you need {more} more.'
|
||||||
waypoint-cooldown: '&cPlease wait {cooldown} before using a waypoint again.'
|
waypoint-cooldown: '&cPlease wait {cooldown} before using a waypoint again.'
|
||||||
not-unlocked-waypoint: '&cYou have not unlocked that waypoint yet.'
|
not-unlocked-waypoint: '&cYou have not unlocked that waypoint yet.'
|
||||||
|
Loading…
Reference in New Issue
Block a user