var scriptName = "FlagDetection";
var scriptAuthor = "BestNub";
var scriptVersion = 0.1;

// You can change your Speedmodule here   \/
var speed = moduleManager.getModule("Speed");
var speedState = false;
var speedMoving = false;
var notify = true;

function FlagModule() {
  this.getName = function () {
    return "FlagDetection";
  }

  this.getDescription = function () {
    return "Detects Flags and disables Speed"
  }

  this.getCategory = function () {
    return "Misc";
  }

  this.onUpdate = function () {
    speedState = speed.getState();
    if (speedState && mc.gameSettings.keyBindForward.isKeyDown()) {
      if ((mc.thePlayer.motionX == 0 && mc.thePlayer.motionZ == 0) && speedMoving) {
        speed.setState(false);
        if (notify) {
          chat.print("Flag detected! Disabled Speed!");
        }
      }
      speedMoving = true;
    } else {
      speedMoving = false;
    }
  }

  this.onDisable = function () {
  }
}

var flagModule = new FlagModule();
var flagModuleClient;

function onEnable() {
  flagModuleClient = moduleManager.registerModule(flagModule);
}

function onDisable() {
  moduleManager.unregisterModule(flagModuleClient);
}