# using a text argument, but making the default argument the player
# this will allow us to use sub-command, while still allowing a player argument
command /stoggle [<text="%player%">]:
permission: spy.toggle
trigger:
# allows us to use "text" argument, while preserving player argument
set {_player} to arg 1 parsed as player
if {_player} is online:
# if this is the first time the player has ran the command
if {spy.enable::%{_player}%} is not set:
set {spy.enable::%{_player}%} to false
# if player is not in spy-mode, make it so
if {spy.enable::%{_player}%} is false:
# using list for looping
set {spy.enable::%{_player}%} to true
broadcast "&8%{_player}% &fhas &cQuit"
message "&8[&b×&8] &7Spy Mode has been Enabled!" to {_player}
message "&8[&b×&8] &7Make sure to disable this before leaving!" to {_player}
message "&8[&b×&8] &7Use /tp to see if players are hacking!" to {_player}
set {spy.loc::%{_player}%} to location of {_player}
# console commands do not have leading slash "/"
execute console command "gamemode spectator %{_player}%"
loop all players:
hide {_player} in tablist of loop-player
# else, if spy-mode is active
else:
set {spy.enable::%{_player}%} to false
broadcast "&8%{_player}% &fhas &9Join"
message "&8[&b×&8] &7Spy Mode has been Disabled!" to {_player}
execute console command "gamemode survival %{_player}%"
loop all players:
# I am unsure why, but we need a delay here
wait 5 ticks
show {_player} in tablist of loop-player
# list players who are in spy-mode
if arg 1 is "list":
loop {spy.enable::*}:
# If your variables use UUID:
add (player from "%loop-index%") to {_spies::*}
# else, use this:
#add loop-index to {_spies::*}
message "&8[&b×&8] &7Spies: &c%{_spies::*}%" to player
on logout:
# saving if a player logs out with spy-mode
if {spy.enable::%player%} is true:
set {spy.logout::%player%} to true
on login:
# wait a few ticks
wait 5 ticks
# if the player logged out with spy-mode active
if {spy.logout::%player%} is true:
# change remove them from spectator
execute console command "gamemode survival %player%"
# reset variables to false
set {spy.logout::%player%} to false
set {spy.enable::%player%} to false
# if a new player logs in while someone is hidden
loop all players:
# if it finds someone who is hidden
if {spy.enable::%loop-player%} is true:
# hides that player from the newly logged in player
hide loop-player in tablist of player