-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Prevent vanished players from being marked as AFK * Apply review suggestions
- Loading branch information
Showing
2 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
eternalcore-core/src/main/java/com/eternalcode/core/feature/vanish/VanishService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.eternalcode.core.feature.vanish; | ||
|
||
import com.eternalcode.core.injector.annotations.Inject; | ||
import com.eternalcode.core.injector.annotations.component.Service; | ||
import java.util.UUID; | ||
import org.bukkit.Server; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.metadata.MetadataValue; | ||
|
||
@Service | ||
public class VanishService { | ||
|
||
private static final String METADATA_VANISHED_KEY = "vanished"; | ||
private final Server server; | ||
|
||
@Inject | ||
public VanishService(Server server) { | ||
this.server = server; | ||
} | ||
|
||
public boolean isVanished(UUID playerUniqueId) { | ||
Player player = this.server.getPlayer(playerUniqueId); | ||
if (player == null) { | ||
return false; | ||
} | ||
return this.isVanished(player); | ||
} | ||
|
||
private boolean isVanished(Player player) { | ||
for (MetadataValue isVanished : player.getMetadata(METADATA_VANISHED_KEY)) { | ||
if (isVanished.asBoolean()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |