Skip to content

Commit d2a7ca1

Browse files
committed
Refactor user validation and enhance debugging in PlayerManager
- Removed commented dependency from pom.xml. - Improved debug logging in PlayerManager for user validation checks. - Added detailed debug statements to track user existence and Bedrock player checks. - Updated BedrockNameResolver documentation for clarity.
1 parent 3e94880 commit d2a7ca1

4 files changed

Lines changed: 53 additions & 12 deletions

File tree

AdvancedCore/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@
207207
<version>2.12.2</version>
208208
<scope>provided</scope>
209209
</dependency>
210-
<!-- <dependency> <groupId>com.github.Ben12345rocks</groupId>
211-
<artifactId>ChatComponentAPI</artifactId>
212-
<version>master-SNAPSHOT</version> <scope>compile</scope> </dependency> -->
213210
<dependency>
214211
<groupId>org.slf4j</groupId>
215212
<artifactId>slf4j-simple</artifactId>

AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bedrock/BedrockNameResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ public Result resolve(String incomingName) {
301301
// implementation)
302302
try {
303303
AdvancedCoreUser user = userManager.getUser(incomingName);
304+
304305
if (user == null) {
305306
String canonical = ciIndex.get(incomingName.toLowerCase(Locale.ROOT));
306307
if (canonical != null)
@@ -486,7 +487,8 @@ private Player findOnlineByNameOrStripped(String name) {
486487
}
487488

488489
/**
489-
* Result of name resolution containing the final name, Bedrock status, and rationale.
490+
* Result of name resolution containing the final name, Bedrock status, and
491+
* rationale.
490492
*/
491493
public static final class Result {
492494
/** The final resolved name. */

AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/PlayerManager.java

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,33 +237,66 @@ public boolean isValidUser(String name) {
237237

238238
@SuppressWarnings("deprecation")
239239
public boolean isValidUser(String name, boolean checkServer) {
240+
plugin.extraDebug("isValidUser START: name=" + name + ", checkServer=" + checkServer);
241+
242+
if (name == null) {
243+
plugin.extraDebug("isValidUser: name is null -> false");
244+
return false;
245+
}
246+
247+
name = name.trim();
248+
240249
Player player = Bukkit.getPlayerExact(name);
241250
if (player != null) {
251+
plugin.extraDebug("isValidUser: matched ONLINE player -> true (" + player.getName() + ")");
242252
return true;
243253
}
244254

245255
boolean userExist = plugin.getUserManager().userExist(name);
256+
plugin.extraDebug("isValidUser: userExist(" + name + ")=" + userExist);
246257
if (userExist) {
247-
return userExist;
258+
plugin.extraDebug("isValidUser: returning true from userExist");
259+
return true;
248260
}
249261

250262
if (name.isEmpty()) {
263+
plugin.extraDebug("isValidUser: empty name -> false");
251264
return false;
252265
}
253266

254-
if (plugin.getBedrockHandle().isBedrock(name)) {
255-
plugin.extraDebug("Player " + name + " is a bedrock player, skipping offline check");
267+
boolean isBedrock = plugin.getBedrockHandle().isBedrock(name);
268+
plugin.extraDebug("isValidUser: isBedrock(" + name + ")=" + isBedrock);
269+
if (isBedrock) {
270+
plugin.extraDebug("isValidUser: bedrock match -> true (skipping offline check)");
256271
return true;
257272
}
258273

259-
if (checkServer && !name.startsWith(plugin.getOptions().getBedrockPlayerPrefix())) {
260-
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
261-
if (p.hasPlayedBefore() || p.isOnline() || p.getLastPlayed() != 0) {
262-
return true;
274+
if (checkServer) {
275+
String prefix = plugin.getOptions().getBedrockPlayerPrefix();
276+
plugin.extraDebug("isValidUser: checkServer enabled, bedrockPrefix=" + prefix);
277+
278+
if (!name.startsWith(prefix)) {
279+
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
280+
281+
boolean hasPlayed = p.hasPlayedBefore();
282+
boolean isOnline = p.isOnline();
283+
long lastPlayed = p.getLastPlayed();
284+
285+
plugin.extraDebug("isValidUser: OfflinePlayer check for " + name + " -> hasPlayedBefore=" + hasPlayed
286+
+ ", isOnline=" + isOnline + ", lastPlayed=" + lastPlayed);
287+
288+
if (hasPlayed || isOnline || lastPlayed != 0) {
289+
plugin.extraDebug("isValidUser: checkServer match -> true");
290+
return true;
291+
}
292+
} else {
293+
plugin.extraDebug("isValidUser: skipping checkServer due to bedrock prefix match");
263294
}
295+
} else {
296+
plugin.extraDebug("isValidUser: checkServer disabled");
264297
}
265298

266-
plugin.extraDebug("Player " + name + " does not exist");
299+
plugin.extraDebug("isValidUser: FINAL -> false (no checks passed for " + name + ")");
267300
return false;
268301
}
269302
}

AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/usercache/UserDataManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.bencodez.advancedcore.api.user.usercache.keys.UserDataKeyBoolean;
1818
import com.bencodez.advancedcore.api.user.usercache.keys.UserDataKeyInt;
1919
import com.bencodez.advancedcore.api.user.usercache.keys.UserDataKeyString;
20+
import com.bencodez.simpleapi.debug.DebugLevel;
2021

2122
import lombok.Getter;
2223

@@ -73,6 +74,13 @@ public void addKey(UserDataKey userDataKey) {
7374
@Deprecated
7475
public void cacheUser(UUID uuid) {
7576
plugin.devDebug("Caching " + uuid.toString());
77+
if (plugin.getOptions().getDebug().isDebug(DebugLevel.DEV)) {
78+
try {
79+
throw new Exception("caching here: " + uuid.toString());
80+
} catch (Exception e) {
81+
e.printStackTrace();
82+
}
83+
}
7684
if (userDataCache.containsKey(uuid)) {
7785
UserDataCache data = userDataCache.get(uuid);
7886
data.clearChanges();
@@ -83,6 +91,7 @@ public void cacheUser(UUID uuid) {
8391
userDataCache.put(uuid, data);
8492
}
8593
}
94+
8695
}
8796

8897
public void cacheUser(UUID uuid, String playerName) {

0 commit comments

Comments
 (0)