Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for player Last Seen while vanished #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/de/myzelyam/api/vanish/VanishAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public static boolean isInvisible(Player p) {
return PLUGIN.getVanishStateMgr().isVanished(p.getUniqueId());
}

/**
* @return Unix timestamp of when the player was last seen not vanished
*/
public static long getLastSeen(UUID uuid) {
Validation.checkNotNull("UUID cannot be null!", uuid);
return PLUGIN.getVanishStateMgr().getLastSeen(uuid);
}

/**
* Checks if a player is invisible, online or not
* <p/>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/myzelyam/supervanish/VanishPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public boolean isOnlineVanished() {
return plugin.getVanishStateMgr().isVanished(player.getUniqueId());
}

public long getLastSeen() { return plugin.getVanishStateMgr().getLastSeen(player.getUniqueId()); }

public boolean hasItemPickUpsEnabled() {
return itemPickUps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public boolean isVanished(final UUID uuid) {
return getVanishedPlayersOnFile().contains(uuid);
}

@Override
public long getLastSeen(UUID uuid) {
return plugin.getPlayerData().getLong("PlayerData." + uuid + ".information.last_seen", System.currentTimeMillis() / 1000L);
}

@Override
public void setVanishedState(final UUID uuid, String name, boolean hide, String causeName) {
PlayerVanishStateChangeEvent event = new PlayerVanishStateChangeEvent(uuid, name, hide, causeName);
Expand All @@ -46,8 +51,11 @@ public void setVanishedState(final UUID uuid, String name, boolean hide, String
else
vanishedPlayerUUIDStrings.remove(uuid.toString());
plugin.getPlayerData().set("InvisiblePlayers", vanishedPlayerUUIDStrings);
if (hide)
plugin.getPlayerData().set("PlayerData." + uuid + ".information.last_seen", null);
if (hide) {
plugin.getPlayerData().set("PlayerData." + uuid + ".information.name", name);
plugin.getPlayerData().set("PlayerData." + uuid + ".information.last_seen", System.currentTimeMillis() / 1000L);
}
plugin.getConfigMgr().getPlayerDataFile().save();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public VanishStateMgr(SuperVanishPlugin plugin) {

public abstract boolean isVanished(final UUID uuid);

public abstract long getLastSeen(final UUID uuid);

public abstract void setVanishedState(final UUID uuid, String name, boolean hide, String causeName);

public final void setVanishedState(final UUID uuid, String name, boolean hide) {
Expand Down