diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java index 55f2a327..37bfbc87 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AdminCommandTreeNode.java @@ -28,7 +28,6 @@ public class AdminCommandTreeNode extends CommandTreeNode { addChild(new PointsCommandTreeNode("attr-realloc", this, PlayerData::setAttributeReallocationPoints, PlayerData::giveAttributeReallocationPoints, PlayerData::getAttributeReallocationPoints)); addChild(new PointsCommandTreeNode("skill-realloc", this, PlayerData::setSkillReallocationPoints, PlayerData::giveSkillReallocationPoints, PlayerData::getSkillReallocationPoints)); addChild(new PointsCommandTreeNode("skill-tree-realloc", this, PlayerData::setSkillTreeReallocationPoints, PlayerData::giveSkillTreeReallocationPoints, PlayerData::getSkillTreeReallocationPoints)); - addChild(new WaypointCommandTreeNode(this)); for (PlayerResource res : PlayerResource.values()) addChild(new ResourceCommandTreeNode(res.name().toLowerCase(), this, res)); } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/WaypointCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/WaypointCommandTreeNode.java deleted file mode 100644 index 28a8c5fb..00000000 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/WaypointCommandTreeNode.java +++ /dev/null @@ -1,75 +0,0 @@ -package net.Indyuce.mmocore.command.rpg.admin; - -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.api.player.PlayerData; -import net.Indyuce.mmocore.command.CommandVerbose; -import net.Indyuce.mmocore.waypoint.Waypoint; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.function.BiConsumer; -import java.util.function.BiFunction; - -public class WaypointCommandTreeNode extends CommandTreeNode { - public WaypointCommandTreeNode(CommandTreeNode parent) { - super(parent, "waypoint"); - addChild(new ActionCommandTreeNode(this, "unlock", - (playerData, waypoint) -> !playerData.hasWaypoint(waypoint) - , (playerData, waypoint) -> playerData.unlockWaypoint(waypoint))); - addChild(new ActionCommandTreeNode(this, "lock", - (playerData, waypoint) -> playerData.hasWaypoint(waypoint) - , (playerData, waypoint) -> playerData.lockWaypoint(waypoint))); - } - - @Override - public CommandResult execute(CommandSender commandSender, String[] strings) { - return null; - } - - private class ActionCommandTreeNode extends CommandTreeNode { - private final BiFunction check; - private final BiConsumer change; - - - public ActionCommandTreeNode(CommandTreeNode parent, String id, - BiFunction check, - BiConsumer change) { - super(parent, id); - this.change = change; - this.check = check; - addParameter(Parameter.PLAYER); - addParameter(new Parameter("waypoint", ((commandTreeExplorer, list) -> - MMOCore.plugin.waypointManager.getAll().forEach(waypoint -> list.add(waypoint.getId())) - ))); - } - - @Override - public CommandResult execute(CommandSender sender, String[] args) { - Player player = Bukkit.getPlayer(args[3]); - if (player == null) { - sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + "."); - return CommandResult.FAILURE; - } - - Waypoint waypoint = MMOCore.plugin.waypointManager.get(args[4]); - if (waypoint == null) { - sender.sendMessage(ChatColor.RED + "Could not find the waypoint called " + args[4] + "."); - return CommandResult.FAILURE; - } - - PlayerData playerData = PlayerData.get(player); - if (!check.apply(playerData, waypoint)) { - sender.sendMessage(ChatColor.RED + "The waypoint " + args[4] + " is already in this state."); - return CommandResult.FAILURE; - } - change.accept(playerData, waypoint); - return CommandResult.SUCCESS; - - } - } - -} diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/LockCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/LockCommandTreeNode.java new file mode 100644 index 00000000..721b2fee --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/waypoint/LockCommandTreeNode.java @@ -0,0 +1,51 @@ +package net.Indyuce.mmocore.command.rpg.waypoint; + +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.api.player.PlayerData; +import net.Indyuce.mmocore.command.CommandVerbose; +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 LockCommandTreeNode extends CommandTreeNode { + + public LockCommandTreeNode(CommandTreeNode parent) { + super(parent, "lock"); + + 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; + } + PlayerData playerData = PlayerData.get(player); + Waypoint waypoint = MMOCore.plugin.waypointManager.get(args[2]); + + if (!playerData.hasWaypoint(waypoint)) { + sender.sendMessage(ChatColor.RED + "The waypoint " + args[2] + " is already locked."); + return CommandResult.FAILURE; + } + PlayerData.get(player).lockWaypoint(waypoint); + CommandVerbose.verbose(sender,CommandVerbose.CommandType.WAYPOINT,ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " successfully locked " + 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 48aeba29..78a557d9 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 @@ -12,6 +12,7 @@ public class WaypointsCommandTreeNode extends CommandTreeNode { addChild(new OpenCommandTreeNode(this)); addChild(new TeleportCommandTreeNode(this)); addChild(new ItemCommandTreeNode(this)); + addChild(new LockCommandTreeNode(this)); } @Override