mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-26 01:59:20 +00:00
Add checks against the user being an NPC
This commit is contained in:
@@ -52,6 +52,10 @@ public abstract class EventListener {
|
||||
* @param user The {@link OnlineUser} to handle
|
||||
*/
|
||||
protected final void handlePlayerJoin(@NotNull OnlineUser user) {
|
||||
if (user.isNpc()) {
|
||||
return;
|
||||
}
|
||||
|
||||
lockedPlayers.add(user.uuid);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
@@ -152,7 +156,7 @@ public abstract class EventListener {
|
||||
return;
|
||||
}
|
||||
// Don't sync players awaiting synchronization
|
||||
if (lockedPlayers.contains(user.uuid)) {
|
||||
if (lockedPlayers.contains(user.uuid) || user.isNpc()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -181,7 +185,7 @@ public abstract class EventListener {
|
||||
return;
|
||||
}
|
||||
usersInWorld.stream()
|
||||
.filter(user -> !lockedPlayers.contains(user.uuid))
|
||||
.filter(user -> !lockedPlayers.contains(user.uuid) && !user.isNpc())
|
||||
.forEach(user -> user.getUserData(plugin.getLoggingAdapter(), plugin.getSettings())
|
||||
.thenAccept(data -> data.ifPresent(userData -> plugin.getDatabase()
|
||||
.setUserData(user, userData, DataSaveCause.WORLD_SAVE))));
|
||||
@@ -194,7 +198,7 @@ public abstract class EventListener {
|
||||
* @param drops The items that this user would have dropped
|
||||
*/
|
||||
protected void saveOnPlayerDeath(@NotNull OnlineUser user, @NotNull ItemData drops) {
|
||||
if (disabling || !plugin.getSettings().saveOnDeath || lockedPlayers.contains(user.uuid)) {
|
||||
if (disabling || !plugin.getSettings().saveOnDeath || lockedPlayers.contains(user.uuid) || user.isNpc()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -223,7 +227,7 @@ public abstract class EventListener {
|
||||
|
||||
// Save data for all online users
|
||||
plugin.getOnlineUsers().stream()
|
||||
.filter(user -> !lockedPlayers.contains(user.uuid))
|
||||
.filter(user -> !lockedPlayers.contains(user.uuid) && !user.isNpc())
|
||||
.forEach(user -> {
|
||||
lockedPlayers.add(user.uuid);
|
||||
user.getUserData(plugin.getLoggingAdapter(), plugin.getSettings()).join()
|
||||
|
||||
@@ -257,15 +257,15 @@ public abstract class OnlineUser extends User {
|
||||
// Prevent synchronising user data from newer versions of Minecraft
|
||||
if (Version.fromMinecraftVersionString(data.getMinecraftVersion()).compareTo(serverMinecraftVersion) > 0) {
|
||||
logger.log(Level.SEVERE, "Cannot set data for " + username +
|
||||
" because the Minecraft version of their user data (" + data.getMinecraftVersion() +
|
||||
") is newer than the server's Minecraft version (" + serverMinecraftVersion + ").");
|
||||
" because the Minecraft version of their user data (" + data.getMinecraftVersion() +
|
||||
") is newer than the server's Minecraft version (" + serverMinecraftVersion + ").");
|
||||
return false;
|
||||
}
|
||||
// Prevent synchronising user data from newer versions of the plugin
|
||||
if (data.getFormatVersion() > UserData.CURRENT_FORMAT_VERSION) {
|
||||
logger.log(Level.SEVERE, "Cannot set data for " + username +
|
||||
" because the format version of their user data (v" + data.getFormatVersion() +
|
||||
") is newer than the current format version (v" + UserData.CURRENT_FORMAT_VERSION + ").");
|
||||
" because the format version of their user data (v" + data.getFormatVersion() +
|
||||
") is newer than the current format version (v" + UserData.CURRENT_FORMAT_VERSION + ").");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -377,4 +377,11 @@ public abstract class OnlineUser extends User {
|
||||
* @return the player's locked status
|
||||
*/
|
||||
public abstract boolean isLocked();
|
||||
|
||||
/**
|
||||
* Get if the player is a NPC
|
||||
*
|
||||
* @return if the player is a NPC with metadata
|
||||
*/
|
||||
public abstract boolean isNpc();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user