From 1d9c4e0e971ef326f8409b63231045e1a9f955da Mon Sep 17 00:00:00 2001 From: RitzKid76 Date: Sat, 22 Mar 2025 19:44:43 -0400 Subject: [PATCH] fix issue where offline players were prioritized in getPlayer the only issue that i can think of that this could create would be in Commandmail. luckily that command never used this function in the first place... infact mail already prioritizes online players, so something to fix in the future? --- .../commands/EssentialsCommand.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java index e73e28754..2891e7968 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java @@ -1,13 +1,18 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.*; +import java.util.List; +import java.util.logging.Logger; + import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.List; -import java.util.logging.Logger; +import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.OfflinePlayer; +import com.earth2me.essentials.Trade; +import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; public abstract class EssentialsCommand implements IEssentialsCommand { @@ -46,13 +51,19 @@ protected User getPlayer(final Server server, final String[] args, final int pos if (args.length <= pos) { throw new NotEnoughArgumentsException(); } + final User user = ess.getUser(args[pos]); - if (user != null) { - if (!getOffline && (user.getBase() instanceof OfflinePlayer || user.isHidden())) { - throw new NoSuchFieldException(Util.i18n("playerNotFound")); - } - return user; - } + if ( + user != null && ( // if the user exists, and either + getOffline || // 1) we allow offline players + !( // 2) the player is not offline/hidden + user.getBase() instanceof OfflinePlayer || + user.isHidden() + ) + ) + ) return user; + + // try to find a user that matches the partial string final List matches = server.matchPlayer(args[pos]); if (!matches.isEmpty()) {