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

@ -239,14 +239,14 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
} }
public void giveSkillReallocationPoints(int value) { public void giveSkillReallocationPoints(int value) {
skillReallocationPoints+=value; skillReallocationPoints += value;
} }
public int countSkillPointsWhenReallocate() { public int countSkillPointsWhenReallocate() {
int sum = 0; int sum = 0;
for(ClassSkill skill:getProfess().getSkills()) { for (ClassSkill skill : getProfess().getSkills()) {
//0 if the skill is level 1(just unlocked) or 0 locked. //0 if the skill is level 1(just unlocked) or 0 locked.
sum+=Math.max(0,getSkillLevel(skill.getSkill())-1); sum += Math.max(0, getSkillLevel(skill.getSkill()) - 1);
} }
return sum; return sum;
} }
@ -415,6 +415,11 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
waypoints.add(waypoint.getId()); waypoints.add(waypoint.getId());
} }
public void lockWaypoint(Waypoint waypoint) {
waypoints.remove(waypoint);
}
/** /**
* @deprecated Provide a heal reason with {@link #heal(double, PlayerResourceUpdateEvent.UpdateReason)} * @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)); getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
} }
@Deprecated @Deprecated
public void setAttribute(PlayerAttribute attribute, int value) { public void setAttribute(PlayerAttribute attribute, int value) {
setAttribute(attribute.getId(), value); setAttribute(attribute.getId(), value);

View File

@ -56,7 +56,8 @@ public class CommandVerbose {
NOCD, NOCD,
POINTS, POINTS,
RESET, RESET,
RESOURCE RESOURCE,
WAYPOINT;
} }
private enum VerboseValue { 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")) { if (item.getFunction().equals("slot")) {
int index = slotSlots.indexOf(context.getSlot()); 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 (context.getClickType() == ClickType.RIGHT) {
if (!playerData.hasSkillBound(index)) { if (!playerData.hasSkillBound(index)) {
MMOCore.plugin.configManager.getSimpleMessage("no-skill-bound").send(player); MMOCore.plugin.configManager.getSimpleMessage("no-skill-bound").send(player);

View File

@ -104,7 +104,6 @@ public class KeyCombos implements Listener {
} }
// Adding pressed key // Adding pressed key
CustomSkillCastingHandler casting = (CustomSkillCastingHandler) playerData.getSkillCasting(); CustomSkillCastingHandler casting = (CustomSkillCastingHandler) playerData.getSkillCasting();
casting.current.registerKey(event.getPressed()); casting.current.registerKey(event.getPressed());
@ -173,18 +172,21 @@ public class KeyCombos implements Listener {
CustomSkillCastingHandler(PlayerData caster) { CustomSkillCastingHandler(PlayerData caster) {
super(caster, 10); super(caster, 10);
if (!caster.getProfess().getCombos().isEmpty()) { if (!caster.getProfess().getCombos().isEmpty()) {
classCombos=caster.getProfess().getCombos(); classCombos = caster.getProfess().getCombos();
classLongestCombo=caster.getProfess().getLongestCombo(); classLongestCombo = caster.getProfess().getLongestCombo();
} else { } else {
classCombos = combos; classCombos = combos;
classLongestCombo=longestCombo; classLongestCombo = longestCombo;
} }
} }
@Override @Override
public void onTick() { public void onTick() {
if (actionBarOptions != null) if (actionBarOptions != null)
getCaster().displayActionBar(actionBarOptions.format(this)); 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 * the current player's key combo on the action bar
*/ */
private final Map<PlayerKey, String> keyNames = new HashMap<>(); private final Map<PlayerKey, String> keyNames = new HashMap<>();
private final boolean isSubtitle;
ActionBarOptions(ConfigurationSection config) { ActionBarOptions(ConfigurationSection config) {
this.separator = Objects.requireNonNull(config.getString("separator"), "Could not find action bar option 'separator'"); 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.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()) for (PlayerKey key : PlayerKey.values())
keyNames.put(key, Objects.requireNonNull(config.getString("key-name." + key.name()), "Could not find translation for key " + key.name())); keyNames.put(key, Objects.requireNonNull(config.getString("key-name." + key.name()), "Could not find translation for key " + key.name()));
} }

View File

@ -256,4 +256,5 @@ command-verbose:
nocd: true nocd: true
points: true points: true
reset: true reset: true
resource: true resource: true
waypoint: true