Fixed error with loading waypoints. New error log

This commit is contained in:
Jules 2025-08-19 14:35:06 +02:00
parent decdc0c046
commit e3bf9bfcd6
8 changed files with 23 additions and 15 deletions

View File

@ -24,18 +24,18 @@ public class ItemCommandTreeNode extends CommandTreeNode {
if (args.length < 4)
return CommandResult.THROW_USAGE;
if (!MMOCore.plugin.waypointManager.has(args[2])) {
var waypoint = MMOCore.plugin.waypointManager.get(args[2]);
if (waypoint == null) {
sender.sendMessage(ChatColor.RED + "Could not find waypoint " + args[2]);
return CommandResult.FAILURE;
}
Player player = Bukkit.getPlayer(args[3]);
var 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 + ".");

View File

@ -25,7 +25,8 @@ public class LockCommandTreeNode extends CommandTreeNode {
if (args.length < 4)
return CommandResult.THROW_USAGE;
if (!MMOCore.plugin.waypointManager.has(args[2])) {
Waypoint waypoint = MMOCore.plugin.waypointManager.get(args[2]);
if (waypoint == null) {
sender.sendMessage(ChatColor.RED + "Could not find waypoint " + args[2]);
return CommandResult.FAILURE;
}
@ -36,14 +37,13 @@ public class LockCommandTreeNode extends CommandTreeNode {
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()
CommandVerbose.verbose(sender, CommandVerbose.CommandType.WAYPOINT, ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " successfully locked " + ChatColor.GOLD + waypoint.getId()
+ ChatColor.YELLOW + ".");
return CommandResult.SUCCESS;

View File

@ -22,7 +22,8 @@ public class TeleportCommandTreeNode extends CommandTreeNode {
if (args.length < 4)
return CommandResult.THROW_USAGE;
if (!MMOCore.plugin.waypointManager.has(args[2])) {
Waypoint waypoint = MMOCore.plugin.waypointManager.get(args[2]);
if (waypoint == null) {
sender.sendMessage(ChatColor.RED + "Could not find waypoint " + args[2]);
return CommandResult.FAILURE;
}
@ -33,7 +34,6 @@ public class TeleportCommandTreeNode extends CommandTreeNode {
return CommandResult.FAILURE;
}
Waypoint waypoint = MMOCore.plugin.waypointManager.get(args[2]);
player.teleport(waypoint.getLocation());
sender.sendMessage(ChatColor.YELLOW + "Successfully teleported " + ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " to "
+ ChatColor.GOLD + waypoint.getId() + ChatColor.YELLOW + ".");

View File

@ -23,18 +23,18 @@ public class UnlockCommandTreeNode extends CommandTreeNode {
if (args.length < 4)
return CommandResult.THROW_USAGE;
if (!MMOCore.plugin.waypointManager.has(args[2])) {
var waypoint = MMOCore.plugin.waypointManager.get(args[2]);
if (waypoint == null) {
sender.sendMessage(ChatColor.RED + "Could not find waypoint " + args[2]);
return CommandResult.FAILURE;
}
Player player = Bukkit.getPlayer(args[3]);
var 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]);
PlayerData.get(player).unlockWaypoint(waypoint);
sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " successfully unlocked " + ChatColor.GOLD + waypoint.getId()
+ ChatColor.YELLOW + ".");

View File

@ -118,7 +118,7 @@ public class WaypointViewer extends EditableInventory {
if (tag.isEmpty()) return;
// Locked waypoint?
final Waypoint waypoint = MMOCore.plugin.waypointManager.get(tag);
final Waypoint waypoint = MMOCore.plugin.waypointManager.getOrThrow(tag);
if (!inv.playerData.hasWaypoint(waypoint)) {
ConfigMessage.fromKey("not-unlocked-waypoint").send(inv.playerData);
return;

View File

@ -5,6 +5,7 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.waypoint.Waypoint;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@ -29,6 +30,14 @@ public class WaypointManager implements MMOCoreManager {
return waypoints.get(id);
}
@NotNull
public Waypoint getOrThrow(@NotNull String id) {
var found = waypoints.get(id);
if (found == null)
throw new IllegalArgumentException(String.format("Could not find waypoint with ID '%s'", id));
return found;
}
public void register(Waypoint waypoint) {
Validate.isTrue(!waypoints.containsKey(Objects.requireNonNull(waypoint, "Waypoint cannot be null").getId()), "There is already a waypoint with ID '" + waypoint.getId() + "'");

View File

@ -45,7 +45,7 @@ public class Waypoint implements Unlockable, PreloadedObject {
if (config.contains("linked")) {
ConfigurationSection section = config.getConfigurationSection("linked");
for (String key : section.getKeys(false))
destinations.put(MMOCore.plugin.waypointManager.get(key), section.getDouble(key));
destinations.put(MMOCore.plugin.waypointManager.getOrThrow(key), section.getDouble(key));
}
// Link reciprocity

View File

@ -56,8 +56,7 @@ public class WaypointsListener implements Listener {
if (Objects.equals(nbtItem.getString("MMOCoreItemId"), "WAYPOINT_BOOK")) {
String waypointId = nbtItem.getString("WaypointBookId");
Waypoint waypoint = MMOCore.plugin.waypointManager.get(waypointId);
if (waypoint == null)
return;
if (waypoint == null) return;
PlayerData playerData = PlayerData.get(event.getPlayer());
if (playerData.hasWaypoint(waypoint))