--- Runs the command. Handles dispatching to the server if necessary.
-- Command:Validate() must be called before this is called or it will throw.

function Command:Run ()
	if self._Validated == nil then
		error("Must validate a command before running.")
	end

	local beforeRunHook = self.Dispatcher:RunHooks("BeforeRun", self)
	if beforeRunHook then
		return beforeRunHook
	end

	if self.Object.Run then -- We can just Run it here on this machine
		self.Response = self.Object.Run(self, unpack(self:GatherArgumentValues()))
	elseif IsServer then -- Uh oh, we're already on the server and there's no Run function.
		warn(self.Name, "command has no implementation!")
		self.Response = "No implementation."
	else -- We're on the client, so we send this off to the server to let the server see what it can do with it.
		self.Response = self.Dispatcher:Send(self.RawText, self.Object.Data and self.Object.Data(self))
	end

	local afterRunHook = self.Dispatcher:RunHooks("AfterRun", self)
	if afterRunHook then
		return afterRunHook
	else
		return self.Response
	end
end
