Waypoints command

This commit is contained in:
Ka0rX 2022-08-08 19:09:23 +02:00
parent ee84739f0d
commit 1466fc661e
6 changed files with 99 additions and 12 deletions

View File

@ -415,6 +415,11 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
waypoints.add(waypoint.getId());
}
public void lockWaypoint(Waypoint waypoint) {
waypoints.remove(waypoint);
}
/**
* @deprecated Provide a heal reason with {@link #heal(double, PlayerResourceUpdateEvent.UpdateReason)}
*/
@ -770,6 +775,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
}
@Deprecated
public void setAttribute(PlayerAttribute attribute, int value) {
setAttribute(attribute.getId(), value);

View File

@ -56,7 +56,8 @@ public class CommandVerbose {
NOCD,
POINTS,
RESET,
RESOURCE
RESOURCE,
WAYPOINT;
}
private enum VerboseValue {

View File

@ -0,0 +1,75 @@
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.getWaypoints().contains(waypoint)
, (playerData, waypoint) -> playerData.unlockWaypoint(waypoint)));
addChild(new ActionCommandTreeNode(this, "lock",
(playerData, waypoint) -> playerData.getWaypoints().contains(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[0]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[0] + ".");
return CommandResult.FAILURE;
}
Waypoint waypoint = MMOCore.plugin.waypointManager.get(args[1]);
if (waypoint == null) {
sender.sendMessage(ChatColor.RED + "Could not find the waypoint called " + args[1] + ".");
return CommandResult.FAILURE;
}
PlayerData playerData = PlayerData.get(player);
if (!check.apply(playerData, waypoint)) {
sender.sendMessage(ChatColor.RED + "The waypoint " + args[1] + "is already in this state.");
return CommandResult.FAILURE;
}
change.accept(playerData, waypoint);
return CommandResult.SUCCESS;
}
}
}

View File

@ -376,7 +376,7 @@ public class SkillList extends EditableInventory {
if (item.getFunction().equals("slot")) {
int index = slotSlots.indexOf(context.getSlot());
KEy // unbind if there is a current spell.
// unbind if there is a current spell.
if (context.getClickType() == ClickType.RIGHT) {
if (!playerData.hasSkillBound(index)) {
MMOCore.plugin.configManager.getSimpleMessage("no-skill-bound").send(player);

View File

@ -104,7 +104,6 @@ public class KeyCombos implements Listener {
}
// Adding pressed key
CustomSkillCastingHandler casting = (CustomSkillCastingHandler) playerData.getSkillCasting();
casting.current.registerKey(event.getPressed());
@ -184,6 +183,9 @@ public class KeyCombos implements Listener {
@Override
public void onTick() {
if (actionBarOptions != null)
if (actionBarOptions.isSubtitle)
getCaster().getPlayer().sendTitle(" ", actionBarOptions.format(this), 0, 20, 0);
else
getCaster().displayActionBar(actionBarOptions.format(this));
}
@ -198,11 +200,13 @@ public class KeyCombos implements Listener {
* the current player's key combo on the action bar
*/
private final Map<PlayerKey, String> keyNames = new HashMap<>();
private final boolean isSubtitle;
ActionBarOptions(ConfigurationSection config) {
this.separator = Objects.requireNonNull(config.getString("separator"), "Could not find action bar option 'separator'");
this.noKey = Objects.requireNonNull(config.getString("no-key"), "Could not find action bar option 'no-key'");
this.isSubtitle = config.getBoolean("is-subtitle", false);
for (PlayerKey key : PlayerKey.values())
keyNames.put(key, Objects.requireNonNull(config.getString("key-name." + key.name()), "Could not find translation for key " + key.name()));
}

View File

@ -257,3 +257,4 @@ command-verbose:
points: true
reset: true
resource: true
waypoint: true