-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from TheMrEngMan/update-vanished-players
Added updating player count when players enter/exit vanished mode
- Loading branch information
Showing
9 changed files
with
221 additions
and
12 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
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
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,46 @@ | ||
package uk.co.angrybee.joe; | ||
|
||
import de.myzelyam.api.vanish.VanishAPI; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.metadata.MetadataValue; | ||
|
||
import static uk.co.angrybee.joe.DiscordWhitelister.*; | ||
|
||
public class Utils { | ||
|
||
// Check if player is vanished | ||
public static boolean isVanished(Player player) { | ||
|
||
// For Essentials | ||
if(essentialsPlugin != null) { | ||
//getPluginLogger().info("Checking via EssX if " + player.getDisplayName() + " is vanished: " + essentialsPlugin.getUser(player).isVanished()); | ||
//getPluginLogger().info("Checking via EssX for list of vanished players: " + essentialsPlugin.getVanishedPlayers()); | ||
if(essentialsPlugin.getUser(player).isVanished()) return true; | ||
} | ||
|
||
// For SuperVanish / PremiumVanish | ||
if(VanishAPI.getPlugin() != null) { | ||
//getPluginLogger().info("Checking via SV if " + player.getDisplayName() + " is vanished: " + VanishAPI.isInvisible(player)); | ||
//getPluginLogger().info("Checking via SV for list of vanished players: " + VanishAPI.getAllInvisiblePlayers()); | ||
if(VanishAPI.isInvisible(player)) return true; | ||
} | ||
|
||
// For VanishNoPacket | ||
if(vanishNoPacketPlugin != null) { | ||
//getPluginLogger().info("Checking via VNP if " + player.getDisplayName() + " is vanished: " + vanishNoPacketPlugin.getManager().isVanished(player)); | ||
//getPluginLogger().info("Checking via VNP for list of vanished players: " + vanishNoPacketPlugin.getManager().getVanishedPlayers()); | ||
if(vanishNoPacketPlugin.getManager().isVanished(player)) return true; | ||
} | ||
|
||
// For others (maybe) | ||
for (MetadataValue meta : player.getMetadata("vanished")) { | ||
if (meta.asBoolean()) return true; | ||
} | ||
|
||
// Otherwise, player is not vanished | ||
return false; | ||
|
||
} | ||
|
||
} | ||
|
21 changes: 21 additions & 0 deletions
21
src/main/java/uk/co/angrybee/joe/events/EssentialsVanishEvents.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,21 @@ | ||
package uk.co.angrybee.joe.events; | ||
|
||
import net.ess3.api.events.VanishStatusChangeEvent; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
public class EssentialsVanishEvents implements Listener { | ||
|
||
@EventHandler | ||
public void onVanishStatusChangeEvent(VanishStatusChangeEvent event){ | ||
// If value is true (player just vanished) | ||
if(event.getValue()) { | ||
VanishEvents.onPlayerHide(event.getAffected().getDisplayName()); | ||
} | ||
// If value is false (player just un-vanished) | ||
else { | ||
VanishEvents.onPlayerShow(event.getAffected().getDisplayName()); | ||
} | ||
} | ||
|
||
} |
21 changes: 11 additions & 10 deletions
21
src/main/java/uk/co/angrybee/joe/events/JoinLeaveEvents.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
21 changes: 21 additions & 0 deletions
21
src/main/java/uk/co/angrybee/joe/events/SuperVanishEvents.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,21 @@ | ||
package uk.co.angrybee.joe.events; | ||
|
||
import de.myzelyam.api.vanish.PlayerHideEvent; | ||
import de.myzelyam.api.vanish.PlayerShowEvent; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import uk.co.angrybee.joe.DiscordWhitelister; | ||
|
||
public class SuperVanishEvents implements Listener { | ||
|
||
@EventHandler | ||
public void onPlayerShowEvent(PlayerShowEvent event){ | ||
VanishEvents.onPlayerShow(event.getPlayer().getDisplayName()); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerHideEvent(PlayerHideEvent event){ | ||
VanishEvents.onPlayerHide(event.getPlayer().getDisplayName()); | ||
} | ||
|
||
} |
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,25 @@ | ||
package uk.co.angrybee.joe.events; | ||
|
||
import uk.co.angrybee.joe.DiscordClient; | ||
import uk.co.angrybee.joe.DiscordWhitelister; | ||
|
||
public class VanishEvents { | ||
|
||
// Called when a player exits vanished mode | ||
public static void onPlayerShow(String playerName) { | ||
if(!DiscordWhitelister.showVanishedPlayersInCount) { | ||
DiscordWhitelister.getPlugin().getLogger().info("Player " + playerName + " un-vanished, incrementing player count"); | ||
DiscordWhitelister.removeVanishedPlayer(); | ||
DiscordClient.SetPlayerCountStatus(DiscordWhitelister.getOnlineUsers()); | ||
} | ||
} | ||
|
||
// Called when a player enters vanished mode | ||
public static void onPlayerHide(String playerName) { | ||
if(!DiscordWhitelister.showVanishedPlayersInCount) { | ||
DiscordWhitelister.getPlugin().getLogger().info("Player " + playerName + " vanished, decrementing player count"); | ||
DiscordWhitelister.addVanishedPlayer(); | ||
DiscordClient.SetPlayerCountStatus(DiscordWhitelister.getOnlineUsers()); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/uk/co/angrybee/joe/events/VanishNoPacketEvents.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,21 @@ | ||
package uk.co.angrybee.joe.events; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.kitteh.vanish.event.VanishStatusChangeEvent; | ||
|
||
public class VanishNoPacketEvents implements Listener { | ||
|
||
@EventHandler | ||
public void onVanishStatusChangeEvent(VanishStatusChangeEvent event){ | ||
// If value is true (player just vanished) | ||
if(event.isVanishing()) { | ||
VanishEvents.onPlayerHide(event.getPlayer().getDisplayName()); | ||
} | ||
// If value is false (player just un-vanished) | ||
else { | ||
VanishEvents.onPlayerShow(event.getPlayer().getDisplayName()); | ||
} | ||
} | ||
|
||
} |
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