mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
Waypoints command
This commit is contained in:
parent
7684164f23
commit
1002bc841d
@ -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));
|
||||
}
|
||||
|
@ -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<PlayerData, Waypoint, Boolean> check;
|
||||
private final BiConsumer<PlayerData, Waypoint> change;
|
||||
|
||||
|
||||
public ActionCommandTreeNode(CommandTreeNode parent, String id,
|
||||
BiFunction<PlayerData, Waypoint, Boolean> check,
|
||||
BiConsumer<PlayerData, Waypoint> 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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("<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;
|
||||
}
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user