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

Fix issues with vanished players while spectating #87

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {

allprojects {
group 'me.realized'
version '3.5.2'
version '3.5.3'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.realized.duels.util.hook.PluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class EssentialsHook extends PluginHook<DuelsPlugin> {

Expand All @@ -19,14 +20,16 @@ public EssentialsHook(final DuelsPlugin plugin) {
this.config = plugin.getConfiguration();
}

public boolean isVanished(@NotNull Player player) {
return getEssentials().getUser(player).isVanished();
}

public void tryUnvanish(final Player player) {
if (!config.isAutoUnvanish()) {
return;
}

final Essentials plugin = (Essentials) getPlugin();
final User user = plugin.getUser(player);

final User user = getEssentials().getUser(player);
if (user != null && user.isVanished()) {
user.setVanished(false);
}
Expand All @@ -37,11 +40,13 @@ public void setBackLocation(final Player player, final Location location) {
return;
}

final Essentials plugin = (Essentials) getPlugin();
final User user = plugin.getUser(player);

final User user = getEssentials().getUser(player);
if (user != null) {
user.setLastLocation(location);
}
}

private Essentials getEssentials() {
return (Essentials) getPlugin();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import me.realized.duels.arena.MatchImpl;
import me.realized.duels.config.Config;
import me.realized.duels.config.Lang;
import me.realized.duels.hook.hooks.EssentialsHook;
import me.realized.duels.hook.hooks.MyPetHook;
import me.realized.duels.player.PlayerInfo;
import me.realized.duels.player.PlayerInfoManager;
Expand Down Expand Up @@ -65,6 +66,7 @@ public class SpectateManagerImpl implements Loadable, SpectateManager {

private Teleport teleport;
private MyPetHook myPet;
private EssentialsHook essentials;

public SpectateManagerImpl(final DuelsPlugin plugin) {
this.plugin = plugin;
Expand All @@ -81,6 +83,7 @@ public void handleLoad() {
// Late-init since SpectateManager is loaded before below variables are loaded
this.teleport = plugin.getTeleport();
this.myPet = plugin.getHookManager().getHook(MyPetHook.class);
this.essentials = plugin.getHookManager().getHook(EssentialsHook.class);
}

@Override
Expand Down Expand Up @@ -136,7 +139,7 @@ public Result startSpectating(@NotNull final Player player, @NotNull final Playe
final MatchImpl match = arena.getMatch();

// Hide from players in match
if (match != null) {
if (match != null && (essentials == null || !essentials.isVanished(player))) {
match.getAllPlayers()
.stream()
.filter(arenaPlayer -> arenaPlayer.isOnline() && arenaPlayer.canSee(player))
Expand Down Expand Up @@ -221,7 +224,7 @@ public void stopSpectating(final Player player, final SpectatorImpl spectator) {
final MatchImpl match = spectator.getArena().getMatch();

// Show to players in match
if (match != null) {
if (match != null && (essentials == null || !essentials.isVanished(player))) {
match.getAllPlayers()
.stream()
.filter(Player::isOnline)
Expand Down