Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Fix bug with stand still ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
ohowe1 committed Jan 3, 2022
1 parent c6b4f3f commit 7b7cceb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/main/java/me/ohowe12/spectatormode/SpectatorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ public void togglePlayer(Player player, boolean forced, boolean silenceMessages)
if (player.getGameMode() == GameMode.SPECTATOR) {
toggleToSurvival(player, silenceMessages);
} else {
if (plugin.getConfigManager().getInt("stand-still-ticks") > 0 && !forced && !player.hasPermission("smpspectator.bypass")) {
Messenger.send(player, "stand-still-message");
stateHolder.addPlayerAwaiting(player, () -> {
toggleToSpectator(player, false, silenceMessages);
stateHolder.removePlayerAwaitingFromRan(player);
});
if (plugin.getConfigManager().getInt("stand-still-ticks") > 0 && !forced) {
if (stateHolder.isPlayerAwaiting(player)) {
stateHolder.removePlayerAwaitingFromCanceled(player);
} else {
Messenger.send(player, "stand-still-message");
stateHolder.addPlayerAwaiting(player, () -> {
toggleToSpectator(player, false, silenceMessages);
stateHolder.removePlayerAwaitingFromRan(player);
});
}
} else {
toggleToSpectator(player, forced, silenceMessages);
}
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/me/ohowe12/spectatormode/state/StateHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,31 @@ public void removePlayerAwaitingFromRan(Player player) {
playersAwaitingSpectator.remove(player);
}

public void removePlayerAwaitingFromMoved(Player player) {
public boolean isPlayerAwaiting(Player player) {
return playersAwaitingSpectator.containsKey(player);
}

private boolean removeAndCancelPlayerAwaiting(Player player) {
if (playersAwaitingSpectator.containsKey(player)) {
playersAwaitingSpectator.get(player).cancel();
playersAwaitingSpectator.remove(player);
return true;
}
return false;
}

public void removePlayerAwaitingFromMoved(Player player) {
if (removeAndCancelPlayerAwaiting(player)) {
Messenger.send(player, "moved-message");
}
}

public void removePlayerAwaitingFromCanceled(Player player) {
if (removeAndCancelPlayerAwaiting(player)) {
Messenger.send(player, "spec-cancel-message");
}
}

public void addPlayerKicker(Player player) {
kickers.put(player, plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
kickers.remove(player);
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ prevent-teleport: false
# Prevents these commands from being executed unless you have the smpspectator.bypass permission. Example list: [back, return, home, homes, tpaccept, tpyes, warp, warps]
bad-commands: [ ]

# If this is above 0, the player has to be still for the next X seconds after preforming the command to enter spectator mode. int
# If this is above 0, the player has to be still for the next X ticks (20 a second normally) after preforming the command to enter spectator mode. int
stand-still-ticks: 0

# Prevents players from going past the world border in spectator mode
Expand Down Expand Up @@ -159,5 +159,8 @@ moved-message: '&cYou moved! Spectator mode has been cancelled'
# Message sent when player has reached there time limit in spectator mode
times-up-message: '&cTime limit reached! Toggling gamemode to &b&lSURVIVAL MODE'

# Message sent when player is awaiting spectator and preforms the command again
spec-cancel-message: '&cSpectator mode has been cancelled'

# Get debug logs
debug: false

0 comments on commit 7b7cceb

Please sign in to comment.