Skip to content

Commit

Permalink
Disabled commands while spectating
Browse files Browse the repository at this point in the history
  • Loading branch information
Chipley committed Sep 13, 2013
1 parent d839d9b commit d878206
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/com/Chipmunk9998/Spectate/Spectate.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onEnable() {

loadConfig();

getServer().getPluginManager().registerEvents(new SpectateListener(), this);
getServer().getPluginManager().registerEvents(new SpectateListener(this), this);
getCommand("spectate").setExecutor(new SpectateCommandExecutor(this));
getAPI().startSpectateTask();

Expand Down
23 changes: 22 additions & 1 deletion src/com/Chipmunk9998/Spectate/SpectateListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
import com.Chipmunk9998.Spectate.api.SpectateScrollEvent;

public class SpectateListener implements Listener {

Spectate plugin;

public SpectateListener(Spectate plugin) {

this.plugin = plugin;

}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Expand Down Expand Up @@ -430,7 +438,20 @@ public void onMobTarget(EntityTargetEvent event) {
@EventHandler
public void onCommandPreprocess(PlayerCommandPreprocessEvent event) {

//check the option for disabling commands in the config and cancel it here if the command isn't /spectate
if (Spectate.getAPI().isSpectating(event.getPlayer())) {

if (plugin.disable_commands) {

if (!event.getMessage().startsWith("/spectate") && !event.getMessage().startsWith("/spec")) {

event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You can not execute this command while spectating.");

}

}

}

}

Expand Down

0 comments on commit d878206

Please sign in to comment.